]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
lamp: snake2, a little more animated :)
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 22 Oct 2016 02:40:10 +0000 (22:40 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 22 Oct 2016 02:40:10 +0000 (22:40 -0400)
draw-snake2.lua [new file with mode: 0644]

diff --git a/draw-snake2.lua b/draw-snake2.lua
new file mode 100644 (file)
index 0000000..e6ce82e
--- /dev/null
@@ -0,0 +1,39 @@
+-- a more curious snake with occasional red "heart" nearby
+--
+--    1 2 3 4 5 6 7 8
+-- 00 o o o o o h x h
+-- 08 o o o o o e x o
+-- 16 o o w w o o x o
+-- 24 x x w w x x x o
+--
+return function(t,fb,g,r,b)
+  local ix = 2 -- since we start effectively in state 1...
+  local c = string.char(g,r,b)
+  local ft = {   -- flatten out
+               [1] = function() fb:set(27,c) fb:set(19,0,0,0) end
+                 -- stay that way
+             , [2] = function() end
+                 -- look back
+             , [2] = function() fb:set(6,c) fb:set(8,0,0,0) end
+                 -- look forward
+             , [3] = function() fb:set(6,0,0,0) fb:set(8,c) end
+                 -- heart on (like what we see)
+             , [4] = function() fb:set(14,0,0xf,0) end
+                 -- slither 1
+             , [5] = function() fb:set(20,c) fb:set(28,0,0,0) end
+                 -- slither 2
+             , [6] = function() fb:set(19,c) fb:set(20,0,0,0) fb:set(27,0,0,0) fb:set(28,c) end
+                 -- slither 1, heart off
+             , [7] = function() fb:set(20,c) fb:set(28,0,0,0) fb:set(14,0,0,0) end
+                 -- slither 2
+             , [8] = function() fb:set(19,c) fb:set(20,0,0,0) fb:set(27,0,0,0) fb:set(28,c) end
+             }
+  fb:fill(0,0,0)
+  fb:set(25,c) fb:set(26,c) fb:set(27,c) fb:set(28,c) fb:set(29,c) fb:set(30,c)
+  fb:set(23,c) fb:set(15,c) fb:set(7,c) fb:set(8,c)
+  t:register(500,tmr.ALARM_AUTO,function()
+    ft[ix]()
+    ix = (ix == 8 and 1) or ix + 1
+    dodraw()
+  end)
+end