brin
YaBB Newbies
Offline
Posts: 13
add moving objects
Sep 17th , 2006, 2:26am
Hi, I started the following sketch: within a certain area ellipses are added in succession and move away instantly after they appear. The problem is, that EITHER they move away and the next ellipse isn´t drawn before the first one leaves the display window. OR every loop draws a new ellipse, the last one disappeares. The intention is to add new ellipses while the others move away undisturbed. Presumably the x-coordinate (or the ellipse-array?) has to be variable, so it won´t be extinguished by the next loop. But how could I do this? Thanks for help! int num = 10; MyEllipse[] e = new MyEllipse[num]; int a = 30; int b = 30; int s; void setup() { size(400,400); e[1] = new MyEllipse(random(50,100),random(50,350),a,b); framerate (30); } void draw() { background (255); noStroke(); fill(0,0,255,100); rect(50,50,100,300); int i=1; //EITHER //for(int i=0; i<10; i++){//OR //e[i] = new MyEllipse(random(50,100),random(50,350),a,b);//OR e[i].drawElli(); e[i].x++; if (e[i].x-a > width) { e[i] = new MyEllipse(random(50,100),random(50,350),a,b); } // }//OR } void mousePressed() { if(mousePressed) { e[1] = new MyEllipse(random(50,100),random(50,350),a,b); } } class MyEllipse { float x, y, a, b; MyEllipse(float x, float y, float a, float b) { this.x = x; this.y = y; this.a = a; this.b = b; } MyEllipse(MyEllipse e) { if (e!=null) { x = e.x; y = e.y; } } void drawElli() { smooth(); noStroke(); fill(255,0,0); ellipse(e[1].x,e[1].y,a,b); } }