adding mouse released ellipses

edited September 2016 in Questions about Code

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();}

Tagged:

Answers

Sign In or Register to comment.