-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththink.py
executable file
·62 lines (48 loc) · 1.63 KB
/
think.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
#!/usr/bin/env python
# Thinking Machines-like LEDs
import pygame
import numpy
import random, time
RESX, RESY = 16, 32 # LED resolution
SIZE = 20 # LED size
COLOR = 200, 0, 0 # LED RGB color
UPDATE = 2/16 # update interval
led = numpy.zeros((RESX, RESY))
class Dazzler:
def __init__(s):
pygame.init()
s.screen = pygame.display.set_mode((RESX * SIZE, RESY * SIZE))
pygame.display.set_caption('Think')
s.clock = pygame.time.Clock()
s.dazz = pygame.Surface((RESX, RESY))
s.last = 0
def events(s):
for event in pygame.event.get():
if event.type == pygame.QUIT: s.running = False
def run(s):
s.running = True
while s.running:
s.clock.tick(50)
s.events()
s.update()
pygame.quit()
def update(s):
if time.time() - s.last > UPDATE:
s.last = time.time()
for j in range(RESY):
if (j // 4) % 2:
led[1:,j] = led[:-1,j]
led[0,j] = random.choice([0, 0, 0, 1])
else:
led[:-1,j] = led[1:,j]
led[-1,j] = random.choice([0, 0, 0, 1])
for i in range(RESX):
if led[i,j]:
pygame.draw.line(s.dazz, COLOR, (i, j), (i, j), 1)
else:
pygame.draw.line(s.dazz, (0, 0, 0), (i, j), (i, j), 1)
out = pygame.transform.scale(s.dazz, (RESX * SIZE, RESY * SIZE))
s.screen.blit(out, (0, 0))
pygame.display.flip()
c = Dazzler()
c.run()