Live data from Hacker News

The Code Side Of Color

coding.smashingmagazine.com

11–20 of 40 posts

Re: The Code Side Of Color

#11

Excellent read. I've been interested in developing some sort of tool to help me select, save, and organize colors for custom palettes. This will definitely help -- thanks!

Completely disagree - it was an awful read, but please try http://www.colourlovers.com/ for the selecting, saving and organising of colours.

Re: The Code Side Of Color

#12
post #4
post #2

Bleh, it seems they forgot to proof this or have it read by someone who ... I don't know, maybe knows a bit more about how it really works. 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…

I also have a real problem with them referring to the second digit from the right as the "tens place", considering it's actually base sixteen...

Only if you take 'ten' to be a number in base 10. /s

Re: The Code Side Of Color

#13
post #2

Bleh, it seems they forgot to proof this or have it read by someone who ... I don't know, maybe knows a bit more about how it really works. 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…

There needs to be a w3fools equivalent for Smashing Magazine.

Re: The Code Side Of Color

#14
As someone who is colorblind, a lot of my design is based on the logic behind colors rather than looks. Of course, I always let an actual designer approve, tinker with, or redo my work. There are a lot of inaccuracies in this piece but I like the gist of it.

Re: The Code Side Of Color

#15
post #4

Earlier quoted context omitted.

I also have a real problem with them referring to the second digit from the right as the "tens place", considering it's actually base sixteen...

Only if you take 'ten' to be a number in base 10. /s

Every base is base 10. ;).

Re: The Code Side Of Color

#16
I found this article useful despite its errors. However, this article only reinforces my belief that it is easier to work with the HSL color notation. Young(Yello-60degree) Guys (Green-120) Can (Cyan-180) Be (Blue-240) Messy (Magenta-210) Rascals (Red-0/360) gives the visualization for hue. Saturation is between 0-100, where 0 is grayed out and 100 is full-hue. Lightness varies from 0-100, where 0 is blacked out, 100 is whited-out and 50 would give the color as-is.

Re: The Code Side Of Color

#17

As someone who is colorblind, a lot of my design is based on the logic behind colors rather than looks. Of course, I always let an actual designer approve, tinker with, or redo my work. There are a lot of inaccuracies in this piece but I like the gist of it.

I'm color-sighted but my son is color blind. I find that the easiest way to remember what colors differentiate well is to remember the orange/blue colors that Valve chose for Portal specifically because they have the greatest visual distinction for the greatest number of people.

It's also an easy shorthand, because many developers/designers know the game, so you can just say "you know, Portal colors"

Re: The Code Side Of Color

#18
Trying to work with color in RGB triplets is like trying to assemble furniture with a plastic fork. Any discussion of color for programmers needs to be in terms of HSL, with a discussion of Lab for completeness and RGB for dealing with legacy systems.

Re: The Code Side Of Color

#19
post #9

I'm all for designers learning a bit of the technical background behind colors on the web, but this article is full of technical inaccuracies, misconceptions, and misleading comparisons. "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 de…

I have to disagree with how critical you're being. Yes, proof-reading is highly important, but he's writing an article for rather untechnical people (that is the audience: people that don't understand hexadecimal representation of colors). There's no guarantee that these folks know base-16, that RGB means bytes representing each color in said order, or even how that maps to a monitor.

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 
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 
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.

Re: The Code Side Of Color

#20

Trying to work with color in RGB triplets is like trying to assemble furniture with a plastic fork. Any discussion of color for programmers needs to be in terms of HSL, with a discussion of Lab for completeness and RGB for dealing with legacy systems.

Maybe I'm getting old, though I'm not even 30 yet, but I've never grasped HSL like I have RGB and RGBA. I come from a background of toying with OpenGL and game programming, so it became habitual as that was the required structure ~10 years ago.
Post reply on HN