bouncing balls

edited November 2013 in How To...

Hi, i'm new to processing. Below is the code for 1 bouncing ball. But I would like to add another ball. How do i edit my codes?

int rad = 60;
float xpos, ypos; 

float xspeed = 2.8;
float yspeed = 2.2; 

int xdirection = 1;
int ydirection = 1;


void setup() 
{
  size(640, 360);
  noStroke();
  frameRate(30);
  ellipseMode(RADIUS);
  xpos = width/2;
  ypos = height/2;
}

void draw() 
{
  background(102);

  xpos = xpos + ( xspeed * xdirection );
  ypos = ypos + ( yspeed * ydirection );

  if (xpos > width-rad || xpos < rad) {
    xdirection *= -1;
  }
  if (ypos > height-rad || ypos < rad) {
    ydirection *= -1;
  }

  ellipse(xpos, ypos, rad, rad);
}
Tagged:

Answers

Sign In or Register to comment.