Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mount = function (peripheral_type)
- for _,location in pairs(peripheral.getNames()) do
- if peripheral.getType(location) == peripheral_type then
- return peripheral.wrap(location)
- end
- end
- return false
- end
- lamp = mount("modem")
- hue = 0.00
- function toHex(dec)
- return(string.format("%x",dec))
- end
- function toDec(hex)
- return(tonumber(hex))
- end
- function hsvToRgb(h, s, v)
- local r, g, b
- local i = math.floor(h * 6);
- local f = h * 6 - i;
- local p = v * (1 - s);
- local q = v * (1 - f * s);
- local t = v * (1 - (1 - f) * s);
- i = i % 6
- if i == 0 then r, g, b = v, t, p
- elseif i == 1 then r, g, b = q, v, p
- elseif i == 2 then r, g, b = p, v, t
- elseif i == 3 then r, g, b = p, q, v
- elseif i == 4 then r, g, b = t, p, v
- elseif i == 5 then r, g, b = v, p, q
- end
- rHex = toHex(math.floor(r*255))
- gHex = toHex(math.floor(g*255))
- bHex = toHex(math.floor(b*255))
- if string.len(rHex) <= 1 then
- rHex = rHex..0
- end
- if string.len(gHex) <= 1 then
- gHex = gHex..0
- end
- if string.len(bHex) <= 1 then
- bHex = bHex..0
- end
- return("0x"..rHex..gHex..bHex)
- end
- function centerText(text)
- local x,y = term.getSize()
- term.setCursorPos(math.floor((x / 2) - (text:len() / 2)), y)
- write(text)
- end
- while not stop do
- for _,v in pairs(lamp.getNamesRemote()) do
- local hex = hsvToRgb(hue,1,1)
- local decimal = toDec(hex)
- lamp.callRemote(v,"setColor",decimal)
- end
- hue = hue+.01 -- Changing this to a smaller number will make the steps between colors smaller
- sleep(.005) -- Changing this line to a bigger number will make the lamp stay one color longer
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement