Advertisement
1vannn

color

Apr 6th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. local event = require("event")
  2. local keyboard = require("keyboard")
  3. local shell = require("shell")
  4.  
  5. local args,options = shell.parse(...)
  6.  
  7. local redstone = options.r
  8. local lightness = 0.25
  9. local hue = math.random()
  10.  
  11. local function setAllLamps(color)
  12. for a,t in component.list("colorful_lamp") do
  13. component.proxy(a).setLampColor(color)
  14. end
  15. end
  16.  
  17. local function encode(r,g,b)
  18. tmp = r
  19. tmp = bit32.bor(tmp,bit32.lshift(g,5))
  20. tmp = bit32.bor(tmp,bit32.lshift(b,10))
  21. return tmp
  22. end
  23.  
  24. --Stolen from https://github.com/EmmanuelOga/columns/blob/master/utils/color.lua
  25. local function hslToRgb(h, s, l)
  26. local r, g, b
  27.  
  28. if s == 0 then
  29. r, g, b = l, l, l -- achromatic
  30. else
  31. local function hue2rgb(p, q, t)
  32. if t < 0 then t = t + 1 end
  33. if t > 1 then t = t - 1 end
  34. if t < 1/6 then return p + (q - p) * 6 * t end
  35. if t < 1/2 then return q end
  36. if t < 2/3 then return p + (q - p) * (2/3 - t) * 6 end
  37. return p
  38. end
  39.  
  40. local q
  41. if l < 0.5 then q = l * (1 + s) else q = l + s - l * s end
  42. local p = 2 * l - q
  43.  
  44. r = hue2rgb(p, q, h + 1/3)
  45. g = hue2rgb(p, q, h)
  46. b = hue2rgb(p, q, h - 1/3)
  47. end
  48.  
  49. return r * 31, g * 31, b * 31
  50. end
  51.  
  52. local function handler()
  53. setAllLamps(encode(hslToRgb(hue,1,lightness)))
  54. hue = (hue+0.005)%1
  55. end
  56.  
  57. if _G.fancylightsID then event.cancel(_G.fancylightsID) end
  58. if options.c then
  59. setAllLamps(0)
  60. print("FancyLights stopped!")
  61. return
  62. end
  63.  
  64. _G.fancylightsID = event.timer(0.5,handler,math.huge)
  65. print("FancyLights loaded!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement