Posted 03 March 2017 - 01:26 AM
So, recently I have been playing around with Colorful lamps from the Computronics mod. The way you set the colors is by wrapping the peripheral and then calling setLampColor(int) on it. The problem here is that integer that you supply the method with.
As listed on the mod's wiki page, the colors range from 0 to 32767 (the same as the colors API minus 1). The 5 least significant bits are red, the next five are green, and the last 5 are blue. The first problem I see with this is that computercraft colors are 16 bit, not 15.
My intentions here are to convert hex colors (#FF00FF for example) or RGB (255,255,255 for white) to this number, but I can't seem to figure out how. I'd rather not just use the 16 colors of the colors API as it limits the colors I can produce. I'm sure there is some way to do this conversion through some calculations. If someone could possibly produce a function that does this, that'd be fantastic!
Regards,
Emanuel
As listed on the mod's wiki page, the colors range from 0 to 32767 (the same as the colors API minus 1). The 5 least significant bits are red, the next five are green, and the last 5 are blue. The first problem I see with this is that computercraft colors are 16 bit, not 15.
My intentions here are to convert hex colors (#FF00FF for example) or RGB (255,255,255 for white) to this number, but I can't seem to figure out how. I'd rather not just use the 16 colors of the colors API as it limits the colors I can produce. I'm sure there is some way to do this conversion through some calculations. If someone could possibly produce a function that does this, that'd be fantastic!
Regards,
Emanuel