Modify a text file: $/p1e.java
$/p1e.java
//// Project 1e //// B.A.Martin CST 112 String title= "Project 1e"; String author= "B.A.Martin -- CST 112"; float horizon; float sunX=0; float georgeX, georgeY; float look; float muttX, muttY, tickX, tickY; float hareX, hareY, hareDX, hareDY; //// SETUP: screen size void setup() { size( 640, 480 ); horizon= height/4; hareX=0; hareY=height-60; hareDX=5; hareDY=0; } //// Next frame. void draw() { scene(); action(); show(); credits(); } //// Draw the scene. void scene() { background( 100, 200, 250 ); fill( 200, 250, 200 ); rectMode( CORNERS ); rect( 0,horizon, width, height ); // Sun. fill( 255,255,0 ); noStroke(); ellipse( (float) sunX, 40, 30,30 ); sunX= (sunX + 1) % width; stroke(0); // House rectMode( CORNER ); fill(255,0,0); rect( 120, horizon-50, 60, 50 ); triangle( 120,horizon-50, 180,horizon-50, 150,horizon-70 ); fill(0); rect( 125, horizon-35, 10, 10 ); rect( 165, horizon-35, 10, 10 ); rect( 142, horizon-35, 16, 33 ); // Trees. fill( 150, 0, 0 ); rectMode( CORNER ); rect( 200, horizon, 20, -60 ); rect( 300, horizon, 25, -70 ); rect( 400, horizon, 15, -50 ); noStroke(); fill( 0, 120, 0 ); ellipse( 210, horizon-70, 35, 35 ); fill( 50, 180, 50 ); ellipse( 312, horizon-85, 55, 40 ); fill( 50, 250, 100 ); ellipse( 407, horizon-45, 30, 30 ); stroke(0); } //// Move the actors. void action() { // Hare goes left to right hareX = hareX + hareDX; if (hareX > width) { hareDX= - hareDX; // Reverse direction at right. } if (hareX < 0) { hareDX= - hareDX; // Reverse direction at left. } // Move George //-- georgeX= mouseX; //-- georgeY= mouseY; georgeX= georgeX + (mouseX-georgeX) / 10; // Chase the mouse. georgeY= georgeY + (mouseY-georgeY) / 20; if (georgeY < horizon) georgeY= horizon; // Look in direction of motion. look=0; if (mouseX>pmouseX) look = 2; if (mouseX
georgeX) muttFace= -40; rect( muttX + muttFace, muttY-20, 30, 20 ); // Bug fill( 150 ); float xx= random( 6 ); ellipse( tickX, tickY, 20, 10 ); line( tickX-10, tickY+4, tickX-12+xx, tickY+8 ); line( tickX-5, tickY+4, tickX-7+xx, tickY+8 ); line( tickX+5, tickY+4, tickX+3+xx, tickY+8 ); line( tickX+10, tickY+4, tickX+10+xx, tickY+8 ); hareShow(); } void hareShow() { // White rabbit fill( 255, 255, 255 ); // White rabbit. ellipse( hareX, hareY, 60, 20 ); fill( 0 ); line( hareX-25, hareY+5, hareX-27, hareY+20 ); line( hareX-20, hareY+5, hareX-22, hareY+20 ); // front legs line( hareX+25, hareY+5, hareX+27, hareY+20 ); line( hareX+20, hareY+5, hareX+22, hareY+20 ); } //// Put some text on the screen.. void credits() { fill( 0 ); text( title, width/3, 20 ); text( author, 20, height-20 ); } //// EVENT HANDLERS //// void keyPressed() { if (key == '+') { hareDX = 1.1 * hareDX; } if (key == '-') { hareDX = 0.91 * hareDX; } if (key == 'b') { background(0); } }