Jump to content




RGB API - Convert RGB colors to ComputerCraft colors and back

api

4 replies to this topic

#1 CrazedProgrammer

  • Members
  • 495 posts
  • LocationWageningen, The Netherlands

Posted 26 April 2015 - 03: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 by CrazedProgrammer, 12 June 2015 - 02:12 PM.


#2 InDieTasten

  • Members
  • 357 posts
  • LocationGermany

Posted 26 April 2015 - 05:47 PM

It it works, it's really neat: +1

#3 CrazedProgrammer

  • Members
  • 495 posts
  • LocationWageningen, The Netherlands

Posted 26 April 2015 - 05:47 PM

View PostInDieTasten, on 26 April 2015 - 05:47 PM, said:

It works, it's really neat: +1
Thanks!

#4 InDieTasten

  • Members
  • 357 posts
  • LocationGermany

Posted 26 April 2015 - 05: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

#5 CrazedProgrammer

  • Members
  • 495 posts
  • LocationWageningen, The Netherlands

Posted 26 April 2015 - 06:07 PM

View PostInDieTasten, on 26 April 2015 - 05:55 PM, said:

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 by CrazedProgrammer, 26 April 2015 - 06:08 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users