-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpongarGui.pd_lua
More file actions
153 lines (133 loc) · 4.39 KB
/
pongarGui.pd_lua
File metadata and controls
153 lines (133 loc) · 4.39 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
local Scan = pd.Class:new():register("pongarGui")
function Scan:initialize(sel, atoms)
--self.inlets = 1
self:setsize(450)
self.pdiam = 20
self.border = 10
self.pan = 0
self.tilt = 0
self.player_width = 30
self.players = {}
self.scan_offset = 0
self.rcv_name = "pongarGui"
if(atoms and atoms[1]) then self.rcv_name = atoms[1] end
return true
end
function Scan:postinitialize()
self.receiver = pd.Receive:new():register(self, self.rcv_name, "receive")
pd.post("receive name: "..self.rcv_name)
end
function Scan:finalize()
self.receiver:destruct()
end
local function clamp(val, lower, upper)
if lower > upper then lower, upper = upper, lower end -- swap if boundaries supplied the wrong way
return math.max(lower, math.min(upper, val))
end
function Scan:receive(sel, atoms)
--pd.post("received "..sel.." : "..tostring(atoms))
--if(sel == "size") self.in_1_size
self["in_1_"..sel](self, atoms)
end
function Scan:setsize(s)
self.size = s
self.center = self.size / 2
self.radius = self.size / 2
self:set_size(self.size, self.size)
end
function Scan:in_1_size(d)
self:setsize(d[1])
end
function Scan:in_1_pos(d)
self.pan = d[1]
self.tilt = d[2]
--pd.post("new pos " .. self.pan .. " " .. self.tilt)
self:repaint()
end
function Scan:in_1_players(d)
self.players = d
--pd.post("nb players " .. #(self.players))
end
function Scan:in_1_collect(d)
collectgarbage()
end
local pi = math.pi
local sqrt = math.sqrt
local sin = math.sin
local cos = math.cos
function Scan:paint(g)
--g:set_color(50, 50, 50)
--g:fill_all()
-- background
g:set_color(0 , 0, 70)
g:fill_ellipse(0, 0, self.size, self.size, 1)
-- dmx spot position
local r = (self.radius - self.pdiam / 2 - 0 * self.border) * self.tilt
local x = self.center + r * cos(self.pan / 180 * pi) - self.pdiam / 2
local y = self.center + r * sin(self.pan / 180 * pi) - self.pdiam / 2
g:set_color(255, 50, 0, 0.3)
g:fill_ellipse(x, y, self.pdiam, self.pdiam)
-- players
g:set_color(20, 250, 0, 1)
local pw = self.player_width
for i = 1, #(self.players) do
local c = self.players[i]
local path = nil
for c2 = c - pw / 2, c + pw / 2 do
local a = 2 * pi * (c2 / 360)
local x, y = (self.radius - 3 * self.border / 2) * cos(a) + self.center, (self.radius - 3 * self.border / 2) * sin(a) + self.center
if(path) then path:line_to(x, y)
else path = Path(x, y)
end
end
if(path) then g:stroke_path(path, self.border); end
end
-- draw lidar detection
local t = pd.table("lidar_distance_masked")
if(t) then
local l = t:length()
--local a = 2 * pi * (359/360)
g:set_color(220, 250, 0, 1)
local path = nil
for i = 0, l-1 do
local a = 2 * pi * (i / l)
local p = t:get(i) < 4000
local x, y = (self.radius - self.border / 2) * cos(a) + self.center, (self.radius - self.border / 2) * sin(a) + self.center
if(p) then
if(path) then path:line_to(x, y)
else path = Path(x, y)
end
else if(path) then g:stroke_path(path, self.border); path = nil; end
end
end
if(path) then g:stroke_path(path, self.border); path = nil; end
t = nil
end
-- pixels
local pixels = pd.table("pixelsRGB")
if(pixels) then
local l = pixels:length() / 3
local diam = 8
local R = self.radius -- + diam / 2
for i = 0, l-1 do
local a = 2 * pi * (i / l)
--local r = pixels:get(i * 3), g = pixels:get(i * 3 + 1), b = pixels:get(i * 3 + 2)
local red, green, blue = pixels:get(i * 3), pixels:get(i * 3 + 1), pixels:get(i * 3 + 2)
--red = 255 * sqrt(red / 255)
local x, y = R * cos(a) + self.center, R * sin(a) + self.center
g:set_color(red, green, blue, 1)
g:fill_ellipse(x - diam / 2, y - diam / 2, diam, diam);
end
pixels = nil
end
end
function Scan:in_1_bang()
self:repaint()
end
function Scan:postreload()
-- stuff to do post-reload goes here
pd.post("Scan reloaded!")
-- instead of doing a full initialization, you could also just change the
-- number of inlets and outlets here
self:initialize()
end