iamhorse
YaBB Newbies
Offline
Posts: 2
Help with removing array elements. *Idiot Beginner
Jan 10th , 2009, 12:01am
Hello, I'm new to programming and processing. Not sure if this is a silly question. I would be very grateful if anyone can helpppp? What I am trying to do is have one wiimote adding random circles to a screen and one wiimote subtracting the random circles from the screen. I have got both wiimotes talking to processing and have one creating circles, I am stuck on trying to remove them with the other controller..... Here is the code..... import oscP5.*; // imports OpenSoundControl libraries, these are used to allow the WiiMote to talk to Processing import netP5.*; WiiRemote wiiRemote; // imports WiiRemote class WiiRemoteII wiiRemoteII; //imports second wiimote class ArrayList balls; //imports ball class as an array void setup() { size (screen.width, screen.height); // sets window size to full screen frameRate(30); // sets frame rate to 30 fps noStroke(); // removes lines from around objects smooth(); // ensures object curves are smooth background(0); // sets background colour as black wiiRemote = new WiiRemote(); // creates new WiiRemote object wiiRemoteII = new WiiRemoteII(); // creates second remote object balls = new ArrayList(); // creates new ball array } void draw() { float x = random(1,width); float y = random(1,height); float bounce2 = ((wiiRemoteII.acc.x + wiiRemoteII.acc.y + wiiRemoteII.acc.z)/3.0)-100; float bounce = ((wiiRemote.acc.x + wiiRemote.acc.y + wiiRemote.acc.z)/3.0)-100; if(bounce < 10.0 || bounce > 40.0) { balls.add(new Ball(x,y,30)); } int del = int(random(balls.size())); for (int i = balls.size()-1; i >= 0; i--) { Ball ball = (Ball) balls.get(i); if (bounce2 < 10.0 || bounce2 > 40.0) { balls.remove(del); } println(del); } } void mousePressed() { background(0); } class Ball { float x,y; color c; float mass = 10.0; Ball(float inx, float iny, float inmass) { x = inx; y = iny; mass = inmass; c = color(random(255), random(255), random(255)); fill(c); ellipse(x,y,mass,mass); } }