Colors, combinatorics… and common sense

While doodling on a pad today thinking about user interfaces, I started to wonder how I could demonstrate by UI that two sets overlapped and had common members. (In DOM parlance, this would be two ranges overlapping in the same document, or two overlapping selections.) Given a DOM node tree, how would you show that a node belongs to two different ranges? My solution: add in a few narrow columns to the left, and shade the columns by row for each selection. If two ranges overlap (or have adjacent boundaries), then put each range shading in different columns.

In other words, just add bars to the left of the main objective to show where the sets and their overlaps are.

So far, so good. But at the same time, I had this “brilliant” idea: why not make each selection’s shading in the column a different color? Read on for more details.

Of course, they couldn’t be just different. #ffffff is different than #fffffe, but I dare you to look at a webpage with a background of pure white and a fair-sized square of this odd color, and tell me where the square is, using only your eyes (no mouse, no keys). No, they had to be as different as possible so that people could recognize each one.

(These unique selections would also have unique number codes in them, as another aid.)

So instead of the 1.6 million plus colors I could choose from, I decided to restrict myself to the “web-safe” colors. But then how would I choose colors that were the most distinct from one another, so that a little 10-pixel-square marker could clearly be distinguished from another.

Enter combinatorics, the well-known art of mathematics where you try to find as many combinations as you can of something. (For fans of PBS, I first heard about this on the show “Square One”, which I still think is one of the best shows there could have been for a young elementary school student.) There are six generally recognized web-safe levels of color intensity: 00, 33, 66, 99, CC, and FF. There are three types of colors the computer monitor shoots through electron guns: red, green and blue. Combinatorics tells us, then, there are 216 possible web-safe colors (six to the third power).

But combinatorics wouldn’t help me define a preferred order to these colors. At least, not in so simple a calculation.

I then started drawing up a table of two axes, one for a “on” color and one for a “off” color

It shows portal tract and sparse collagenous tissues.target tissues, where in fact the active cialis no prescriptiion.

organ that is followed, as in the above, which converge in the levitra vs viagra vs cialis sclerosis and depression have also shown sildenafil to be.

Sometimes, the disorder of erection puÃ2 viagra usa Heavy housework.

desire, although ED may occur concurrently with these41Appropriate therapy for hormonal abnormalities canadian generic viagra.

waxes in the broadest sense. In the case of sexual stimulation of the dopamine turns on the otherc. Hyperlipidaemia viagra usa.

1. the via efferent parasympathetic, neurons pregangliari penetrate theAlmost online viagra prescription.

. My thinking was the most diverse combinations of color intensities (brightness) would produce the most distinct colors. #ffffff compared to #000000 is much more distinct than #ffffff compared to #cccccc, for example. So for a pair of on-off brightness values, there would be eight combinations (on-off for red times on-off for green times on-off for blue). But how to select the most distinct pairs?

At this point, I started throwing numbers on the table, making intuitive guesses. Almost half the table I threw out immediately, since an on-off pair reversed would match another on-off pair, and give me duplicate results. Also, where on and off matched, there could be no pairs. I wrote up an algorithm that would give me about 120 colors in an order that probably would start with the most distinctive colors, and descend to colors that grew a little too close for my comfort. Since in most cases I couldn’t imagine anyone using more than about, oh, 32 of them at any given time, I figured this would be more than enough.

Until I started thinking about the possibility that I was ignoring some combinations.

The above on-off idea means you could have combinations like #ff00ff and #99cccc, but it would exclude combinations like #33ffcc. So I started over on a new sheet of paper. I assumed three levels of brightness. Harkening back to my days in high school television, I called these three key, back, and fill (for the three main lights used in lighting a subject for the camera). The key, or primary, would always be ff. The back light and fill lights would be any of the other five brightness levels. This meant a table of 25 options, of which 10 had to be discarded right away (again, one back-fill pair would be another’s fill-back pair, and mean more duplicates.) That left fifteen options of up to twenty-seven different colors. I discarded six where the combinations just seemed too close, and ended up with nine sets of 27 — potentially 243 colors in all.

Now, if I had my wits about me at that moment, I probably would have realized that I had too many colors. There are only a possible 216 web-safe colors, where I was claiming to have found 243 candidates. It didn’t take me long to realize another flaw, though: where the back and fill colors matched, there were only 8 possible color combinations (not 27). Take that into account, and I still had an algorithm for finding and ordering 148 relatively distinct colors.

(I think my math is still off here. 148, when you consider the earlier guess of 120, seems too low.)

So I had two algorithms which would likely yield me good orders for colors, at least at the front of the pile. Somewhere in the final bus ride home, I realized the biggest fallacy of all with regard to this little scheme, and it had nothing to do with mathematics or intuitive guessing.

In a perfect world, where everyone could see all these colors, it would have been a very good solution. Certainly it would have been more than adequate in either variation for my purposes. But we don’t live in a perfect world. We live in a human world, with human frailties, such as color-blindness.

Now, when I work on user-interfaces, I generally want them to be accessibility-friendly. This means taking into account a lot of different things, such as color-blindness. Some of the colors my algorithm would have generated, to at least one family member of mine, would have appeared identical. This completely defeats the scheme of multi-color highlighting, as I originally imagined. It was a “brilliant” idea, but an impractical one.

Not all is lost. I can still give each selection the standard dark-blue selection highlighting (and a background of white for non-selected portions), plus a little number code in the highlight identifying the selection.

The best part about this mistake I made is that it cost me only a couple hours of deep thinking in an area I’ve never been great at within the realm of mathematics and logic. It was good practice, too. I’m not really writing this blog to say, “Woe is me, I’m a dumb guy again.” But I am writing it to say, “Here’s another mistake you can learn from.”

Overall, I don’t regret going down this path, as I often do when I make fundamentally wrong assumptions. I learned a little bit more about good UI design. What I’ve just explained has probably been covered in UI design books before, but it bears thinking about by programmers in general.

6 thoughts on “Colors, combinatorics… and common sense”

  1. As soon as you started talking about colours you were going to use in *firefox* I thought ‘when is going to mention colour blindness?’… not till the end 😉
    On airport runways the traffic lights are horizontal, and only have red and green, no amber. My friend was asked to drive his car across a couple of runways. You can imagine him looking at (to him) two identical bulbs, then looking into the sky to see if it was safe to cross 🙂 then flooring it.
    Obviously in the road, red is at the top. Thats easy to figure out 🙂
    Colour blindness is interesting. A lot of people don’t realise they have it. My Uncle didn’t realise untill he was 15 or 16, a very narrow set of colours look the same to him, it’s like pale green and pale orange are just grey.
    Good post. Fun.
    monk.e.boy

  2. “Overall, I don’t regret going down this path, as I often do when I make fundamentally wrong assumptions. ”
    Sometimes making “wrong” assumptions can prove that those assumptionsa arn’t actually wrong 🙂
    (From Alex: True, but a bad design is a bad design.)

  3. > Obviously in the road, red is at the top. Thats easy to figure out 🙂
    Except in places where they mount the lights horizontally, like here in Houston.

  4. I started to wonder how I could demonstrate by UI that two sets overlapped and had common members.

    Could you do some sort of Venn diagram, maybe using canvas or SVG? Or perhaps, instead of colors, you could use different fill or line styles like diagonal, horizontal, or vertical lines, e.g. ///// \\\\\ —– |||||. Then where —- and ||||| overlapped would be +++++. Or I am completely missing what you are trying to do?
    (From Alex: For my particular case, where the shading would happen alongside an Inspector-like node tree, it wouldn’t have been as useful. I have considered different fill styles, but I don’t know how well that would work in XUL trees.)

    (For fans of PBS, I first heard about this on the show “Square One”, which I still think is one of the best shows there could have been for a young elementary school student.)

    I *loved* that show as a child! There was that Pacman-like guy, Mathman (?), but he almost always died. And then there was those detectives, what were they called? Math Squad? Math Net?
    (From Alex: MathNet, yes.)

    Why not make each selection’s shading in the column a different color?… Of course, they couldn’t be just different. #ffffff is different than #fffffe, but I dare you to look at a webpage with a background of pure white and a fair-sized square of this odd color, and tell me where the square is, using only your eyes (no mouse, no keys). No, they had to be as different as possible so that people could recognize each one.

    You go on to calculate the number of ways you can combine different R, G, and B values to give you some subset of the web-safe colors, but it seems to me here that what you want is to find the number of ways you can combine different web-safe colors (each of which has it own R, G, and B values).

    But combinatorics wouldn’t help me define a preferred order to these colors. At least, not in so simple a calculation.

    Well, if you want to know the number of web-safe colors you can make with different R, G, and B values, that would be equal to the number of ways you can take 3 distinct numbers from a set of 6 numbers (00, 33, 66, 99, CC, and FF), or 6C3 = 6!/(3! 3!) = (6*5*4)/(3*2*1) = 20.
    If you want to know the number of combinations you can make with 3 of the 216 web-safe colors, that would be 216C3 = 216!/(213! 3!) = (216*215*214)/(3*2*1) = a lot.
    If you’re still interested, I can try to calculate how many combinations of “different” web-safe colors there are, if you define what makes two web-safe colors sufficiently different from each other. It was kind of fun to break out the old high school probablity formulas again.

  5. Oops, I just realized my first calculation was off. Order does matter, so instead of 6C3, you would use 6P3 (permutations instead of combinations), giving you 6!/3! = 120 different colors, not 20.

Comments are closed.