Hi, I really need help with this code. I’ve been trying to make infinite jellyfish appear from the bottom of the screen and move upwards until they disappear. For some reason after a while the jellyfish start appearing from the middle of the screen even though I set the translation to more than 800 and only 4 of them appear. I’m thinking that more are being added too far up the screen so they’re not visible. Below is the code:
float xSpeed;
float ySpeed;
float ellipseX = 500;
float ellipseY = 550;
ArrayList<Jellyfish> jellies = new ArrayList<Jellyfish>();
ArrayList<Jellyfish> visibleJellies = new ArrayList<Jellyfish>();
float ty = 500;
int time=0;
int counter;
void setup(){
counter=0;
for(int i =0; i<100; i++){
jellies.add(new Jellyfish(random(0, 1500), 850, random(-40, 40), random(0.05, 0.35)));
}
size(1500, 850);
void draw() {
background(8, 22, 46);
for (int s = 0; s < stars.length; s++) {
stars[s].display();
}
image(b, 0, 0);
if (millis()>time+2000) {
time=millis();
visibleJellies.add(jellies.get(counter));
if (counter < 100) counter++;
else counter = 0;
}
for (int i = 0; i < visibleJellies.size(); i++) {
visibleJellies.get(i).display();
}
}
class Jellyfish{
float transX;
float transY;
float r;
float s;
Jellyfish(float transX, float transY, float r, float s){
this.transX = transX;
this.transY = transY;
this.r = r;
this.s = s;
}
void display(){
pushMatrix();
translate(transX, transY);
rotate(radians(r));
scale(s);
strokeWeight(5);
fill(5, 29, 242, 40);
stroke(5, 29, 242);
xSpeed += 0;
ySpeed -= random(5, 6);
beginShape();
strokeWeight(12);
arc(500+xSpeed, 500+ySpeed, 500, 500, -PI, 0);
endShape();
//tentacle1
beginShape();
noFill();
curveVertex(500+xSpeed, ty+ySpeed);
curveVertex(500+xSpeed, ty+ySpeed);
curveVertex(600+xSpeed, ty+250+ySpeed);
curveVertex(550+xSpeed, ty+350+ySpeed);
curveVertex(475+xSpeed, ty+400+ySpeed);
endShape();
//tentacle2
beginShape();
noFill();
curveVertex(375+xSpeed, ty+ySpeed);
curveVertex(375+xSpeed, ty+ySpeed);
curveVertex(325+xSpeed, ty+100+ySpeed);
curveVertex(350+xSpeed, ty+325+ySpeed);
curveVertex(250+xSpeed, ty+350+ySpeed);
endShape();
//tentacle3
beginShape();
noFill();
curveVertex(650+xSpeed, ty+ySpeed);
curveVertex(650+xSpeed, ty+ySpeed);
curveVertex(650+xSpeed, ty+100+ySpeed);
curveVertex(700+xSpeed, ty+325+ySpeed);
curveVertex(550+xSpeed, ty+350+ySpeed);
endShape();
popMatrix();
}
}