Enter graph data and test pygame

This commit is contained in:
Aaron Fenyes 2019-09-28 16:42:50 +02:00
parent 605080a9db
commit e3e00bac3d
1 changed files with 76 additions and 0 deletions

76
interactions.py Normal file
View File

@ -0,0 +1,76 @@
from math import pi, cos, sin
import pygame, colorsys
# === graph data ===
# vertices as screen positions
viewsize = 600
shrink = 0.9
vertices = [(viewsize*(1 + shrink*x)/2, viewsize*(1 + shrink*y)/2) for x, y in
[(0, 0)] + [(cos(-n*pi/5), sin(-n*pi/5)) for n in range(10)] + [(0, 0)]
]
# edges as vertex pairs
edges = [
(0, 1), (0, 3), (0, 5), (0, 7), (0, 9),
(2, 8), (2, 6), (6, 10), (10, 4), (4, 8),
(2, 9), (2, 11), (2, 5),
(4, 1), (4, 9), (4, 7),
(6, 3), (6, 11), (6, 9),
(8, 5), (8, 11), (8, 1),
(10, 7), (10, 11), (10, 3),
(9, 3), (9, 5),
(1, 5), (1, 7),
(3, 7)
]
# cyclic edge adjacencies
cyc_edge_adj = [
(0, 1), (1, 2), (2, 3), (3, 4), (4, 0),
(5, 10), (10, 11), (11, 12), (12, 6), (6, 5),
(6, 16), (16, 17), (17, 18), (18, 7), (7, 6),
(7, 22), (22, 23), (23, 24), (24, 8), (8, 7),
(8, 13), (13, 14), (14, 15), (15, 9), (9, 8),
(5, 9), (9, 19), (19, 20), (20, 21), (21, 5),
(4, 10), (10, 25), (25, 26), (26, 18), (18, 4),
(3, 15), (15, 29), (29, 28), (28, 22), (22, 3),
(2, 12), (12, 27), (27, 26), (26, 19), (19, 2),
(1, 24), (24, 25), (25, 29), (29, 16), (16, 1),
(0, 21), (21, 28), (28, 27), (27, 13), (13, 0),
(14, 11), (11, 23), (23, 20), (20, 17), (17, 14)
]
# === phase space ===
litness = 30*[0]
# === main loop ===
if __name__ == '__main__':
# set up display and clock
pygame.display.init()
screen = pygame.display.set_mode((viewsize, viewsize))
pygame.display.set_caption('Preview')
clock = pygame.time.Clock()
to_light = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
litness[to_light] = 1.
for e in range(30):
pygame.draw.aaline(
screen,
tuple(255*c for c in colorsys.hsv_to_rgb(e/30., litness[e], 0.2 + 0.8*litness[e])),
vertices[edges[e][0]],
vertices[edges[e][1]],
)
litness[e] *= 0.9
# step
to_light = (to_light + 1) % 30
pygame.display.flip()
clock.tick(24)