-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiceProblem.py
More file actions
73 lines (66 loc) · 2.08 KB
/
Copy pathMiceProblem.py
File metadata and controls
73 lines (66 loc) · 2.08 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
import pygame, math, time
from random import randint as rand
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((500, 500))
n = 10
skip = 0
clockwise = True
mode = 0
class Mouse:
def __init__(self, x, y, col):
self.x = x
self.y = y
self.col = col
self.nextx = -1
self. nexty = -1
def update(self, x, y):
self.nextx = self.x + (x - self.x)/10
self.nexty = self.y + (y - self.y)/10
def show(self):
pygame.draw.line(screen, self.col, (round(self.x), round(self.y)), (round(self.nextx), round(self.nexty)))
self.x = self.nextx
self.y = self.nexty
modeset = {K_0: 0, K_1: 1, K_2: 2}
inc = 360/n
cx = screen.get_width()/2
cy = screen.get_height()/2
startup = True
while True:
if startup == True:
screen.fill((255, 255, 255))
mice = []
for i in range(n):
col = (i*(255/n), (n-i)*(255/n), 0)
if mode == 0:
r = min(cx, cy)
mice.append(
Mouse(cx + (r * math.cos(math.radians(inc * i))), cy + (r * math.sin(math.radians(inc * i))), col))
elif mode == 1:
r = rand(0, min(cx, cy))
mice.append(
Mouse(cx + (r * math.cos(math.radians(inc * i))), cy + (r * math.sin(math.radians(inc * i))), col))
elif mode == 2:
mice.append(Mouse(rand(0, cx * 2), rand(0, cy * 2), col))
startup = False
if clockwise:
mice.reverse()
for i in range(len(mice)):
M2 = mice[(i + 1 + skip) % len(mice)]
mice[i].update(M2.x, M2.y)
for M in mice:
M.show()
pygame.display.flip()
for e in pygame.event.get():
if e.type == QUIT:
quit()
elif e.type == KEYDOWN:
if e.key == K_ESCAPE:
exit()
elif e.key in modeset.keys():
mode = modeset[e.key]
startup = True
elif e.key == K_SPACE:
clockwise = not clockwise
startup = True
time.sleep(0.03)