-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsss.py
executable file
·72 lines (53 loc) · 1.47 KB
/
sss.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
#!/usr/bin/env python
import pygame
pygame.init() #do it early and only call once?
import sys, random, time
import math
import threading
W = 120
H = 20
cell_size = 12
#COLORS
black = [0,0,0]
white = [255,255,255]
screen = pygame.display.set_mode((W*cell_size,H*cell_size), pygame.NOFRAME)
clock = pygame.time.Clock()
screenCenter = screen.get_rect().center
changes = pygame.Surface((W*cell_size,H*cell_size))
def idx(x,y):
return W*y + x
def draw_cell(surface, x,y):
r = pygame.Rect((x * cell_size, y*cell_size), (cell_size, cell_size))
pygame.draw.rect(surface, black, r)
width = 0 if cells[idx(x,y)] else 1
pygame.draw.circle(surface, white, r.center, (cell_size / 2) - 1, width)
#init
pygame.draw.rect(screen, black, pygame.Rect( (0,0), (W, H)))
cells = []
for y in range(H):
for x in range(W):
cells.append(False)
draw_cell(screen, x, y)
def read_cmds():
for line in sys.stdin:
# print line
if line.startswith("#"):
continue
coords = line.split()
x = int(coords[0])
y = int(coords[1])
cells[idx(x,y)] = not cells[idx(x,y)]
draw_cell(screen, x,y)
time.sleep(.00005); # the flip time aproximation
t = threading.Thread(target=read_cmds)
t.start()
done = False
while not done:
clock.tick_busy_loop(1500);
pygame.event.pump()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
done = True
pygame.display.update()
pygame.display.flip()
pygame.quit()