// Waves // Yennifer Tejada // declare the variables float horizon; float sunX = 10; float sunY = 100; float wavesX; float wavesY = 350; // declare the random RGB float r; float g; float b; float x; float y; float w; float h; // float birds float bird1X, bird1Y = 10; float bird2X, bird2Y = 20; float bird3X, bird3Y = 35; float bird4X, bird4Y = 50; float bird5X, bird5Y = 60; // float fishes float fish1X, fish1Y = 10; float fish2X, fish2Y = 20; float fish3X, fish3Y = 35; int n; void setup() { size(900, 700); horizon = height/2; sunY = horizon/2; r = random(255); g = random(255); b = random(255); } void draw() { scene(); waves(); sun(); fill(0); fish(); birds(); grass(); } // birds body void birds() { bird1X += random(4, 6); bird2X += random(1, 3); bird3X += random(3, 5); bird4X += random(2, 5); bird5X += random(1, 2); if (bird1X > width - 20) { bird1X = 60; bird1Y = random (20, horizon); } if (bird2X > width - 20) { bird2X = 60; bird2Y = random (20, horizon); } if (bird3X > width - 20) { bird3X = 60; bird3Y = random (20, horizon); } if (bird4X > width - 20) { bird4X = 60; bird4Y = random (20, horizon); } if (bird5X > width - 20) { bird5X = 60; bird5Y = random (20, horizon); } fill(26, 139, 198); drawBird(bird1X, bird1Y+5+random(5) ); fill(41, 214, 103); drawBird(bird2X, bird2Y); fill(169, 203, 66); drawBird(bird3X, bird3Y); fill(27, 82, 219); drawBird(bird4X, bird4Y); fill(30, 70, 200); drawBird(bird5X, bird5Y); } // draw the 5 birds void drawBird( float x, float y ) { triangle( x, y, x-60, y-10, x-60, y+10 ); } void scene() { x += random(20); y = y + 10 - random(20); background(44, 151, 255); noStroke(); fill(0, 68, 250); rect(0, horizon, width, height* 4/5); sunX = sunX + 1.5; // the speed of the waves wavesX = (wavesX +1) % 80; /* if(wavesX > width + 80) { wavesX = +width; } */ } void reset() { n = int (random(3, 10)); x = random(width/2); y = random(height/2); w = random(10, 70); h = w/2; } // draw the waves that would move accross void waves() { fill(44, 151, 255); for (float x = wavesX - 100; x < width + 300; x += 80) { ellipse(x, wavesY, 80, 40); } } // Draw the sun going accross the screen void sun() { if (sunX > width) { sunX = 0; sunY = random (20, horizon-20); } // the sun and the rays fill(255, 255, 0); stroke(2); rect(sunX, sunY, 70, 5); rect(sunX, sunY, -70, 5); rect(sunX-2, sunY+25, 5, 40); rect(sunX-2, sunY-60, 5, 40); //rect(sunX-50,sunY,5,40); ellipse(sunX, sunY, 55, 55); } // draw the grass under the sea void grass() { float tilt= wavesX; if (wavesX<1) { tilt = -1; } for (float x = wavesX - 200; x < width + 80; x = x +60) { stroke(0, 255, 0); line(x, height, x+ 1*wavesX, height -40); } } // fish body void fish() { fish1X += 6; fish2X +=2; fish3X += 3; if (fish1X > width - 20) { fish1X = 60; fish1Y = random (20, horizon); } if (fish2X > width - 20) { fish2X = 60; fish2Y = random (20, horizon); } if (fish3X > width - 20) { fish3X = 60; fish3Y = random (20, horizon); } fill(26, 139, 198); drawFish(fish1X, fish1Y+5+random(5) ); fill(41, 214, 103); drawFish(fish2X, fish2Y); fill(169, 203, 66); drawFish(fish3X, fish3Y); } //The 3 fishes void drawFish(float x, float y) { smooth(4); fill(r, g, b); ellipse(x-20, y+500, h+70, 10); ellipse(x, y+500, h+80, 40); // draw the eyes fill(0); ellipse(x+20, y+500, h+10, 10); } // when 'R' is pressed birds fly accross void keyPressed() { if (key== 'r') reset(); }