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
Hello, and welcome to the forum!
Great to have you here!
You need setup and draw in your Sketch.
Then use rect() to display an rectangle. See 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():
Unfortunately, we are not allowed to show you Code.
@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:
def setup(): size(200, 200) def draw(): background(0) # draw shapes here
For drawing rectangles, refer to the relevant Python Mode reference entry: https://py.processing.org/reference/rect.html
x = random(width)is the same in Python.
y += 1. You’ll need to make it a global variable, too.
For more documentation, you can refer to the Processing.py website.