Sunday 3 September 2017

Cracking the QBasic Color Code

Every time I try to get colorful in QBasic, I find myself having to refer to the following table.

NumberColor
0Black
1Blue
2Green
3Cyan
4Red
5Purple
6Brown
7Light Grey
8Dark Grey
9Light Blue
10Light Green
11Light Cyan
12Light Red
13Light Purple
14Yellow
15White

And after a while, I find myself wishing there was some way this would make sense to me, so I wouldn't have to keep having to look it up. The eureka moment hit me recently, years later after I typed my first "Hello World" in QBasic, when I was staring at the table again, and realized that it had made sense all along - I just hadn't seen it. And I would have seen it much sooner if I had just been a little more binary about it. Let's look at the table again, and this time, convert the first eight numbers numbers to binary.

NumberColor
000Black
001Blue
010Green
011Cyan
100Red
101Purple
110Brown
111Light Grey
8Dark Grey
9Light Blue
10Light Green
11Light Cyan
12Light Red
13Pink
14Yellow
15White

Now, if you understand the principle of RGB, you'll notice that the first eight colors correspond pretty well, if the first bit represents the Red component, the second bit represents the Green component, and the third bit represents the Blue component. So Blue would be 001, Red would be 100, and Purple would be 101, a combination of Blue and Red! And since 110 would be a combination of Red and Green, that would naturally give you Brown. And while in the natural world, Blue and Green will not give you Cyan, it will in RGB. Thus 011 gives you Cyan.

What about the other eight colors? 

This is where it gets interesting. Notice that I've put the eight colors in a second column.

NumberColorNumberColor
000Black8Dark Grey
001Blue9Light Blue
010Green10Light Green
011Cyan11Light Cyan
100Red12Light Red
101Purple13Pink
110Brown14Yellow
111Light Grey15White

You'll see that the colors on the right are all paler versions of the color on the left! Dark Grey is a lighter version of Black. Yellow is a lighter version of Brown. And White is definitely the lighter version of Light Grey.

Well, hot damn. 

I could have kicked myself for not seeing this pattern earlier. I guess everyone's got their blind spots, eh?

Hue says this is hard?
T___T

No comments:

Post a Comment