This is the code for the main class of our creature-maker:
import java.util.HashMap;
HashMap words = new HashMap();
String[] lines;
String oneLine;
String animalName;
PImage head;
PImage body;
PImage legs;
PFont font;
void setup() {
background(random(100, 255), random(100, 255), random(100, 255));
animalName=”";
font = loadFont(“Goudy-Bold-70.vlw”);
size(700, 700);
words.put(“horsehead.png”, “H”);
words.put(“bluejayhead.png”, “Bl”);
words.put(“staghead.png”, “St”);
words.put(“horsebody.png”, “or”);
words.put(“bluejaybody.png”, “ue”);
words.put(“stagbody.png”, “a”);
words.put(“horselegs.png”, “se”);
words.put(“bluejaylegs.png”, “jay”);
words.put(“staglegs.png”, “g”);
}
void draw() {
//puts file into contextFilter object, collectString retreives output that
//would normally be printed, puts into oneLine String
oneLine = new ContextFilter().collectString(createReader(“animals.txt”));
lines = oneLine.split(” “);
//for debugging
for (int i = 0; i < lines.length; i++) {
String t = lines[i];
if (words.containsKey(t)) {
animalName = animalName + words.get(t);
}
}
//we’ll have
head = loadImage(lines[0]);
body = loadImage(lines[1]);
legs = loadImage(lines[2]);
image(head, 0, 0);
image(body, 0, 0);
image(legs, 0, 0);
println(animalName);
textFont(font);
textAlign(CENTER);
fill(0);
text(animalName, width/2, 620);
noLoop();
}
void mousePressed() {
background(random(100, 255), random(100, 255), random(100, 255));
animalName=”";
redraw();
}
