I've edited a program that can change the color of a colorful lamp. I now want it to change the color of multiple lamps. As of now I've created a table to hold the info of the component table (which is just a placeholder intended for debugging) and a table to hold just the address of the different lamps. I however don't know how to specify which lamp the setLampColor method should apply to, the "component.invoke()" sounds promising but I got no results other than this error msg:
I've created a program similar this on computercraft but it was too much of a pain to translate it all; most of the code changing the accuall colors isn't mine.
Thank you in advance for helping me solve this issue!
local c = require('component')local bit32 = require("bit32")local term = require("term")local address ={}local lamps ={}for address in c.list("colorful_lamp")dolocal lamp = component.proxy(address)
table.insert(lamps, lamp)endfor index, data in ipairs(lamps)do
print(index)for key, value in pairs(data)do
print(' '.. key, value)if key =="address"then
table.insert(address, value)endendendlocal radians = math.pi /180local epsilon =1e-9local almost_one =1- epsilon
localfunction clamp(v)return math.min(math.max(v,0), almost_one)endlocalfunction cubehelix_2(gamma, steps, a, b)local ah =(a.h +120)* radians
local bh =(b.h +120)* radians - ah
local as = a.s
local bs = b.s - as
local al = a.l
local bl = b.l - al
local step =0local last_step = steps -1returnfunction()if step >= steps thenreturnnilendlocal t = step / last_step
local h = ah + bh * t
local l = math.pow(al + bl * t, gamma)local a =(as + bs * t)* l *(1- l)local cos_h, sin_h = math.cos(h), math.sin(h)
step = step +1return{
r = clamp(l + a *(-0.14861* cos_h +1.78277* sin_h)),
g = clamp(l + a *(-0.29227* cos_h -0.90649* sin_h)),
b = clamp(l + a *(1.97294* cos_h)),}endendlocalfunction cubehelix(gamma,...)local t ={...}local i, i_max =0,#t -1local it
localfunction next_it()
i = i +1if i > i_max then
it =nilelselocal a, b = t[i], t[i +1]
it = cubehelix_2(gamma, a.steps, a, b)endend
next_it()returnfunction()ifnot it thenreturnnilendwhile it dolocal ret = it()if ret thenreturn ret
else
next_it()endendendendwhiletruedolocal it = cubehelix(1,{h =-100, s =0.75, l =0.35, steps =20},{h =80, s =1.50, l =0.80, steps =20},{h =260, s =0.75, l =0.35})for rgb in it dolocal color = math.floor(rgb.r *32)
color = bit32.replace(color, math.floor(rgb.g *32),5,5)
color = bit32.replace(color, math.floor(rgb.b *32),10,5)for i=1,#address do
print(address[1])--It prints the adress as expected
print(color)
term.read()--for reference this works for lamp nr 1: --c.colorful_lamp.setLampColor(color)
c.invoke(address[i], setLampColor, color)
os.sleep(0)endendend
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
I've edited a program that can change the color of a colorful lamp. I now want it to change the color of multiple lamps. As of now I've created a table to hold the info of the component table (which is just a placeholder intended for debugging) and a table to hold just the address of the different lamps. I however don't know how to specify which lamp the setLampColor method should apply to, the "component.invoke()" sounds promising but I got no results other than this error msg:
I've created a program similar this on computercraft but it was too much of a pain to translate it all; most of the code changing the accuall colors isn't mine.
Thank you in advance for helping me solve this issue!
Link to post
Share on other sites