This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CrazedProgrammer's profile picture

RGB API - Convert RGB colors to ComputerCraft colors and back

Started by CrazedProgrammer, 26 April 2015 - 02:35 PM
CrazedProgrammer #1
Posted 26 April 2015 - 04:35 PM
This small API converts 24-bit RGB colors to ComputerCraft colors and back.
You can even have 2 layers of colors to create more precision.
This API doesn't have its own functions, but it injects functions into the colors and colours APIs,
so it doesn't matter if you load this as an API, or copy and paste it into your program.

Download:
pastebin get BCSWghjR rgb

Example:
colors.fromRGB(255, 0, 0) returns 16384 (colors.red)
colors.toRGB(colors.blue) returns 51, 102 and 204

All functions are documented here:
colors.fromRGB
colors.toRGB
colors.fromRGB2
colors.toRGB2
Edited on 12 June 2015 - 01:12 PM
InDieTasten #2
Posted 26 April 2015 - 06:47 PM
It it works, it's really neat: +1
CrazedProgrammer #3
Posted 26 April 2015 - 06:47 PM
It works, it's really neat: +1
Thanks!
InDieTasten #4
Posted 26 April 2015 - 06:55 PM
You could calculate the ratios of the two cc-colors to form the rgb2-complement, which could either be returned like back and text color, or maybe even translated into characters of appropriate occupy'ness. this would enable smoother gradients.
If you don't understand it in the way I'm writing it, maybe remember the firepit program. it uses this exact technique to enable much better gradients.

Note, that you can occupy about 50%? with the '#', so if you would need more, you could simply switch the text and back color, and achieve the perfect color ratio with lower occupy-values
CrazedProgrammer #5
Posted 26 April 2015 - 07:07 PM
You could calculate the ratios of the two cc-colors to form the rgb2-complement, which could either be returned like back and text color, or maybe even translated into characters of appropriate occupy'ness. this would enable smoother gradients.
If you don't understand it in the way I'm writing it, maybe remember the firepit program. it uses this exact technique to enable much better gradients.

Note, that you can occupy about 50%? with the '#', so if you would need more, you could simply switch the text and back color, and achieve the perfect color ratio with lower occupy-values
The colors are calculated with the # occupying 20 (7 * 2 + 3 * 2) of the 54 (6 * 9) pixels for every character (which is true if you look closely).
I may make an update that uses characters of appropriate occupy'ness.
Edited on 26 April 2015 - 05:08 PM