Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides = {"left", "right", "top", "bottom", "front", "back"}
- local colors = { "green", "brown", "black", "pink", "yellow", "orange", "magenta", "purple", "cyan", "red", "white", "lightBlue", "gray", "lime", "blue" }
- local lights = {}
- local function sin2(num)
- return math.sin(math.rad(num))
- end
- local function updateCable(side)
- for k, v in ipairs(colors) do
- if peripheral.getType(side..":"..v) == "Light" then
- lights[side..":"..v] = true
- else
- lights[side..":"..v] = nil
- end
- end
- end
- for k, v in ipairs(sides) do
- local n = peripheral.getType(v)
- if n == "Light" then
- lights[v] = true
- elseif n == "cable" then
- lights[v] = nil
- updateCable(v)
- else
- lights[v] = nil
- end
- end
- local function setColorRGB(r, g, b)
- for k, v in pairs(lights) do
- if v then
- peripheral.call(k, "setColorRGB", r, g, b)
- end
- end
- end
- while true do
- for a = 1, 180 do
- local r, g, b = sin2(a) * 255, sin2(a+120) * 255, sin2(a-120) * 255
- r = math.sqrt(r * r)
- g = math.sqrt(g * g)
- b = math.sqrt(b * b)
- --print("r:",r," g:", g, " b:", b)
- pcall(
- function() setColorRGB(r, g, b) end
- )
- local cont = os.startTimer(0.2)
- while true do
- e, p1, p2 = os.pullEvent()
- if e == "timer" and p1 == cont then
- break
- elseif e == "peripheral_attach" then
- local n = peripheral.getType()
- if n == "Light" then
- lights[p1] = true
- elseif n == "cable" then
- lights[p1] = nil
- updateCable(p1)
- else
- lights[p1] = nil
- end
- elseif e == "peripheral_deattach" then
- lights[p1] = nil
- updateCable(p1)
- end
- end
- --term.clear()
- --term.setCursorPos(1, 1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement