# Random falling rectangles

**URL:** <https://discourse.processing.org/t/random-falling-rectangles/19185>\
**Category:** Processing.py\
**Created:** [March 30, 2020, 11:22am UTC](https://discourse.processing.org/t/random-falling-rectangles/19185 "2020-03-30T11:22:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruh\_Momentum](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bruh_momentum/32/8577_2.png) [@Bruh\_Momentum](https://discourse.processing.org/u/Bruh_Momentum)\
**Post date:** [March 30, 2020, 11:22am UTC](https://discourse.processing.org/t/random-falling-rectangles/19185/1 "2020-03-30T11:22:25Z")

</div>

Hi, I would like to know if anyone can help me. I want to have rectangles fall from the top of the window in random x positions, but I am not sure how to do that. If anyone could help, that would be great. I currently don’t have any code for this program. Thanks in advance

---

<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:** [March 30, 2020, 12:41pm UTC](https://discourse.processing.org/t/random-falling-rectangles/19185/2 "2020-03-30T12:41:21Z")

</div>

Hello, and welcome to the forum!

Great to have you here!

Please go to the [processing.org](http://processing.org) website and check the examples. [https://www.processing.org/examples/linear.html](https://www.processing.org/examples/linear.html) - for example section Motion.

You need setup and draw in your Sketch.

See [https://www.processing.org/tutorials/overview/](https://www.processing.org/tutorials/overview/)

Then use rect() to display an rectangle. See reference [https://www.processing.org/reference/](https://www.processing.org/reference/)

Its x is `float x;` before setup (also `float y;` before setup)

` x=random(width);` in setup after size

Then in draw(): `y++;`

Unfortunately, we are not allowed to show you Code.

Chrisir

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [March 30, 2020, 9:05pm UTC](https://discourse.processing.org/t/random-falling-rectangles/19185/3 "2020-03-30T21:05:16Z")

</div>

@Chrisir’s outlined it nicely for you. You’ve posted your question in the Processing.py section, so I’m assuming you’re after Python advice? For Python Mode, the syntax is a little different:

- To setup and draw in your sketch:

- For drawing rectangles, refer to the relevant Python Mode reference entry: [https://py.processing.org/reference/rect.html](https://py.processing.org/reference/rect.html)

- `x = random(width)` is the same in Python.

- In Python, `y++` becomes `y += 1`. You’ll need to make it a [global variable](https://py.processing.org/reference/globals.html), too.

For more documentation, you can refer to the [Processing.py website](https://py.processing.org/).
