-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw-heartstream.lua
More file actions
62 lines (51 loc) · 2.15 KB
/
draw-heartstream.lua
File metadata and controls
62 lines (51 loc) · 2.15 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
return function(t,fb,p)
local c, c2
local z = string.char(0,0,0)
local function reinit()
c = p[1]
c2 = p[2] or c
end
reinit()
local s = {}
local b = {}
-- fill sequence table
local ft = { [1] = function() local k,v for k,v in ipairs(s) do fb:set(8 + v,c2) end end, -- side chambers
[2] = function() local k,v for k,v in ipairs(s) do fb:set(8 + v,z) end
local k,v for k,v in ipairs(b) do fb:set(16 + v,c2) end end, -- bottom chambers
[3] = function() local k,v for k,v in ipairs(b) do fb:set(16 + v,z) end end, -- empty
[4] = function() end -- stay empty
}
-- heart sequence table (leftmost column only; see use of fb:shift below)
local ht = { [1] = function() fb:set(9,c) end,
[2] = function() fb:set(1,c) fb:set(17,c) table.insert(s,1,1) end,
[3] = function() fb:set(9,c) fb:set(25,c) table.insert(b,1,1) end,
[4] = function() fb:set(1,c) fb:set(17,c) table.insert(s,1,1) end,
[5] = function() fb:set(9,c) end,
[6] = function() end,
}
-- update fill positions when advancing frame
local function fm()
local k,v
for k,v in ipairs(b) do if v == 8 then table.remove(b,k) else b[k] = v+1 end end
for k,v in ipairs(s) do if v == 8 then table.remove(s,k) else s[k] = v+1 end end
end
fb:fill(0,0,0)
local tix = 0
local fix = #ft
local hix = 1
t:register(150,tmr.ALARM_AUTO,function()
fm() ; fb:set(8,z) fb:set(16,z) fb:set(24,z) ; fb:shift(1,ws2812.SHIFT_LOGICAL)
-- heart positions
ht[hix]()
hix = (hix == #ht and 1) or hix + 1
-- fill positions always render (may be superfluous)
tix = (tix + 1) % 3
if tix == 0 then
fix = (fix == #ft and 1) or fix + 1
end
ft[fix]()
dodraw()
end)
--local hixp for hixp = 1,hix do ht[hixp]() end; local fixp for fixp=1,fix do ft[fixp]() end;
return { ['ncolors'] = 2, ['cccb'] = function() reinit(); local fixp for fixp=1,fix do ft[fixp]() end; dodraw() end }
end