// EXERCISES (in class): Waves & Fishes // bam String title="EXERCISES (in class): Waves & Fishes"; String author="Bruce Alan Martin"; float sealevel,bottom; float left,right; float chop=40; // Distance between waves. float waveX=0, waveDX=1; float fishX,fishY; float fishDX=3; float fishDY=0; float sunX,sunY; int numfishes= 3; void setup() { // setup // size( 800,600 ); bottom= height; left=0; right=width; sealevel= height / 4; reset(); } void reset() { // reset // fishX=200; fishY= random(sealevel,bottom); sunX=0; sunY= sealevel*2/3; } void draw() { // Next frame // scene(); sun(); sunX= (sunX + 2) % width; if ( (frameCount % 60) == 0) { chop= random( 20, 80 ); waveDX= random( 1,5); } waves( chop ); waveX = (waveX += waveDX) % chop; grass(); fill(0); text( fishX, 10,10 ); text( fishDX, 10,20 ); fishies( numfishes ); fishX += fishDX; fishY= fishY - 3 + random(6); if ( fishX>right+200 || fishX0) { eye( x+25, y-12 ); } else { eye( x-25, y-12 ); } } void eye( float x, float y) { // eye // fill(255); ellipse( x, y, 8,8 ); } void sun() { // sun moves across sky, at altitude az // fill(255,255,0); float az= -70 * sin(PI*sunX/width); ellipse(sunX, sunY+az, 40,40 ); } void keyPressed() { // Handle keys // if (key == 'q' ) exit(); if (key == 'r' ) reset(); }