PDA

View Full Version : Coding HTML Color Codes



AvatarVecna
2022-12-18, 03:13 PM
Some friends and I have been tooling around with color codes on the forum and we're trying to figure out the logic behind some things. Some things just translate directly into HTML color codes by default (infamously, "c0ffee" makes coffee), while some words are the default name for a color ("gold" makes gold). But we've been putting random words in and seeing what colors come out, and we're trying to figure out the logic behind it, since none of them are really color names. Some letters don't really translate into HTML the way coffee does, and they're definitely not normal color names, and yet they're still returning colors?

As a few examples (with each word being its own color code):

AvatarVecna
Zookeeper
McDonalds
Puppets
Santa
Halloween
Keyboard
Administrator

If anyone can shed light on what's happening here, I'd love to hear it. :smallsmile:

Jasdoif
2022-12-18, 04:22 PM
The standard is, shall we say, exciting (https://html.spec.whatwg.org/#colours)....To sum up the type of stuff you're talking about: The browser converts non-hex-digits in the color code to 0, pads the end with 0s make the length a multiple of three if it isn't already, splits them into R/G/B pieces, trims equally shared leading zeroes to a minimum of two characters each, truncates to the leading two characters if necessary, and uses that as the RGB value.


AvatarVecna
a0a0a00ec0a (convert)
a0a0a00ec0a0 (pad)
a0a0, a00e, c0a0 (split)
a0, a0, c0 (truncate to two)
a0a0c0

ZooKeeper
0000ee0e0 (convert)
000, 0ee, 0e0 (split)
00, ee, e0 (trim leading zeros)
00eee0

McDonalds
0cd00a0d0 (convert)
0cd, 00a, 0d0 (split)
cd, 0a, d0 (trim leading zeros)
cd0ad0

Puppets
0000e00 (convert)
0000e0000 (pad)
000, 0e0, 000 (split)
00, e0, 00 (trim leading zeros)
00e000

Santa
0a00a (convert)
0a00a0 (pad)
0a, 00, a0 (split)
0a00a0

Halloween
0a0000ee0 (convert)
0a0, 000, ee0 (split)
0a, 00, ee (truncate to two)
0a00ee

Keyboard
0e0b0a00 (convert)
0e0b0a000 (pad)
0e0, b0a, 000 (split)
0e, b0, 00 (truncate to two)
0eb000

Administrator
ad0000000a000 (convert)
ad0000000a00000 (pad)
ad000, 0000a, 00000 (split)
ad, 00, 00 (truncate to two)
ad0000

AvatarVecna
2022-12-18, 04:51 PM
The standard is, shall we say, exciting (https://html.spec.whatwg.org/#colours)....To sum up the type of stuff you're talking about: The browser converts non-hex-digits in the color code to 0, pads the end with 0s make the length a multiple of three if it isn't already, splits them into R/G/B pieces, trims equally shared leading zeroes to a minimum of two characters each, truncates to the leading two characters if necessary, and uses that as the RGB value.


AvatarVecna
a0a0a00ec0a (convert)
a0a0a00ec0a0 (pad)
a0a0, a00e, c0a0 (split)
a0, a0, c0 (truncate to two)
a0a0c0

ZooKeeper
0000ee0er (convert)
000, 0ee, 0e0 (split)
00, ee, e0 (trim leading zeros)
00eee0

McDonalds
0cd00a0d0 (convert)
0cd, 00a, 0d0 (split)
cd, 0a, d0 (trim leading zeros)
cd0ad0

Puppets
0000e00 (convert)
0000e0000 (pad)
000, 0e0, 000 (split)
00, e0, 00 (trim leading zeros)
00e000

Santa
0a00a (convert)
0a00a0 (pad)
0a, 00, a0 (split)
0a00a0

Halloween
0a0000ee0 (convert)
0a0, 000, ee0 (split)
0a, 00, ee (truncate to two)
0a00ee

Keyboard
0e0b0a00 (convert)
0e0b0a000 (pad)
0e0, b0a, 000 (split)
0e, b0, 00 (truncate to two)
0eb000

Administrator
ad0000000a000 (convert)
ad0000000a00000 (pad)
ad000, 0000a, 00000 (split)
ad, 00, 00 (truncate to two)
ad0000

Okay that's pretty neat! :smallsmile:

KillianHawkeye
2022-12-18, 10:02 PM
Huh, that's interesting. TIL