-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpainel.py
More file actions
91 lines (71 loc) · 2.68 KB
/
painel.py
File metadata and controls
91 lines (71 loc) · 2.68 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import socket
import numpy as np
import time
UDP_IP = "192.168.50.50"
UDP_PORT = 2711
HEAD_BYTE = 0
HEAD_AMOUNT = 1
message = [HEAD_BYTE, 0, 0, 0, 100]
L = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
LHC = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0],
[1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0],
[1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
SHIP = np.array([[0, 1, 0],
[1, 1, 1]])
INVASOR = np.array([[1, 1],
[1, 1]])
BULLET = np.array([[1]])
class Sprite():
def __init__(self):
self.drawing = []
# Position of left up pixel
self.position = (0, 0)
# RGB color, 8 bits each
self.color = [0, 0, 0]
self.visible = True
class LedPanelLHC():
def __init__(self):
self.spriteList = []
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def addSprite(self, sprite):
self.spriteList.append(sprite)
def draw(self):
frame = [[[0, 0, 0] for a in range(10)] for b in range(10)]
for sprite in self.spriteList:
'''
>>> import numpy as np
>>> frame = np.array([[[a, b, a+b] for a in range(10)] for b in range(10)])
>>> frame[0:2,0:2]=[[[111,111,111],[222,222,222]],[[333,333,333],[444,444,444]]]
'''
a = 0
fullFrame = LHC
while True:
time.sleep(0.25)
fullFrame = np.concatenate((fullFrame[:, 1:20], fullFrame[:, 0:1]), axis=1)
frame = fullFrame[:, 0:10]
frameArray = np.ravel(frame.T)
COLOR = [0, 255, 0]
image = []
for pixel in frameArray:
for color in COLOR:
image.append(pixel * color)
message += image
message = bytearray(message)
sock.sendto(message, (UDP_IP, UDP_PORT))
message = [HEAD_BYTE, 0, 0, 0, 100]