-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelperfunctions.py
87 lines (71 loc) · 1.98 KB
/
helperfunctions.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import datastructures as ds
import config as conf
def generateJSON(data: [], rot: [], mirr: [], zigzag: []):
message = {}
message['brightnessFactor'] = 0.1
message['panels'] = []
for i in range(len(data)):
panel = {}
panel["rot"] = rot[i]
panel["mirr"] = mirr[i]
panel["zigzag"] = zigzag[i]
panel["dots"] = data[i]
message['panels'].append(panel)
return message
def clamp(x):
return max(0, min(x, 255))
def clampTuple(x: tuple):
return tuple([clamp(val) for val in x])
#point order in x1, y2, x2, y2...
def setPointsAbsolute(*argv):
points = []
i = 0
while i < len(argv):
tmp = ds.Vector()
tmp.x = argv[i]
tmp.y = argv[i + 1]
if i == 0:
tmp.x = 0
elif i is len(argv) - 2:
tmp.x = conf._MatrixSizeX - 1
i += 2
if tmp.x < 0:
tmp.x = 0
if tmp.y < 0:
tmp.y = 0
if tmp.x > conf._MatrixSizeX - 1:
tmp.x = conf._MatrixSizeX - 1
if tmp.y > conf._MatrixSizeY - 1:
tmp.y = conf._MatrixSizeY - 1
points.append(tmp)
return points
#point order in x1, y1, x2, y2...
def setPointsRelative(*argv):
points = []
i = 0
while i < len(argv):
minX = 1 / conf._MatrixSizeX
minY = 1 / conf._MatrixSizeY
tmp = ds.Vector()
tmp.x = argv[i]
tmp.y = argv[i + 1]
if i == 0:
tmp.x = 0
elif i is len(argv) - 2:
tmp.x = 1
i += 2
if tmp.x < 0:
tmp.x = 0
if tmp.y < 0:
tmp.y = 0
if tmp.x > 1 - minX:
tmp.x = 1 - minX
if tmp.y > 1 - minY:
tmp.y = 1 - minY
scalingVector = ds.Vector(conf._MatrixSizeX, conf._MatrixSizeY)
tmp *= scalingVector
#convert to int bc dealing only with full pixels
tmp.x = round(tmp.x)
tmp.y = round(tmp.y)
points.append(tmp)
return points