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. :)
Just messing around with other possible approaches, using base 32 numbers. Doesn't get as small as the base64 string, but still smaller than joining the hex numbers (depending on size of the palettes array).