arrays - Append does not work with mousepressed? -


i having issue project, , cannot figure out. processing telling me have not array, not see how not. also, issue occurs when click mouse in attempt make else appear.

int numparticles = 200;  genparticle [] p = new genparticle[numparticles];  float r=170; float g=150; float b=85; float velx; float vely;  void setup(){   size(500,500);   nostroke();   smooth();   framerate(30);   (int i=0; i<p.length; i++){      velx = random(-1,1);      vely = -i;     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, velx, 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);   } } 

syntax error: array first parameter , object want append second parameter of append() function

your mousepressed should this:

void mousepressed() {      genparticle gp = new genparticle(mousex,mousey, velx, vely,5.0,mousex,mousey);     p = (genparticle[]) append(p,pg); } 

notice array p goes first, object (append array p object pg).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -