Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Let there be lights")
- --# Choose a brightness between 1-10
- local brightness = 7
- --# Choose Fade Time (s)
- local fade = 0
- --# Choose delay (s)
- local delay = 10
- ------------------- ignore ----------------
- fade = fade/10
- local tbl = {} -- Declare tbl as a table to store lamps in
- local rNext, gNext, bNext = 100, 250, 250 -- The next random color
- local rCur, gCur, bCur = 100, 250, 250 -- current color
- --#Makes a decimal number hexdecimal
- function intToHex(num)
- return string.format("%x", num)
- end
- --#Keeps numbers from breaking everything
- function rgbreg(num)
- if num > 255 then return 255
- elseif num < 0 then return 0
- else return num end
- end
- --#Turns seperate rgb values into hexidecimal form
- function rgbToHex(r,g,b)
- rhex = intToHex(r)
- ghex = intToHex(g)
- bhex = intToHex(b)
- hexstring = rhex .. ghex .. bhex
- return tonumber(hexstring, 16)
- end
- --# returns a random rgb color
- function randomColor()
- lum = rgbreg(math.floor(brightness*25.5))
- r = math.random(lum,255)
- g = math.random(lum,255)
- b = math.random(lum,255)
- return rgbreg(r),rgbreg(g),rgbreg(b)
- end
- --#Find and automatically wrap lights.
- for a,v in pairs(peripheral.getNames()) do -- Start loop
- if (peripheral.getType(v) == "thermalexpansion_light" ) then -- If lights are detected then continue
- tbl[#tbl + 1] = peripheral.wrap(v) -- Add lamps to table
- end
- end
- --#Initialize lights
- for i = 1,#tbl do
- tbl[i].setColor(rgbToHex(rCur, gCur, bCur))
- end
- while true do -- Start loop
- rs.setOutput("right",true)
- -- Choose a new random color
- rNext, gNext, bNext = randomColor()
- sleep(delay)
- -- fade the colors 'Cur' into colors 'Next'
- rStep,gStep,bStep = (rNext-rCur)/20,(gNext-gCur)/20,(bNext-bCur)/20
- -- Creates more precise version of current color
- rCurP, gCurP, bCurP = rCur, gCur, bCur
- for i = 1,20 do
- rCurP = rCurP + rStep
- gCurP = gCurP + gStep
- bCurP = bCurP + bStep
- rCur, gCur, bCur = math.floor(rCurP),math.floor(gCurP),math.floor(bCurP)
- curColor = rgbToHex(rCur, gCur, bCur)
- for i = 1,#tbl do
- tbl[i].setColor(curColor)
- end
- sleep(fade)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement