Using Strings For Graphics Storage
If you've ever been frustrated attempting to PLOT and DRAWTO your way through a complex pattern or design in Atari graphics, you might appreciate a method of graphics generation using text strings to store pixel data. While this string method is not simpler to use in all cases, its ease of data entry and manipulation possibilities make it a strong graphics tool.
Simple line drawings over large areas of the screen are best done using PLOT and DRAWTO commands, since this method uses less memory and generates images faster than the string method will. However, if you have a very complex pattern in a small area of the screen, the string method works well. The heart of string graphics lies in the fact that if you run a PRINT #6 statement followed by ASCII characters while in graphics modes 3-7, colored pixels will appear on the screen. Different letters and symbols will plot different colors, but for our purpose we will deal only with the letters A, B, C, and D. Each of these letters plots a different colored pixel in graphics modes 3, 5, and 7:
A plots color 1 (color register #0)
B plots color 2 (color register #1)
C plots color 3 (color register #2)
D plots color 0 (color register #4)
In graphics modes 4 and 6, only the letters A and B need be used, A for the plotting color, B for the background color.
For a demonstration, typing the command
GRAPHICS 3: PRINT #6; "ABCDA"
moves the pixel string down and to the right.
Creating A Graphics String
We can now use the above methods to plot a pattern. First graph out the area needed for the pattern, then fill in the pattern using "A", "B", "C", and "D" to represent the colors wanted:
String 1 CDDDDAAAAA
String 2 DCDDDDDDAA
String 3 DDCDDDDADA
String 4 DDDCDDADDA
String 5 DDDDCADDDA
String 6 AAAAACDDDD
String 7 ABBBADCDDD
String 8 ABCBADDCDD
String 9 ABBBADDDCD
String 10 AAAAACCCCC
Now break down the graph as a series of strings, in this case ten string of ten characters each:
String 1 is "CDDDDAAAAA"
String 2 is "DCDDDDDDAA" etc.
Concatenate the ten strings for more efficient data storage:
We have now generated all the data necessary to plot our figure (a square with an arrow) in the graphics mode, and have stored it in one long string.
To plot the string on the screen, determine where you would like the upper left-hand corner of the figure to be located, and enter it during the run of the following program after prompt "X,Y?".
10 GRAPHICS 5
20 DIM A$(100)
40 PRINT "X,Y";:INPUT X,Y
80 FOR K = 1 TO 10
90 POSITION X,Y+K-1
100 PRINT #6;A$(K*10-9,K+10)
110 NEXT K
In this program, lines 20 and 30 set up our main pixel data string, and line 40 establishes the upper left corner coordinates of the figure. Lines 80 and 110 set up a loop of ten steps, to divide our main data string into seven rows. Line 90 positions the cursor for each row, and line 100 prints ten consecutive ten-character strings on the screen.
Obviously, there are figures which require strings too long for direct entry in Atari BASIC. In that case, divide the figure into several rectangular sections, each small enough for inclusion into one string (usually under 100 characters in length). Then concatenate the string as explained in the Atari BASIC Reference Manual, p. 39.
Plotting a figure using string graphics is fairly simple and straightforward. Its real strength lies in figure manipulation through string reading. Some easy manipulations are:
1. Figure rotation (in 90¡ increments)
2. Figure inversion
3. Color changes
For figure rotation, using the same example figure and data string, let's substitute and add to the previous program. For a 90-degree turn clockwise, add and substitute:
20 DIM A$(100),B$(100)
50 FOR K = 1 TO 10: FOR L = 1 TO 10
70 NEXT L, NEXT K
100 PRINT #6;B$(K*10-9,K*10)
For a 270-degree clockwise rotation, substitute to the above:
60 B$(K*10- 10+L,K*10 - 10+1)+A$(L*10+1 -K,L*10+1 -K)
For a 180-degree clockwise rotation, substitute to the above:
50 FOR K=1 TO 100
70 NEXT K
To change color assignments, add and substitute to the original program:
50 FOR K=1 TO 100
60 IF A$(K,K) = "C" THEN A$(K,K) = "A"
70 NEXT K
To invert a figure, substitute to the original program:
100 PRINT #6;A$((11- K)*10-9,(11-K)*10)
To turn a figure left to right, substitute in the 180-degree rotation program:
100 PRINT #6;B$((11-K*10-9,(11-K)*10))
The string used to manipulate this 10 x 10 figure can easily be incorporated into subroutines for use in programs using repetitive figures in different positions. Further experimentation for more possibilities is definitely in order.
Return to Table of Contents | Previous Section | Next Section