Advertisement
Symmetryc

Fireworks 2.0

Oct 4th, 2013
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. local color = {colors.red, colors.orange, colors.yellow, colors.white, colors.lightGray, colors.gray}
  2. local refresh = 0.05
  3. local frequency = 10
  4. local text = {"<Enter Loading Text Here>", colors.lime}
  5. local background = colors.black
  6. local rainbowColors = true
  7. -- change any of the above values to alter the look of the fireworks
  8. term.setBackgroundColor(colors.black)
  9. term.clear()
  10. local fw = {}
  11. local x, y = term.getSize()
  12. color = rainbowColors and {
  13.     {colors.red, colors.orange, colors.yellow, colors.white};
  14.     {colors.green, colors.lime, colors.yellow, colors.white};
  15.     {colors.blue, colors.cyan, colors.lightBlue, colors.white};
  16.     {colors.purple, colors.magenta, colors.pink, colors.white};
  17. } or color
  18. local len = rainbowColors and #color[1] or #color
  19. if rainbowColors then
  20.     for i, t in ipairs(color) do
  21.         t[#t + 1] = background
  22.     end
  23. else
  24.     color[#color + 1] = background
  25. end
  26. local advance = function()
  27.     for k, t in pairs(fw) do
  28.         t[2] = t[3] == 1 and (t[2] + 0.5) or (t[2] - 1)
  29.         t = t[3] == 1 and (t[2] <= (y + len) and t or nil) or (t[2] >= 1 - len and t or nil)
  30.     end
  31. end
  32. local render = function()
  33.     for k, t in pairs(fw) do
  34.         for i = 1, len + 1 do
  35.             if t[2] - i >= 1 then
  36.                 term.setCursorPos(t[1], math.floor(t[2]) - i)
  37.                 term.setTextColor(t[3] == 1 and (rainbowColors and color[t[4]][i] or color[i]) or (rainbowColors and color[t[4]][len + 2 - i] or color[i]))
  38.                 term.write(t[3] == 1 and (t[2] % 1 == 0 and "-" or "_") or string.char(166))
  39.             end
  40.         end
  41.     end
  42.     term.setCursorPos((x - #text[1]) / 2, y / 2)
  43.     term.setTextColor(text[2])
  44.     for char in text[1]:gmatch(".") do
  45.         if char ~=" " then
  46.             term.write(char)
  47.         else
  48.             local xpos, ypos = term.getCursorPos()
  49.             term.setCursorPos(xpos + 1, ypos)
  50.         end
  51.     end
  52. end
  53. local timer = os.startTimer(refresh)
  54. while true do
  55.     do
  56.         local e = {os.pullEvent("timer")}
  57.         if e[2] ~= timer then return end
  58.         advance()
  59.         if math.random(len / refresh / frequency) == 1 then
  60.             local rand = math.random(2)
  61.             fw[{}] = {math.random(x), rand == 1 and 0.5 or y + 1, rand, rainbowColors and math.random(#color) or nil}
  62.         end
  63.         render()
  64.         timer = os.startTimer(refresh)
  65.     end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement