-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflower.py
More file actions
executable file
·110 lines (90 loc) · 3.5 KB
/
flower.py
File metadata and controls
executable file
·110 lines (90 loc) · 3.5 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pygame
import math
pygame.init()
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('"Flower"')
clock = pygame.time.Clock()
colors = [(255, 0, 0), (100, 149, 237), (0, 255, 0), (0, 255, 127), (173, 216, 230), (0, 0, 255)]
background_color = (0, 0, 0)
radius = 160
total_circles = 36
segments = 360
def draw_circle_segment(x_center, y_center, radius, color, start_angle, end_angle):
paused = False
for angle in range(start_angle, end_angle):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
paused = not paused
if event.key == pygame.K_RETURN:
return False
if event.key == pygame.K_q:
pygame.quit()
return True
if not paused:
x = x_center + radius * math.cos(math.radians(angle))
y = y_center + radius * math.sin(math.radians(angle))
screen.set_at((int(x), int(y)), color)
pygame.display.flip()
pygame.time.delay(1)
return False
def draw_circles():
angle_offset = 0
for i in range(total_circles):
color = colors[i % len(colors)]
x_center = width // 2 + radius * math.cos(math.radians(270 + angle_offset))
y_center = height // 2 + radius * math.sin(math.radians(270 + angle_offset))
for segment in range(0, segments, 10):
if draw_circle_segment(x_center, y_center, radius, color, segment, segment + 10):
return
angle_offset += 10
def rotate_circles():
angle_offset = 0
rotating = True
paused = False
while rotating:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
paused = not paused
if event.key == pygame.K_RETURN:
rotating = False
if event.key == pygame.K_q:
pygame.quit()
return
if not paused:
screen.fill(background_color)
for i in range(total_circles):
color = colors[i % len(colors)]
x_center = width // 2 + radius * math.cos(math.radians(270 + angle_offset))
y_center = height // 2 + radius * math.sin(math.radians(270 + angle_offset))
pygame.draw.circle(screen, color, (int(x_center), int(y_center)), radius, 1)
angle_offset += 10
pygame.display.flip()
angle_offset += 1
clock.tick(60)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
screen.fill(background_color)
draw_circles()
rotate_circles()
if event.key == pygame.K_RETURN:
screen.fill(background_color)
draw_circles()
rotate_circles()
if event.key == pygame.K_q:
running = False
clock.tick(60)
pygame.quit()