Newer
Older
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
#!/usr/bin/python
PWIDTH = 5
WIDTH = PWIDTH*96
PHEIGHT = 7
PPAD = 5
HEIGHT = (PHEIGHT+PPAD)*9+PHEIGHT
ZOOM = 2
import pygame, sys
pygame.init()
size = (WIDTH*ZOOM, HEIGHT*ZOOM)
screen = pygame.display.set_mode(size)
import struct
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5570")
def set_pixel(x, y, v):
v = v/255.0
row = y / 7
if row in [0, 1, 2, 9]:
c = (0xff*v, 0, 0)
elif row in [3, 4, 5]:
c = (0, 0xff*v, 0)
else:
c = (0xff*v, 0xa5*v, 0)
y += y / PHEIGHT * PPAD
screen.fill(c, (x*ZOOM, y*ZOOM, ZOOM, ZOOM))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if not socket.poll(1):
pygame.display.update()
continue
message = socket.recv()
x, y, v = struct.unpack_from('iiB', message)
# print("Received request: %r, %r, %r" % (x, y, v))
set_pixel(x, y, v)
socket.send(b"")