Is there a way to use a command that draws what I want instead of using e.g. rect or ellipses very much?

Hello. I would like to know if there is a way to use a command or a function instead of using e.g. ellipse or rect very very often to create an animation? Here is an example:
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);
rect(x,y -= g,g,g);

Thank you for your help.

1 Like

You could use a ‘for’ loop to draw a large number of rectangles.

void setup() {
  size(400, 600);
  int x, y, g;
  x = 30;
  y = 550;
  g = 20;

  for (int i = 0; i < 24; i++) {
    rect(x, y -= g, g, g);
  }
}

void draw() {
}
1 Like

Essentially draw() is made to show animations.

It loops automatically.

It updates the screen at its end only so you won’t see an animation with a for loop!

int x, y, g;
int speed = 1; 

void setup() {
  size(600, 600);

  x = 30;
  y = 550;
  g = 20;
}

void draw() {
  background(0);

  rect(x, y -= speed, g, g);
}

Point taken. I was just going by what was posted, and it showed a bunch of squares stacked on top of one another. There was no animation in the original post. Now he knows how to do animation as well as stack a bunch of squares.

1 Like

Thank you that helped me a lot!

1 Like