If you need to code-golf a set of predefined RGB color palettes, how would you do it?
Problem: Each palette has a variable amount of RGB colors. The program output should closely match the input palettes, in string hex code format (with or without #
prefix) so that it can be fed into Canvas2D APIs. Solution must be valid JavaScript code.
Proposed Solution: Turn each palette into a base64 encoded string. During decoding, use atob
to convert the Base64 palette to a set of hex codes.
Other Solutions? Maybe with RGB565 or RGB444? Please comment if you have any other solutions. :)
As you are fine with RGB444 values, I thought about encoding the array of #RGB888 colors down to #RGB444 and into a string of UTF8 characters to use one character per color which would take 1-3 byte per color.
This brings the data + decoder for the list of colors you provided down to 185bytes
Hope this helps,