The Code Side Of Color
coding.smashingmagazine.com
coding.smashingmagazine.com
When computers name a color, they use a so-called hexidecimal code that most humans gloss over: 24-bit colors. That is, 16,777,216 unique combinations of exactly seven characters made from ten numerals and six letters — preceded by a hash mark.
I mean, "hexidecimal" is hopefully just a typo, but the "explanation" in the second sentence is off by one, it's not seven characters that make up the color, since the hash mark is constant and doesn't contribute. I would object to the "ten numerals and six letters" too, but I guess that's a suitable popular nomenclature.
And I don't even have a lawn ...
1 = 1
2 = 11
3 = 111
4 = 1111 ...etc.
If octal uses the digits 0-7, and binary uses the digits 0-1, then shouldn't base one use only the digit 0?
1 = 11
2 = 111
3 = 1111, etc. {1,2,3...} and {0,1,2...} are isomorphic.
0 = 00 = 000 = 0000 = the number of apples I have if I don't have any.
Why do we do this? Because every integer has exactly one unique representation in this system. We could have picked any values we wanted for the places (rather than N^i) but unless we pick carefully, either some numbers aren't representable, or some numbers have multiple representations.
Base one has a problem right from the start, which is that 1^i = 1 for any value of i - when all places have the same place value, numbers aren't going to have a unique representation. The other problem is that the only number you can write in base one is zero, because the only possible weight (the only integer between 0 and N-1) is 0.
When you write 1111 = 4 you are sneakily using the length of the number on the page to encode the value. The length of the number on the page isn't supposed to matter. In base 10, 17 = 017 = 0017 = 00017.
I couldn't find a rigorous definition of a base system offhand. If you require that number N prepended with additive identity I, so IN = N, I agree with you. But every number in the system I described certainly has a unique representation. Also, this is incorrect: "The other problem is that the only number you can write in base one is zero, because the only possible weight (the only integer between 0 and N-1) is 0." Try taking a look at: http://en.wikipedia.org/wiki/Peano_arithmetic
It is "unary", which is completely different encoding than the "positional notations" such as decimal, octal, binary, etc. The positional notation doesn't work with base 1, as in that notation there would be only 0, and 0, 00, 000, etc., which all mean the same number: zero.
"Tens place"? "24-bit color" ignores alpha and color palettes "# means 'This is a hex number'": No, it means a web color expressed as 3 hex numbers.
Plus, I know it looks better to make your colors less saturated, but when you are demonstrating starting from #ff0000 and adding other colors, why not actually display #ff0000 instead of #e93f32?
Finally, spellcheck.
While the original article is somewhat misleading over why hexadecimal works the way it does, it's closer than you. The OP is trying to explain base-16 at the same time he's trying to describe basic RGB handling. Not everyone learns math in other bases at school (I didn't, I had to teach myself) so he had to cover it, and make use of familiar terms like "tens place".
On top of that, the explanation was presented in a highly visual way. There are a lot of visual learners who just don't get it when I try to explain just verbally, or just with the code.
The OP is right: the pound, or hash, sign is how the browser knows that the identifier is a hexadecimal sequence—just like compilers using 0xff00... to indicate hexadecimal numbers. #ff0000 is one hexadecimal number just like #ff000000 is. They aren't separate numbers, they just have different numbers of bits.
So what's going on here? Well, it's all about the bits, because 2 hexadecimal digits can express 0-255 or 1 byte. So this is actually a data structure of 3 bytes left-shifted into a single 32-bit integer.
#ff8060 (16744544) is the same as
// R G B
color = 255 << 16 | 128 << 8 | 96
Colors with an alpha channel shift all that over another 8 bits and then add an alpha channel. So RGBA(0,0,0,0.5) is equivalent to: // R G B A
color = 0 << 24 | 0 << 16 | 0 << 8 | round(0.5 * 255)
In fact, this latter bit order is probably how the browser stores all the colors now that browsers allow for alpha channels in colors. Yeah, you can store this in a struct if you want (I remember Delphi let me encode a struct to/from a raw unsigned integer automatically by compiler optimization), but in the end this is how the raw color is encoded and sent to the the underlying renderer. Ask anyone that has dealt with OpenGL, DirectX, or anything close to the hardware.So why are hexadecimals widely used in CSS? Because they represent the actual data structure in memory after all the fancy conversions, like HSL, are done.
Perhaps I misunderstood you, but I felt like writing up an explanation of this anyhow. Might be useful to someone that didn't understand the why.
But I found the article to be quite good and useful, and it's obvious that the guy had all the good intentions.
It's also an easy shorthand, because many developers/designers know the game, so you can just say "you know, Portal colors"
See:
This will definitely help -- thanks!
Thanks. Sorry you didn't find the article interesting.
Thanks. Sorry you didn't find the article interesting.
I never thought I'd be down voted for havi g the opinion that something was great.
You are a SHINING example of why HN comments are such awful places these days.
Agreed, but while HSL is surely more intuitive than RGB, it is still a relatively crude tool because the numbers typically aren’t calibrated in any useful way.
After studying colour theory for a long time, I became convinced that the most interesting colour systems are often those based on actual human perception rather than “arbitrary” physics or mathematics. See for example Munsell’s work[1], which is built around perceptually uniform changes as the values representing colours vary, or the Opponent Process theory[2], where hues are represented in terms of red-green and blue-yellow axes rather than placing three primary colours at the vertices of an equilateral triangle and then interpolating into a circle.
Personally, I have found the perceptual systems more useful than RGB or a traditional colour wheel and something like HSL built on it, particularly for technical/mechanical tasks that require generating variations of colours starting from one or more known anchor points like colours lifted from a photograph or a client’s branding guidelines. I think you always need a human touch, though: all useful colour models have multiple dimensions, and there is definitely both skill and art in making choices like whether to vary each dimension by large amounts, subtle but visible differences, or not at all.
Sadly, I fear we’re still many years from calibrated/environmentally-aware display devices being the norm. That means for something like web design, the majority of visitors to most sites are going to see all those lovingly chosen colours on a poorly calibrated screen that may scarcely resemble the original designer’s choices anyway, so to some extent trying hard to refine a colour scheme at the above level is mostly wasted effort, at least for now. Such is life. :-)