-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.py
41 lines (34 loc) · 1.13 KB
/
animation.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
""" This contains the Animation class which generates a pygame
animation of the lights """
import pygame
import numpy as np
import sys
DIMENSIONS = (1000, 50)
BLACK = (0, 0, 0)
BORDER = 20
class Animation:
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode(DIMENSIONS)
self.screen.fill(BLACK)
def draw_circles(self, values):
coords, diameter = spacing(len(values),
DIMENSIONS[0],
DIMENSIONS[1],
BORDER)
radius = int(diameter / 2)
for i, coord in enumerate(coords):
pygame.draw.circle(self.screen, values[i], coord, radius)
def update(self, values):
self.draw_circles(values)
pygame.display.update()
for evt in pygame.event.get():
if evt.type == pygame.QUIT:
pygame.quit()
sys.exit()
def spacing(n, width, height, border):
xs = np.linspace(border, width - border, n).astype(int)
y = [height - border] * n
coords = zip(xs, y)
diameter = xs[1] - xs[0]
return coords, diameter