How would I go about turning this bouncing ball code into code to show multiple random balls?

edited December 2017 in Questions about Code

Im trying to make code based off of my previous code. I want to make random balls come into the screen and then leave the screen from random directions without bouncing. How would I go about doing this?

This is what i have:

float circleX;
float xspeed=3;

void setup(){
  size(400,400);
  circleX=0;
}
void draw(){
  background(51);
  fill(102);
  stroke(255);
  ellipse(circleX,height/2,32,32);

  circleX = circleX + xspeed;

  if(circleX>width || circleX<0){
    xspeed=xspeed*-1.1;
  }
}
Tagged:
Sign In or Register to comment.