I’m trying to make particles fall from wherever the mouse is clicked and each mousebutton displays a different type of particle. My main code for just the right mouse button works perfectly with rainbow particles. I added a second class and just changed it to all white particles to see if it would work and I get an error message. My code works on processing (the program) but on repl.it (with a plugin to read processing) it does not work. here’s my code:
List<Particle> particles;
List<Right> rights;
void setup()
{
size(500, 500);
particles = new ArrayList<Particle>();
rights = new ArrayList<Right>();
}
void draw()
{
background(20, 25, 50);
fill(255);
text(particles.size() + rights.size(),250,50);
if (mousePressed && (mouseButton == LEFT)){
particles.add(new Particle(mouseX,mouseY));
}
if(mousePressed && (mouseButton == RIGHT)){
rights.add(new Right(mouseX,mouseY));
}
for(int i=0; i < particles.size(); i++){
particles.get(i).display();
particles.get(i).update();
particles.get(i).delete();
}
for(int i=0; i < rights.size(); i++){
rights.get(i).display();
rights.get(i).update();
rights.get(i).delete();
}
}
class Right
{
float x;
float y;
float grav;
float ySpeed;
float xSpeed;
float r1;
float g1;
float b1;
Right(float x, float y)
{
this.x = x;
this.y = y;
xSpeed = random(-1,1);
ySpeed = 1;
grav = 0.2;
r1=random(255);
g1=random(255);
b1=random(255);
}
void update(){
x+= xSpeed;
y+= ySpeed;
ySpeed+= grav;
}
void display(){
fill(255,255,255);
ellipse(x,y,5,5);
}
void delete(){
if(y > height || x > width || x < 0 || y<0){
rights.remove(this);
}
}
}
I left out the other particle class and it is named Right because I tried renaming it a couple times thinking that was the issue.