-
Notifications
You must be signed in to change notification settings - Fork 0
/
flashy.py
63 lines (49 loc) · 1.51 KB
/
flashy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Rohan Shah
3/17/23
Flashing circles animation that randomly appear and change
"""
import pygame, sys
from pygame.locals import *
import random
pygame.init()
screen = pygame.display.set_mode((400, 400), 0, 32)
pygame.display.set_caption('flashy!')
clock = pygame.time.Clock()
LIGHTCORAL = (240,128,128)
PALEGREEN = (152,251,152)
LAVENDER = (230,230,250)
# Creates the lists of x and y coordinates for the circles.
listX = []
listY = []
list_colors = [LIGHTCORAL, PALEGREEN, LAVENDER]
def add_circle():
centerX = random.randint(0, 400)
centerY = random.randint(0, 400)
listX.append(centerX)
listY.append(centerY)
def remove_circle():
if len(listX) > 10:
remove_ind = random.randint(0, len(listX)-1)
listX.pop(remove_ind)
listY.pop(remove_ind)
def draw_circles():
# Clears the canvas and redraws the background.
pygame.draw.rect(screen, (0, 0, 0), (0, 0, 400, 400))
# Loops over all the coordinates and draws 2 circles with random
# radius and color.
for index, centerX in enumerate(listX):
centerY = listY[index]
radius = random.randint(5, 25)
color = random.choice(list_colors)
pygame.draw.circle(screen, color, (centerX, centerY), radius, 1)
pygame.draw.circle(screen, color, (centerX, centerY), radius+5, 3)
while True:
add_circle()
remove_circle()
draw_circles()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
pygame.display.update()
clock.tick(10)