//Bubble Variables
float[] bubbleY;
int bubbleCount = 50;
int fx = 300;
int fy = 150;
void setup(){
size(600,300);
bubbleY = new float[bubbleCount];
for(int i = 0; i < bubbleCount; i++){
bubbleY[i] = random(0,height);
}
}
void draw(){
// 1: drawTank()
drawTank();
// 2: call drawKelp() and drawFish()
drawKelp(200);
drawFish(300, 150);
drawFish(430, 50);
drawKelp(450);
// 3: call drawBubbles()
drawBubbles(500);
drawBubbles(100);
// Bonus Challenge: add motion to a fish
drawFish(fx, fy);
fx -= 2;
fy += .4;
if(fx <0) {
fx += width;
}
if(fy > height) {
fy -= height;
}
}
void drawTank(){
noStroke();
//Water
fill(0,150,250);
rect(0,0,width,height);
//gravel
fill(125,75,20);
rect(0,height-height/5,width, height/5);
}
void drawFish(float fishX, float fishY){
translate(fishX,fishY);
noStroke();
fill(255,255,150);
triangle(-20,0, +10,-20,+10,+20);
ellipse(+10,0,40,25);
triangle(+25,0,+35,+15,+35,-15);
fill(0);
ellipse(-7,-2,5,5);
stroke(0);
strokeWeight(1);
noFill();
resetMatrix();
}
void drawBubbles(float bubbleX){
randomSeed((int)bubbleX);
for(int i = 0; i < bubbleCount; i++){
fill(0,0,255,30);
stroke(230,230,255,80);
float s = random(5,10);
ellipse(bubbleX+random(-20,20),bubbleY[i],s,s);
bubbleY[i]-=1.5;
if(bubbleY[i] < -10){
bubbleY[i] = height;
}
}
}
void drawKelp(float kelpPosition){
randomSeed((int)kelpPosition*2);
float stop = random(200,300);
float start = random(10,50);
for(float y = start; y <stop; y++){
float wide = sin(y/10.0 + frameCount/60.0)*10;
stroke(0,150,0);
strokeWeight(2);
line(kelpPosition-wide,y,kelpPosition-wide/2,y);
}
}