-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmxspot.pd_lua
More file actions
66 lines (53 loc) · 1.56 KB
/
dmxspot.pd_lua
File metadata and controls
66 lines (53 loc) · 1.56 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
local Scan = pd.Class:new():register("dmxspot")
function Scan:initialize(sel, atoms)
self.inlets = 1
self:setsize(250)
self.pdiam = 20
self.pan = 0
self.tilt = 0
self.pan_offset = 0
return true
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: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
local pi = math.pi
local sin = math.sin
local cos = math.cos
function Scan:paint(g)
--g:set_color(50, 50, 50)
--g:fill_all()
g:set_color(220 , 220, 250)
g:fill_ellipse(0, 0, self.size, self.size, 1)
local r = (self.radius - self.pdiam / 2) * self.tilt / 45
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(50, 200, 20, 0.3)
g:fill_ellipse(x, y, self.pdiam, self.pdiam)
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