Modify a text file: $/p1e.pde
$/p1e.pde
// BAM: Creature moves diagonally (toward last mouse click). // Mouse controls feet, eyes, mouth. int xsize=400, ysize=400; // screen size // Creature coordiantes. // int x=125, y=125; // (x,y) coordinates for center of creeature. int dx=1, dy=1; int fathead=0; // Head gets bigger when a key is pressed. String name=""; String top= "PLEASE type in a name, for this creature!"; void setup() { // size(xsize, ysize); println(frameRate); frameRate(30); } void draw() { // background(255, 255, 200); //// HEADLINE //// text( top, 10, 10 ); text( " He moves diagonally (toward last click).", 10, 20 ); text( " Mouse controls his feet, eyes, mouth.", 20, 30); text( "BAM", 10, ysize-10 ); //// CREATURE DESCRIPTION //// rectMode(CENTER); ellipseMode(CENTER); fill(63, 255, 63); // Body: 60x80 rect green teeshirt. noStroke(); rect( x, y, 60, 80); fill(255, 0, 255); // Red label for shirt. text( "My name is", x-30, y-10); text( name, x-30, y+10); fill(0, 0, 0); // Bellybutton rect( x, y, 2, 2); // Head: 30x40 red ellipse. int xHead=x, yHead= y - 60; // (Move head up by 1/2 of shirt and head. fill(255, 192, 63); ellipse( x, yHead, 30+fathead, 40+fathead); fill(255, 192, 63); // Ears ellipse( x-20, yHead-5, 15, 15); ellipse( x+20, yHead-5, 15, 15); fill(127, 63, 63); // Toupee ellipse( x, yHead-20, 24, 6); // Eyes left or right. How far away (left or right) is the mouse? int xx= x-mouseX; int xLook= xx / 50; fill(0, 192, 255); // Blue eyes ellipse( x-8-xLook, y-65, 10, 10); ellipse( x+8-xLook, y-65, 10, 10); // Mouth (up or down); int yy= y-mouseY; int bigMouth= abs( yy / 20 ); stroke(255, 0, 0); // Red lips. strokeWeight(2); fill(255, 255, 255); // White teeth. ellipse( x, y-48, 20.0, 4+bigMouth); noStroke(); // Nose fill(255, 127, 63); ellipse( x, y-60, 8, 12); fill(255, 127, 63); // Arms & hands. rect( x-45, y-25, 30, 10); rect( x+45, y-25, 30, 10); fill(255, 127, 63); rect( x-65, y-25, 10, 15); // Left hand rect( x-70, y-30, 10, 5); // Left finger rect( x+65, y-25, 10, 15); // Right hand rect( x+70, y-30, 10, 5); // Right finger stroke(0, 0, 255); // Legs strokeWeight(12); line( x-20, y+40, pmouseX-45, pmouseY+100); line( x+20, y+40, pmouseX+45, pmouseY+100); stroke(192,192,0); // Shoes strokeWeight(2); fill(128,64,0); rectMode(CENTER); rect( pmouseX-45, pmouseY+100, 25, 15); rect( pmouseX+45, pmouseY+100, 25, 15); //// END OF CREATURE DESCRIPTION. //// //// DRIFTING CREATURE. //// x += dx; y += dy; x = x<0? xsize-1 : x; y = y<0? ysize-1 : y; // Force >=0 (wrap) x = x % xsize; y = y % ysize; // Constrain to size of sketch } void mouseClicked() { // Capture mouse x,y when clicked. x= mouseX; y= mouseY; // Change direction toward mouse. if (x < xsize/2) dx= -1; else dx=1; if (y < ysize/2) dy= -1; else dy=1; } void keyPressed() { println( key + 100 ); if (key < 31) return; if (key > 255) return; fathead = (fathead+10) % 100; name= name + key; top= name; // Change first line to creature name (after key pressed). // Capture mouse x,y when clicked. x= mouseX; y= mouseY; dy = dx*dy; // Reverse direction. dx = -dx; }