Kingdaro

CC Rainbow Animation

May 9th, 2013
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.89 KB | None | 0 0
  1. local time, period, updateTimer, draw
  2. time = 0
  3. period = 0.05
  4. updateTimer = os.startTimer(period)
  5. local rainbow
  6. do
  7.   local _with_0 = colors
  8.   rainbow = {
  9.     _with_0.black,
  10.     _with_0.red,
  11.     _with_0.orange,
  12.     _with_0.yellow,
  13.     _with_0.green,
  14.     _with_0.blue,
  15.     _with_0.purple,
  16.     _with_0.black
  17.   }
  18. end
  19. draw = function()
  20.   do
  21.     local _with_0 = term
  22.     local w, h = term.getSize()
  23.     for x = 1, w do
  24.       for i = 1, #rainbow do
  25.         _with_0.setBackgroundColor(rainbow[i])
  26.         for y = i * 3 - 2, i * 3 do
  27.           y = y + (math.sin(x / 15 + time) * 3)
  28.           _with_0.setCursorPos(x, y)
  29.           _with_0.write(' ')
  30.         end
  31.       end
  32.     end
  33.     return _with_0
  34.   end
  35. end
  36. while true do
  37.   local _, timer = os.pullEvent('timer')
  38.   if timer == updateTimer then
  39.     draw()
  40.     time = time + 0.5
  41.     updateTimer = os.startTimer(period)
  42.   end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment