/**Credit to Kotchen for his idea on waves ORIGINAL NOTES HAVE BEEN MOVED TO A FILE CALLED "NOTES"**/ String title = ( "Schools of Fish" ); String author = ( "Jenna Klima" ); float water; float sky; float wavesI; float wavesII; float seaweed; float tilt = 20; float sunX = 50; float sunY = 150; float setDaycycle = 2; int randomNumberOfFish; float x, y, w, h; float fishDX = 7; float fishDY = 0; float left, right; float sealevel = 400; float bottom = 500; float waveX; void setup ( ) { size ( 1020, 600 ); reset ( ); } void reset ( ) { //reset randomNumberOfFish = int ( random ( 3, 5 ) ); //-- x = random ( width / 2 ); //-- y = random ( height / 2 ); x = 0; y = random ( 400, 450 ); w = random( 10, 70 ); h = w / 3; } void draw ( ) { water ( ); wavesI ( ); wavesII ( ); wavesIIDoes ( ); sky ( ); seaweed ( ); school ( randomNumberOfFish, x, y, w, h ); x += fishDX; // if ( x > right + width + 320 || x < left - width + 700 ) { // if ( x > right + 1320 || x < left - 320 ) { if ( x > right + width + 320 || x < left - 320 ) { fishDX = -fishDX; y = random ( sealevel, bottom - 30 ); // random #, y, and SIZE of fish randomNumberOfFish = int ( random ( 3, 5 ) ); w= random ( 10, 70 ); h= w / 3; } sun ( ); textSize ( 20 ); fill ( 130 ); text ( title, width / 3, 30 ); text ( author, width / 10, 30 ); } void water ( ) { if ( setDaycycle %2 == 0 ) { noStroke ( ); fill ( 100, 100, 200 ); rect ( 0, 200, width, height ); } else { noStroke ( ); fill ( 50, 50, 100 ); rect ( 0, 200, width, height ); } } void sky ( ) { if ( setDaycycle %2 == 0 ) { noStroke ( ); fill ( 150, 150, 255 ); rect ( 0, 0, width, height / 3 ); } else{ noStroke ( ); fill ( 75 ); rect ( 0, 0, width, height / 3 ); } } void seaweed ( ) { if ( fishDX < 0 ) tilt = -20; if ( fishDX > 0 ) tilt = 20; for ( float x = 0; x < width + 10; x += 20 ) { //draw ONE seaweed if ( setDaycycle %2 == 0 ) { strokeWeight ( 3 ); stroke ( 150, 250, 150 ); line ( x, height, x + tilt, height - 75 ); } else { strokeWeight ( 3 ); stroke ( 50, 100, 50 ); line ( x, height, x + tilt, height - 75 ); } } } void wavesI ( ) { if ( setDaycycle %2 == 0 ) { //-- stroke ( 0 ); fill ( 150, 150, 255 ); } else { //-- stroke ( 0 ); fill ( 75 ); ellipseMode ( RADIUS ); } //draw a STATIONARY line of waves for ( int j = 0; j < width + 11; j = j + 60 ) { ellipse ( j, 180, 60, 40 ); } } void wavesII ( ) { if ( setDaycycle %2 == 0 ) { //-- stroke ( 0 ); fill ( 150, 150, 255 ); } else { //-- stroke ( 0 ); fill ( 75 ); ellipseMode ( RADIUS ); } //draw a line of wavesI for moving later on for ( int j = 30; j < width; j = j + 60 ) { ellipse ( waveX + j, 180, 60, 40 ); ellipse ( waveX - 30, 180, 60, 40 ); ellipse ( waveX - 90, 180, 60, 40 ); ellipse ( waveX - 150, 180, 60, 40 ); } } void wavesIIDoes ( ) { //make line of wavesII move waveX = waveX + 4; //reset waves if ( waveX + 900 == width ) { waveX = 0; } } void sun ( ) { float arc = -70 * sin ( PI * sunX / width ); //draw sun OR moon if ( setDaycycle %2 == 0 ) { ellipseMode ( CORNER ); noStroke ( ); fill ( 255, 255, 100 ); ellipse ( sunX - 24, sunY - 24 + arc, 50, 50 ); sunX = sunX + 1; //sun rays strokeWeight ( 3 ); stroke ( 255, 255, 100 ); line ( sunX + 40, sunY + 40 + arc, sunX + 18, sunY + 18 + arc ); line ( sunX - 40, sunY - 40 + arc, sunX - 18, sunY - 18 + arc ); line ( sunX + 40, sunY - 40 + arc, sunX + 18, sunY - 18 + arc ); line ( sunX - 40, sunY + 40 + arc, sunX - 18, sunY + 18 + arc ); line ( sunX, sunY + 25 + arc, sunX, sunY + 55 + arc ); line ( sunX, sunY - 25 + arc, sunX, sunY - 55 + arc ); line ( sunX + 25, sunY + arc, sunX + 55, sunY + arc ); line ( sunX - 25, sunY + arc, sunX - 55, sunY + arc ); } else { fill ( 220 ); } ellipseMode ( CORNER ); noStroke ( ); ellipse ( sunX - 24, sunY - 24 + arc, 50, 50 ); sunX = sunX + 2; //reset sun AND moon (works with both) if ( sunX > width + 10 ) { sunX = 0; //-- sunY = random ( 50, 130 ); setDaycycle = setDaycycle +1 ; } } void school ( int randomNumberOfFish, float x, float y, float w, float h ) { //school of fish if ( fishDX > 0 ) { ////draw a school of n fish //draw first fish float xx = x; //higher (or lower) float up = h * 3; //width gets smaller float ww = w; float tt = h; //tail height fish ( xx, y, w, h ); ////now draw pairs behind this pair //new pair behind this pair xx = xx - 2 * w; for ( int j = 1; j < randomNumberOfFish; j++ ) { //draw new pair of fish fish ( xx, y + up, ww, tt );//----above fish ( xx, y - up, ww, tt );//----below xx= xx - 2 * ww;//----------------new pair behind this pair ww *= 0.7;//----------------------smaller width tt *= 0.7;//----------------------smaller tail-height up= up + h * 3;//-----------------up/down } } //fish swim RIGHT if ( fishDX < 0 ) { ////draw a school of n fish //draw first fish float xx = x; //higher (or lower) float up = h * 3; //width gets smaller float ww = w; //tail height float tt = h; fish ( xx, y, w, h ); ////now draw pairs behind this pair //new pair behind this pair xx = xx + 2 * w; for ( int j = 1; j < randomNumberOfFish; j++ ) { //draw new pair of fish fish ( xx, y + up, ww, tt );//----above fish ( xx, y - up, ww, tt );//----below xx = xx + 2 * ww;//---------------new pair behind this pair ww *= 0.7;//----------------------smaller tt *= 0.7;//----------------------smaller tail-height up= up + h * 3;//-----------------up/down }//for// }//if// } void fish ( float x, float y, float w, float h ) { //draw fish if ( fishDX > 0 ) { //-- triangle ( x + 20, y, x - w, y - h, x - w, y + h ); //-- ellipse ( x, y, w + 50, w - 40 ); //-- ellipse ( x, y, w * 2, w ); //-- fill ( color ( random ( 0, 100 ) ) ); if ( setDaycycle %2 == 0 ) { noStroke ( ); fill ( 150, 250, 250 ); triangle ( x, y, x - w, y - h, x - w, y + h ); ellipseMode ( RADIUS ); ellipse ( x, y, w, w / 3 ); } else { noStroke ( ); fill ( 50, 100, 100 ); triangle ( x, y, x - w, y - h, x - w, y + h ); ellipseMode ( RADIUS ); ellipse ( x, y, w, w / 3 ); } } if ( fishDX < 0 ) { if ( setDaycycle %2 == 0 ) { noStroke ( ); fill ( 150, 250, 250 ); triangle ( x, y, x + w, y - h, x + w, y + h ); ellipseMode ( RADIUS ); ellipse ( x, y, w, w / 3 ); } else { noStroke ( ); fill (50, 100, 100 ); triangle ( x, y, x + w, y - h, x + w, y + h ); ellipseMode ( RADIUS ); ellipse ( x, y, w, w / 3 ); } } } void keyPressed ( ) { //keys if ( key == 'r' ) reset ( ); if ( key == 'q' ) exit ( ); }