Using Loops to Make Objects. Help!

Well once you’re done you might say: “dude now it’s the same but way more complex”. And that’s kind of true. But firstly it’s nicer to look at and secondly, now you can do this:

int r, g, b;
int num_of_balls = 100;
Ball[] balls = new Ball[num_of_balls];

void setup()
{
  size (400, 400);
  smooth();
  
  for (int i = 0; i < balls.length; i++) {
    balls[i] = new Ball((int)random(50, width - 50), (int)random(50, height - 50));
  }
}

void draw()
{
  background(r, g, b);
  
  for (int i = 0; i < balls.length; i++) {
    balls[i].show();
    balls[i].move();
  }
}

void keyPressed()
{
  if (key == ENTER || key == RETURN)
  {
    r = (int) random(255);
    g = (int) random(255);
    b = (int) random(255);
  }
}

class Ball {
  int x = 0;
  int y = 0;
  int xDir = 1;
  int yDir = 1;
  int diam = 20;

  Ball(int x1, int y1) {
    x = x1;
    y = y1;
  }

  void show() {
    fill(255 - (x + y) * .6375 / 2);
    ellipse(x, y, diam, diam);
  }

  void move() {
    if (x > width - diam / 2 || x < diam / 2)
    {
      xDir = -xDir;
    }

    if (y > height - diam / 2 || y < diam / 2)
    {
      yDir = -yDir;
    }

    x = x + xDir;
    y = y + yDir;
  }
}

PS: I cleaned up a bit more…