Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("back")
- local lamps = modem.getNamesRemote()
- --Modifiers
- local time = 0
- local timeScale = 1
- local frequency = 0.1
- local phaseMod = 0.3
- local delay = 0.08
- --Organizes the list of lamps by the order you activated the modems
- local function setupList()
- lamps = modem.getNamesRemote()
- local buf = ""
- local cut = 0
- while cut+1 < #lamps-1 do
- for j=1+cut,#lamps do
- if(tonumber(string.sub(tostring(lamps[j]),24)) < tonumber(string.sub(tostring(lamps[cut+1]),24))) then
- buf = tostring(lamps[cut+1])
- lamps[cut+1] = tostring(lamps[j])
- lamps[j] = buf
- end
- end
- cut = cut+1
- end
- end
- setupList()
- local function rgbToHex(rgb)
- local hexadecimal = '0x'
- for key, value in pairs(rgb) do
- local hex = ''
- while(value > 0)do
- local index = math.fmod(value, 16) + 1
- value = math.floor(value / 16)
- hex = string.sub('0123456789ABCDEF', index, index) .. hex
- end
- if(string.len(hex) == 0)then
- hex = '00'
- elseif(string.len(hex) == 1)then
- hex = '0' .. hex
- end
- hexadecimal = hexadecimal .. hex
- end
- return hexadecimal
- end
- local function RGBSine(redPhase,bluePhase,greenPhase)
- local red = math.sin(frequency*time + (redPhase*phaseMod) + 0) * 127 + 128
- local green = math.sin(frequency*time + (bluePhase*phaseMod) + 2) * 127 + 128
- local blue = math.sin(frequency*time + (greenPhase*phaseMod) + 4) * 127 + 128
- local colores = rgbToHex({red,green,blue})
- return tonumber(colores)
- end
- --run loop
- local function start()
- for i=1,#lamps do
- modem.callRemote(lamps[i], "setColor", RGBSine(i,i,i))
- end
- time = time+(1*timeScale)
- end
- while true do
- sleep(delay)
- if pcall(start) == false then
- setupList()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement