I wanted to share a cheap trick I use when I am specifying colors. It’s not rocket science, but it’s not immediately obvious either, and with any luck, it’ll save you some hassle, a few seconds at a time.
Colors specified in hexadecimal (aka, the pre-RGBA web way) are easy to remember. For example, I first used
#ed145b way back in the day for enemy bullets in Vetica and it’s been my go-to ever since.
#ed145b is burned in my brain, but
237, 20, 91 (the 8-bit RGB version), not so much. Converting hex to decimal is pretty trivial, but at least for me, doing the arithmetic can break my flow.
Here’s the thing: unless you do a lot of bit twiddling, you may have forgotten that most programming languages really don’t mind if you talk to them in hex. So, as far as (for example) Processing is concerned this:
color(237, 20, 91)
is just as good as
color(0xed, 0x14, 0x5b)
That is, the three pairs of digits in
#ed145b separated and prefixed with
0x, meaning that what follows is in hexadecimal.
If you need floats from
1.0 instead of 8-bit integers, just divide by
255.f. For example, to specify a
UIColor in Objective-C, just write:
[UIColor colorWithRed:0xed/255.f green:0x14/255.f blue:0x5b/255.f alpha:1.f];
You can use similar transformations if you have some other strange format. And if you still need a go-to color, I can recommend the criminally underused