I'm working in CMU CS Academy's Sandbox and I currently have a function that will draw a rectangle of random size, color, and position:
# List of colors
app.colors = ['crimson', 'gold', 'dodgerBlue', 'mediumPurple']
# Creating random shapes
import random
# Draws a random rectangle with random points for size and center along with a random color
def drawRect(x, y):
color = random.choice(app.colors)
x = random.randint(5,390)
y = random.randint(15,300)
w = random.randint(10,40)
h = random.randint(10,40)
r = Rect(x,y,w,h,fill=color,border='dimGray')
x = r.centerX
y = r.centerY
# Draws multiple random rectangles
def drawRects():
for i in range(5):
x = 50 * i
y = 60 * i
drawRect(x,y)
drawRects()
However, I want to add all the random rectangles that the function draws to a group so that I'm able to use the .hitsShape() method.
I also thought about creating a list with the random x and y values, but I'm not sure how to create a list with coordinates in CS Academy. What should I do to my current code? What should I do next?