String title = ( "Flocks of Birds" ); String author = ( "Jenna Klima" ); float ground; float sky; float grass; float tilt = 20; float sunX = 50; float sunY = 150; int randomNumberOfBirds; float x, y, w, h; float left, right; float groundLevel = 400; float bottom = 500; float cloud1X, cloud1Y = 20; float cloud2X, cloud2Y = 40; float cloud3X, cloud3Y = 60; float cloud4X, cloud4Y = 80; void setup ( ) { //setup size ( 1000, 600 ); reset ( ); } void reset ( ) { //reset randomNumberOfBirds = int ( random ( 3, 5 ) ); //-- x = random ( width / 2 ); //-- y = random ( height / 2 ); x = 0; y = random ( 100, 300 ); w= random ( 10, 70 ); h= w / 3; } void draw ( ) { //draw these functions ground ( ); sky ( ); grass ( ); sun ( ); clouds ( ); flock ( randomNumberOfBirds, x, y, w, h ); x = x + 10; textSize ( 20 ); fill ( 130 ); text ( title, width / 3, 30 ); text ( author, width / 10, 30 ); } void ground ( ) { //draw the ground noStroke ( ); fill ( 100, 250, 100 ); rect ( 0, 500, width, height ); } void sky ( ) { //draw the sky noStroke ( ); fill ( 150, 150, 255 ); rect ( 0, 0, width, height - 100 ); } void grass ( ) { //draw the grass that grows on the ground for ( float x = 0 ; x < width + 10 ; x += 20 ) { //draw ONE blade of grass strokeWeight ( 3 ); stroke ( 150, 250, 150 ); line ( x, height - 100, x + tilt, height - 125 ); } } void sun ( ) { //draw sun ellipseMode ( CORNER ); noStroke ( ); fill ( 255, 255, 100 ); ellipse ( sunX + 410, sunY - 75, 100, 100 ); /*//sun rays strokeWeight(3); stroke ( 255, 255, 100 ); line ( sunX + 40, sunY + 40, sunX + 18, sunY + 18 ); line ( sunX - 40, sunY - 40, sunX - 18, sunY - 18 ); line (sunX + 40, sunY - 40, sunX + 18, sunY - 18 ); line ( sunX - 40, sunY + 40, sunX - 18, sunY + 18 ); line ( sunX, sunY + 25, sunX, sunY + 55 ); line ( sunX, sunY - 25, sunX, sunY - 55 ); line ( sunX + 25, sunY, sunX + 55, sunY ); line ( sunX - 25, sunY, sunX - 55, sunY );*/ } void clouds ( ) { //draw & move 3 clouds noStroke ( ); cloud1X += random ( 3, 5 ); cloud2X += random ( 2, 4 ); cloud3X += random ( 1, 2 ); cloud4X += random ( 2, 3 ); //reset clouds after they've drifted completely across if ( cloud1X > width + 500 ) { cloud1X = -500; cloud1Y = random ( 20, 200 ); } if ( cloud2X > width + 500 ) { cloud2X = -500; cloud2Y = random ( 20, 200 ); } if ( cloud3X > width + 500 ) { cloud3X = -500; cloud3Y = random ( 20, 200 ); } if ( cloud4X > width + 500 ) { cloud4X = -500; cloud4Y = random ( 20, 200 ); } //draw clouds fill ( 255 ); drawCloud ( cloud1X, cloud1Y ); fill ( 255 ); drawCloud ( cloud2X, cloud2Y ); fill ( 255 ); drawCloud ( cloud3X, cloud3Y ); fill ( 255 ); drawCloud ( cloud4X, cloud4Y ); } void drawCloud ( float x, float y ) { //draw one cloud many times ellipse ( x, y, 500, 250 ); } void flock ( int randomNumberOfBirds, float x, float y, float w, float h ) { ////draw a flock of n birds //draw first bird float xx = x; //higher (or lower) float hh = h * 3; //width gets smaller float ww = w; bird ( xx, y, w, h ); ////now draw pairs behind this pair //new pair behind this pair xx = xx - 2 * w; for ( int j = 1 ; j < randomNumberOfBirds ; j++ ) { //draw new pair of birds bird ( xx, y + hh, ww, h );//----above bird ( xx, y - hh, ww, h );//----below xx = xx - 2 * ww;//--------------new pair behind this pair ww *= 0.7;//---------------------smaller hh = hh + h * 3; } } void bird ( float x, float y, float w, float h ) { //draw birds noStroke ( ); fill ( 150, 250, 250 ); //-- triangle ( x, y, x - w, y - h, x - w, y + h ); ellipseMode ( RADIUS ); ellipse ( x, y, w * 1, w * 1 / 3 ); if ( x > width + 1000 && x - w > width + 1000 ) { reset ( ); } } void keyPressed ( ) { //keys if ( key == 'r' ) reset ( ); if ( key == 'q' ) exit ( ); }