Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1

204 Chapter 8


for n in range(100):
colors[n] = (random.randint(0,255),random.randint(0,255),
random.randint(0,255))
locations[n] = (random.randint(0,800),
random.randint(0,600))
sizes[n] = random.randint(10, 100)

Finally, instead of drawing one dot in our while loop, add
a for loop to draw the 100 random dots by using the colors,
locations, and sizes arrays:

for n in range(100):
pygame.draw.circle(screen, colors[n], locations[n],
sizes[n])

Call your new creation RandomDots.py. The final app
should look something like Figure 8-9 when complete.

Figure 8-9: An advanced version of our dot program, RandomDots.py,
gives us 100 dots of random color, location, and size.
Free download pdf