Made In The Shade: An Introduction To "Three-Dimensional" Graphics on the Atari Computers

David D. Thornburg

If you know anything at all about the Atari 400 and 800, you probably know that these machines give you access to 128 colors. What you may not realize is that these colors are specified with two independent parameters which allow you to create "three-dimensional" objects on the display.

The two parameters of interest are hue and luminosity. Atari gives you access to sixteen colors (the hues), each of which can be darkened or lightened by setting the luminance to one of eight levels. Traditionally, computers that offer limited colors (sixteen total, for example) preselect different hues and luminosities for each color so that inter-color contrast is always apparent, even when the picture is shown on a black and white display. If two colors have the same luminosity, you will not see any difference between the colors when they are shown on a black and white display - a phenomenon you should demonstrate to yourself sometime.

The beauty of the Atari scheme is that the wide range of available colors leads to the ability to create some pretty pictures, even though only four colors can be displayed at one time. The program presented here illustrates a common graphics task - the representation of a solid three-dimensional object through shading.

Since we can display three colors plus the background in a moderate resolution graphics mode, this lets us represent a shaded cube. After all, you can only see a maximum of three faces of a cube at any given time. The function of the program, then, is to create a two-dimensional representation of a cube in which the "realism" results from the control of the shading on each visible face.

In case you are not familiar with Atari graphics, a short digression is in order. Displayed colors are established by the SETCOLOR command which takes the form SETCOLOR A, B, C in which A is the color register (0-4), B is the hue (0-15) and C is the luminosity (an even number from 0 to 14). (I don't know why luminosity isn't set with numbers between 0 and 7, but the use of even numbers doesn't present too much of a problem, as you will see.) The hues (see Table I) are the various basic colors you can use to draw your pictures, and the luminosities control the brightness from 0 (very dark) to 14 (almost white). Once you have set the color registers, you need to indicate which register should be used for the various plotting commands. This function is performed with the COLOR statement. This statement has the form COLOR D in which D refers to the color register where the desired color is located. Now, for reasons that I don't understand, the value of D is generally larger than the color register number by one. In other words, D = A + 1.

Listing: Shading Demo

Download (Saved BASIC)
Download / View (Listed BASIC)

Now that these tips on Atari color have been described, it is time to try out the program.

The listing starts out by setting a moderately high resolution full-frame graphics mode in statement 20. This mode allows the display of four colors and contains 160 x 96 picture elements plenty for our needs. The OPEN statement lets us use a GET statement to receive data from the keyboard without having to press RETURN. Note that the Atari version of GET is very different from the version you may be accustomed to from Microsoft BASIC. Next, the color registers are all set at the same color value so that when the cube is first drawn you cannot see it. The front face of the cube is drawn in COLOR 1 (from SETCOLOR register 0) in lines 70-90, and the other two faces are drawn in COLOR 2 and COLOR 3 in lines 110-130 and 150-170 respectively. At this point, the computer waits in line 190 until a key is typed. (Note that in Microsoft BASIC the program would not stay at a GET command, but would look once and be on its way.) Since I expect to be GET-ting a keystroke from keys 0 through 7 (which have the Atari-ASCII values 48 through 55), lines 200 and 210 convert the keystroke to an even number between 09 and 14 for use in the SETCOLOR command. This program looks for three keystrokes one for each face of the cube. As each key is typed (try 5, 6 and 7, for example) a cube face will become visible. The result is that a "three-dimensional" representation of a cube is now nicely displayed on your screen.

If you want to change the shadings, type three more numbers between 0 and 7 and see what happens. Next, for some more excitement, type J, K and L. Once again you will see the shaded cube, but the color will have changed from gold to more of a magenta. As you can see, luminance values greater than 14 cause the hue to change.

Now that you know about shading, you should be able to make some truly beautiful pictures with the Atari.

Table 1. Hue Values For The Atari Computers

GRAY                 0
LIGHT ORANGE         1
ORANGE               2
RED-ORANGE           3
PINK                 4
PURPLE               5
PURPLE-BLUE          6
BLUE                 7
ANOTHER BLUE         8
LIGHT BLUE           9
TURQUOISE           10
GREEN-BLUE          11
GREEN               12
YELLOW-GREEN        13
ORANGE-GREEN        14
LIGHT ORANGE        15

Return to Table of Contents | Previous Section | Next Section