sofunk
YaBB Newbies
Offline
Posts: 21
overlapping circles.
Jan 17th , 2008, 8:12pm
Hi all! I designed my program so that the circles inside the applet will move 80 pixels in length when I hold down the mouse. The circles move around randomly across the screen, but the circles should overlap perfectly with one another. I am getting a bug where if I hold down the mouse button for a bit the circles deviate from its 80 pixels restriction... to 79 78 77 etc.... does anyone know what is going on and also how to resolve this? here's the code: int count = 70; Thing[]things = new Thing[count]; void setup(){ background(0); size(640, 800); frame.setResizable(true); frameRate(20); for(int i = 0; i < things.length; i++){ things[i] = new Thing(40,40, int(random(100,210)), 250, 40); } } void draw(){ background(0); noFill(); rect(0, 0, width, height); for(int i = 0; i < things.length; i++){ things[i].display(); if(mousePressed == true){ things[i].move(); println(things[i].x); println(things[i].y); } } } class Thing{ float x, y; int r; int g; int b; int vd = 80; int opacity = 100; int diameter = 80; Thing(int xpos, int ypos, int rr, int gg, int bb){ x = xpos; y = ypos; r = rr; g = gg; b = bb; } void display(){ fill(r, g, b, opacity); smooth(); noStroke(); //ellipseMode(CORNER); ellipse(x, y, diameter, diameter); } void move() { int t = int(random(-2, 2)); int v = int(random(2)); if(v == 0){ x += vd*t; println("5"); println(v); println(t); }else if(v==1){ y += vd*t; println("6"); println(v); println(t); } if (x + diameter/2 > width) { x = width - diameter/2; vd += -1; println("1"); } else if (x - diameter/2 < 0) { x = diameter/2; vd *= -1; println("2"); } if (y + diameter/2 > height) { y = height - diameter/2; vd *= -1; println("3"); } else if (y - diameter/2 < 0) { y = diameter/2; vd *= -1; println("4"); } } }