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

**URL:** https://discourse.processing.org/t/is-there-a-way-to-use-a-command-that-draws-what-i-want-instead-of-using-e-g-rect-or-ellipses-very-much/35402
**Category:** Coding Questions
**Created:** [February 23, 2022, 8:39pm UTC](https://discourse.processing.org/t/is-there-a-way-to-use-a-command-that-draws-what-i-want-instead-of-using-e-g-rect-or-ellipses-very-much/35402 "2022-02-23T20:39:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Coder1](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Coder1](https://discourse.processing.org/u/Coder1)
#### Post date: [February 23, 2022, 8:39pm UTC](https://discourse.processing.org/t/is-there-a-way-to-use-a-command-that-draws-what-i-want-instead-of-using-e-g-rect-or-ellipses-very-much/35402/1 "2022-02-23T20:39:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [February 23, 2022, 9:25pm UTC](https://discourse.processing.org/t/is-there-a-way-to-use-a-command-that-draws-what-i-want-instead-of-using-e-g-rect-or-ellipses-very-much/35402/2 "2022-02-23T21:25:47Z")

</div>

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

```auto
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() {
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 24, 2022, 11:40am UTC](https://discourse.processing.org/t/is-there-a-way-to-use-a-command-that-draws-what-i-want-instead-of-using-e-g-rect-or-ellipses-very-much/35402/3 "2022-02-24T11:40:06Z")

</div>

> [@Coder1](#):
>
> create an animation?

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!

```auto
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);
}

```

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [February 24, 2022, 5:22pm UTC](https://discourse.processing.org/t/is-there-a-way-to-use-a-command-that-draws-what-i-want-instead-of-using-e-g-rect-or-ellipses-very-much/35402/4 "2022-02-24T17:22:31Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Coder1](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Coder1](https://discourse.processing.org/u/Coder1)
#### Post date: [March 1, 2022, 9:46am UTC](https://discourse.processing.org/t/is-there-a-way-to-use-a-command-that-draws-what-i-want-instead-of-using-e-g-rect-or-ellipses-very-much/35402/5 "2022-03-01T09:46:15Z")

</div>

Thank you that helped me a lot!
