mousePressed problems
in
Programming Questions
•
5 months ago
I am trying to make multiple "fireworks" where ever I click the mouse, but it says I am missing a semicolon. I have tried comparing it to other things alike the mousePressed I am trying to use, but it is not working. Am I missing something that someone else can see?
- int numParticles = 200;
GenParticle [] p = new GenParticle[numParticles];
//GenParticle [] p = new GenParticle[1];
float r=170;
float g=150;
float b=85;
void setup(){
size(500,500);
noStroke();
smooth();
frameRate(30);
for (int i=0; i<p.length; i++){
float velX = random(-1,1);
float velY = -i;
//Inputs: x,y,x-velocity,y-velocity,
//radius,origin x,origin y
p[i]=new GenParticle(width/2,height/2,velX,velY,5.0,width/2,height/2);
}
}
void draw(){
fill(0,20);
rect(0,0,width,height);
fill(255,60);
for(int i=0; i<p.length; i++){
p[i].update();
p[i].regenerate();
p[i].display();
}
}
void mousePressed() {
GenParticle gp = new GenParticle(mouseX,mouseY,float velx,float vely,5.0,mouseX,mouseY);
p = (GenParticle[]) append(gp,p);
} - class GenParticle extends Particle{
float originX,originY;
GenParticle(int xIn,int yIn,float vxIn,float vyIn,float r,float ox,float oy){
super(xIn, yIn, vxIn, vyIn, r);
originX=ox;
originY=oy;
}
void regenerate(){
if ((x>width+radius) || (x<-radius) || (y>height+radius) || (y<-radius)){
x=originX;
y=originY;
vx=random(-1.0,1.0);
vy=random(-4.0,-2.0);
}
}
} - class Particle{
float x, y;
float vx,vy;
float radius;
float gravity=0.1;
float r=0;
float g=0;
float b=0;
Particle(int xpos,int ypos,float velx,float vely,float r){
x=xpos;
y=ypos;
vx=velx;
vy=vely;
radius=r;
}
void update(){
vy=vy+gravity;
y += vy;
x += vx;
}
void display(){
fill(r,g,b);
ellipse(x, y, radius*3,radius*3);
if(mouseX>width/2){
r=r+9;
}else{
g=g+6;
}
if(mouseY>height/2){
b=b+7;
}else{
b=b-3;
}
if(keyPressed) {
g=g+1;
}else{
g=g-5;
}
r=constrain(r,0,255);
g=constrain(g,0,255);
b=constrain(b,0,255);
}
}
1