Using Loops to Make Objects. Help!

Ok.
When you look at your code you notice that you basically did the same thing 3 times, the only difference is the starting position, right?!

Now I want you to stare at this until you think you understand it and then post your new code, using this as a start, where there are 3 balls flying again. Then we’ll continue :slight_smile:

int diam = 20;
int r, g, b;
myObject ball1;

void setup()
{
  size (400, 400);
  smooth();
  
  ball1 = new myObject(10, 10);
}

void draw()
{
  background(r, g, b);
  
  ball1.show();
  ball1.move();
}

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

class myObject {
  int x = 0;
  int y = 0;
  int xDir = 1;
  int yDir = 1;

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

Here’s a tip:
You don’t need to create a “myObject2”.