-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
73 lines (55 loc) · 1.65 KB
/
test.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
64
65
66
67
68
69
70
71
72
73
import math
import sys
import pygame
# Initialize pygame
pygame.init()
# Set up the window
window_width = 640
window_height = 480
window = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption("Spiral Entities")
# Set up the clock
clock = pygame.time.Clock()
class Entity:
def __init__(self, angle):
self.angle = angle
self.color = (255, 0, 0)
self.size = 10
def update(self, mouse_position, radius):
self.angle += 0.02
self.x = mouse_position[0] + radius * math.cos(self.angle)
self.y = mouse_position[1] + radius * math.sin(self.angle)
def draw(self, surface):
pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), self.size)
# Set up the entities
num_entities = 8
entities = []
for i in range(num_entities):
angle = 2 * math.pi * i / num_entities
entities.append(Entity(angle))
radius = 150
# Start the game loop
while True:
# Handle events
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Get the position of the mouse
mouse_position = pygame.mouse.get_pos()
for event in events:
if event.type == pygame.MOUSEWHEEL:
radius += event.precise_y * 20
# Update the entities
for entity in entities:
entity.update(mouse_position, radius)
# Clear the screen
window.fill((255, 255, 255))
# Draw the entities
for entity in entities:
entity.draw(window)
# Update the display
pygame.display.update()
# Wait for the next frame
clock.tick(60) # limit the frame rate to 60 FPS