December 21, 1993 Dear Fellow RoboBOARD/FX SysOps, Here is a trivial exercise which, after getting my arm really tired, may save you some time. I'm writing some programs that generate .TFX files and I had to know how FXdraw handles colors. Seth wouldn't tell me, so I went into FXdraw and started playing around. I got carried away, but I liked the result, so I'm sharing it. FXdraw has three kinds of colors. There are the standard sixteen, which match 16-color VGAs. Second, there are the 32 scales of gray. Finally, there are all the other colors, which we'll discuss. You can look at FX colors as a cube: Red 0 63 -------------- 0 Blue Green 0|\ \ | \ \ | \ \ | \ \ | \ \ | -------------- 63 | | | 63| | | \ | | \ | | \ | | \ | | \| | -------------- (63,63,63) Now, you'd think this means there are 64 * 64 * 64, or 262,144 colors. But it doesn't! When a color is displayed on a 256-color VGA, you can have a palette of any 256 colors you want out of 262K or even 16.7 million, depending on the VGA board. But you need software that manages the palette, assigning one of the 262K colors to each of the 256 palette entries. Think of the cube as 64 * 64 * 64 clear plastic boxes, all stacked up. Now you can pick up to 256 of them and fill them with paint, numbering the filled ones in any order from 0 to 255. To fill any box, you start with white paint. (Yes, I know you start with black on a screen, but this is paint!) Now you measure the column number of the box, and add from 0 to 63 drops of red pigment, then measure the layer number and add drops of green pigment, and last, add blue pigment for the row number. Shaken, not stirred! FXterm does this, and selects a set of colors you can use, assigning each color to a palette entry. FXdraw shows you the same set of colors and lets you pick. Now, FXdraw knows the secret mapping! If you look at the .TFX file, you'll see the cube coordinates of each color, not its palette entry number. The compiler, FXcomp, translates the cube coordinates to the magically hidden format used for the .BLB files. Using a still-undisclosed mechanism, RoboBOARD reads the .BLB files, and transmits a color selection of unknown format for each color. If you edit a .TFX file or generate one with a program, you might be tempted to just pick any old color numbers out of the 262K that are possible. But there are only a few that FXdraw and FXcomp really like--the cubes that are filled with paint. If you load your .TFX file into FXdraw and save it, you'll see that your color numbers have been modified into the closest color numbers that FXterm can display. Seth says FXcomp does a better job of the approximation than FXdraw does. Here are the sixteen standard colors: Cube Coordinates Color Name Red Green Blue ------------ --- ----- ---- Black 1 1 1 Dark Blue 0 0 42 Dark Green 0 42 0 Dark Cyan 0 42 42 Dark Red 42 0 0 Dark Magenta 42 0 42 Dark Yellow 42 21 0 Light Gray 44 44 44 Dark Gray 24 24 24 Light Blue 21 21 63 Light Green 21 63 21 Light Cyan 21 63 63 Light Red 63 21 21 Light Magenta 63 21 63 Light Yellow 63 63 21 White 61 61 61 The thirty-two scales of gray are simple: Cube Coordinates Color Name Red Green Blue ------------ --- ----- ---- Black 0 0 0 Gray #1 2 2 2 Gray #2 4 4 4 : : : : : : : : : : Gray #30 60 60 60 White 62 62 62 As you can see, you get a blacker black and a whiter white, but there's still no way to get color (63,63,63). Or is there? There are 180 additional colors in FXdraw. They are actually mixtures of six shades of red, five shades of green, and six shades of blue. And 6 X 5 X 6 = 180. Here are the only values that are used: Red 0 13 25 38 50 63 Green 0 16 32 47 63 Blue 0 13 25 38 50 63 In fact if you use integer arithmetic, you can see the formula: given RedIndex = 0 to 5 GreenIndex = 0 to 4 BlueIndex = 0 to 5 Red = (RedIndex * 63) / 5 Green = (GreenIndex * 63) / 4 Blue = (BlueIndex * 63) / 5 We've explained 16 + 32 + 180 = 228 colors. And actually, (0,0,0), (24,24,24), and (44,44,44) are each in there twice. We've got three whites, (61,61,61), (62,62,62), and (63,63,63). Are there 28 or even 31 more secret colors? There might be no way to find out. The .TFX file I've zipped up with this text file has two uses. One is to illustrate the explanation above. Take a look at it with any ASCII editor. The INT commands set the interior color of a whole bunch of 10 X 10 rectangles. You can also load the .TFX file into FXdraw and use it as a color chart when you're making up screens. The first color box was created by putting the colors down in the order they are in FXdraw as six horizontal stripes of thirty colors. As you can see, the upper- right corner is cyan and the lower-left corner is red. Red increases from top to bottom, and green and blue increase from left to right; the blue in five repetitions of six increments, the green in five 6 x 6 squares of red and blue values. The second color box was created by putting the colors down in the order they are in FXdraw as 36 vertical stripes of five colors. The upper-right corner is magenta and the lower-left corner is green. Green increases from top to bottom, and red and blue increase from left to right; the blue in six repetitions of six increments, the red in six 6 x 5 rectangles of green and blue values. The third color box was harder to concoct. I won't go into details. The upper-right corner is yellow and the lower-left corner is blue. Blue increases from top to bottom, and red and green increase from left to right; the green in six repetitions of five increments, the red in six 5 x 6 rectangles of green and blue values. Finally, I put in boxes of the 32 scales of gray and the sixteen standard colors, so you can see them in the .TFX file. If you get a color wrong when you draw up a screen with FXdraw, you might have dozens of drawing entities the wrong color. It's a lot easier to edit the .TFX file than it is to select each entity in FXdraw and change the color. First, load COLORS.TFX into FXdraw and pick the color you want. Write down its red, green, and blue indices and use either the table or the formula above to convert them to the color cube coordinates. Edit the .TFX file and use the editor's search-and-replace function to change all of the drawing entities you're after all at once. The BOR commands set the border colors and the INT commands set the interior colors. I hope this helps somebody out there. If we all share what we can learn, we'll all get a lot better results out of RoboBOARD/FX. Feel free to share with me in return! My board is Home in San Diego. Give us a call with FXterm at (619)675-9772 and check us out. Be sure to leave me a Comment telling me you're a SysOp and what you thought of Home, and I'll take a look at your board, too. I'll have board lists on Home, soon, as well. Dave Brumley The Home System BBS (619)675-9772 Voice (619)675-3055 Personal (619)451-8384