We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a bouncing ellipse, but I can't seem to get the code right for adding new mouseReleased ellipses that will be separate from each other, but will also bounce. I have tried many variations of mouseReleased shape.draw, but cannot get it right. This is the extent of what I can get working.
class Shape{ float x = 0; float y = 0; float xspeed = 1; float yspeed = 1.3;
Shape(){} void draw(){ x = x + xspeed; y = y + yspeed;
if ( (x > width) || (x < 0)) { xspeed = xspeed * -1; } if ( (y > height) || (y < 0)) { yspeed = yspeed * -1; }
stroke(0); fill(175); ellipse(x, y, 10, 10); } }
Shape shape;
void setup(){ size(400,400); shape = new Shape(); background(175); smooth(); }
void draw(){ noStroke(); //fill(255,10); rect(0,0,width, height);
shape.draw();}
Answers
If you want to have more than one ball bouncing around, then you're going to have to have multiple instances of
Shape. You might want to use anArrayListto keep track of them for you.Here is a tutorial on using ArrayLists in Processing to have multiple circles on the screen. (Disclaimer: I wrote it.)
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
http://studio.SketchPad.cc/sp/pad/view/ro.9oyKfI9kOIa77/latest
https://forum.Processing.org/two/discussions/tagged?Tag=#bounce