Modify a text file: $/guydog3.java
$/guydog3.java
//////// Guy and dog, plus birds. //////// // bam:2907a // //// GLOBAL DATA //// int birdX=100, birdY=100; // Initial position of bird int birdDX=20; int sunX=100, sunY=100; // Position of sun boolean eastbound=true; void setup() { size( 800, 600 ); smooth(); frameRate(5); } void draw() { //// Move and show everything // scene(); bird(); guy(); dog(); } void scene() { //// Sky, sun, grass. background( 150, 200, 255 ); // Sky //// Move the sun. sunX = (sunX+5) % width; sunY = (int) ( 100 - 100*sin( PI*( sunX/width ) ) ); text( "@@@ sun: "+sunX+","+sunY, 600, 50 ); float xw= sunX/width; text( "@@@ x/w: "+xw, 600, 70 ); float sinyy= 100*sin( PI*( sunX/width ) ); text( "@@@ sin(PI*x/w): "+sinyy, 600, 90 ); //// Draw the sun fill( 255, 255, 0 ); // Sun ellipse( sunX, sunY, 40, 40 ); //// Grass fill( 100, 255, 100 ); rectMode( CORNERS); rect( 0, height/3, width, height ); } void bird() { //// Bird flies across screen. (Press key to drop load.) birdX = birdX + birdDX; birdX = birdX % width; birdY = birdY + 10 - (int) random( 20 ); fill( 200, 100, 200, 150 ); triangle( birdX,birdY, birdX-50,birdY-15, birdX-50,birdY+15 ); if (birdY >150){ birdY = birdY - 5; } else if (birdY <-200){ birdY= birdY - 10; } } void guy() { //// Guy follows mouse. fill( 0,0,255 ); // Blue shirt rectMode( CENTER ); rect( mouseX, mouseY, 60, 80 ); fill( 255, 200, 200 ); // Pink face ellipseMode( CENTER ); ellipse( mouseX, mouseY-40-15, 30,30 ); // +++ add a hat? //// Eye. fill(0,0,255); if (eastbound) { ellipse( mouseX+10, mouseY-40-20, 5,5 ); } else { ellipse( mouseX-10, mouseY-40-20, 5,5 ); } } void dog() { if (pmouseX < mouseX) eastbound=true; else if (pmouseX > mouseX) eastbound=false; else {} // No change if = //// Dog chases guy. //dog is on the right if ( ! eastbound){ int dogX=pmouseX-50; int dogY=pmouseY+100; dogX = dogX + 5*( pmouseX-mouseX ); dogY = dogY + 2*( pmouseY-mouseY ); fill( 150, 50, 50 ); rectMode( CORNER ); rect( dogX+80, dogY, 40, 20 ); rect( dogX+70, dogY-10, 20, 10 ); } //dog is on the left else { int dogX=pmouseX-70; int dogY=pmouseY+100; dogX = dogX + 5*( pmouseX-mouseX ); dogY = dogY + 2*( pmouseY-mouseY ); fill( 150, 50, 50 ); rectMode( CORNER ); rect( dogX, dogY, 40, 20 ); rect( dogX+30, dogY-10, 20, 10 ); } }