Random
in
Programming Questions
•
1 year ago
I am trying to draw random fishes in this aquarium but I am only seeing one fish why ? Please if one can help me out !
Here is the code :
void setup () {
size (900,600);
background (0) ;
// aquarium body
stroke (0);
fill (255,102); // using alpha transparency
rectMode (CENTER);
rect (450,320,800,500);
//
for (int i=1; i<=30; i++) ; {
drawFish (int (random (450,370)), int (random (320,400)), int (random (20,65)), int (random (30,60)), int (random (0,2)), int (random (0,255)), int (random (0,255)), int (random (0,255)));
}
}
void drawFish (int x, int y, int w, int h, int d, int c1, int c2, int c3) {
//body
fill (c1,c2,c3) ;
ellipse (x,y,w,h);
//direction - odd left, even right
if (d%2==0) {
// tail
fill (c1,c2,c3);
triangle (x-(w/2),y,x-w,y+(h/2),x-w,y-(h/2));
//outer eye
fill (255);
ellipse(x+(w/4),y-(h/4),8,8);
//inner eye
fill (0);
ellipse (x+(w/4),y-(h/4),4,4) ; }
else {
//tail oppposite side
fill (c1,c2,c3);
triangle (x+(w/2),y,x+w,y-(h/2),x+w,y+(h/2));
//outer eye opposite side
fill (255);
ellipse (x-(w/4),y-(h/4),8,8);
//inner eye
fill (0);
ellipse (x-(w/4), y-(h/4),4,4);
}
}
Here is the code :
void setup () {
size (900,600);
background (0) ;
// aquarium body
stroke (0);
fill (255,102); // using alpha transparency
rectMode (CENTER);
rect (450,320,800,500);
//
for (int i=1; i<=30; i++) ; {
drawFish (int (random (450,370)), int (random (320,400)), int (random (20,65)), int (random (30,60)), int (random (0,2)), int (random (0,255)), int (random (0,255)), int (random (0,255)));
}
}
void drawFish (int x, int y, int w, int h, int d, int c1, int c2, int c3) {
//body
fill (c1,c2,c3) ;
ellipse (x,y,w,h);
//direction - odd left, even right
if (d%2==0) {
// tail
fill (c1,c2,c3);
triangle (x-(w/2),y,x-w,y+(h/2),x-w,y-(h/2));
//outer eye
fill (255);
ellipse(x+(w/4),y-(h/4),8,8);
//inner eye
fill (0);
ellipse (x+(w/4),y-(h/4),4,4) ; }
else {
//tail oppposite side
fill (c1,c2,c3);
triangle (x+(w/2),y,x+w,y-(h/2),x+w,y+(h/2));
//outer eye opposite side
fill (255);
ellipse (x-(w/4),y-(h/4),8,8);
//inner eye
fill (0);
ellipse (x-(w/4), y-(h/4),4,4);
}
}
1