dark_skeleton

rainbow.lua

Feb 18th, 2017
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. function rainbowize()
  2.     green = {0, 61, 127, 193, 255, 255, 255, 255, 255, 255, 255, 255, 255, 193, 127, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  3.     red   = {255, 255, 255, 255, 255, 183, 127, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 127, 193, 255, 255, 255, 255, 255}
  4.     blue = {0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 127, 193, 255, 255, 255, 255, 255, 255, 255, 255, 255, 193, 127, 61, 0}
  5.  
  6.     rainbow_i = (rainbow_i % table.getn(green))+1
  7.    
  8.     return red[rainbow_i], green[rainbow_i], blue[rainbow_i]
  9. end
  10.  
  11. function dupa()
  12.     ws2812.init()
  13.     rainbow_i = 0
  14.     local dir, i, buffer = 0, 0, ws2812.newBuffer(300, 3);
  15.     buffer:fill(0, 0, 0);
  16.     tmr.create():alarm(25, 1, function()
  17.         if (dir==0) then
  18.           i = i + 1
  19.           if (i == buffer:size()) then
  20.             dir=1
  21.           end
  22.         else
  23.           i = i - 1
  24.           if (i == 0) then
  25.             dir=0
  26.           end
  27.         end
  28.         buffer:mix(220, buffer)
  29.  
  30.         r,g,b = rainbowize()
  31.         buffer:set(i % buffer:size() + 1, r, g, b)
  32.         buffer:set((2 * i) % buffer:size() + 1, r, g, b)
  33.  
  34.         ws2812.write(buffer)
  35.     end)
  36. end
  37.  
  38. dupa()
Advertisement
Add Comment
Please, Sign In to add comment