PROGRAMMING THE TI
Planning Color Sets
In a previous column we looked at defining characters for graphics. Let's expand on that idea and discuss in more detail how to plan the color sets for high-resolution graphics.
To define colors for your graphics, use the CALL COLOR statement. The form is CALL COLOR(s,f,b) where s is the set number, f is the foreground color, and b is the background color. Each of the numbers can be from 1 to 16. Each graphics character you define can have two colors (a foreground color and a background color) chosen from the list of 16 colors.
The Color Sets
There are 16 color sets. Each color set contains eight character numbers (ASCII codes). The table shows which ASCII character codes are in which color set. You may find it handy to mark off these sets on the "Character Codes" table on the BASIC Reference Card that came with your computer. Just make a mark after every eighth number, then number the sets so you can tell at a glance which character is in which set — and which other characters are in the same set.
Now try this short program to see how the CALL COLOR statement works:
100 PRINT "HELLO THERE!" 110 PRINT "THIS IS A SAMPLE." 120 CALL COLOR(5,7,1) 130 GOTO 130
RUN the program. Lines 100 and 110 just print some words on the screen. By the way, we didn't use a CALL CLEAR statement, so the program will also still be on the screen. The screen turns green when the program starts to run. Line 120 says to change all characters in set number 5 to a red foreground (color 7) and a transparent background (color 1). Line 130 holds the colors on the screen until you press FCTN 4 to CLEAR or stop the program (SHIFT C on the TI-99/4 console). You will notice when you RUN the program that the screen turns green, and then all the letters in Set 5 (@, A, B, C, D, E, F, G) turn red. Color 1 for the transparent background means that the background for the character will be the screen color.
Stop the program by pressing CLEAR. Change line 120 to
120 CALL COLOR(5, 6, 1)
The letters turn blue. Go ahead and try different colors for the second number in parentheses.
Now experiment with background color. Add these lines to your program:
130 FOR DELAY = 1 TO 100 140 NEXT DELAY 150 CALL COLOR(6, 7, 16) 160 FOR DELAY = 1 TO 100 170 NEXT DELAY 180 CALL COLOR(6, 16, 7) 190 GOTO 130
Lines 130-140 and 160-170 are delay loops. RUN the program. Line 120 changes the letters in Set 5 to whatever color you specified. Line 150 changes the letters in Set 6 (H, I, J, K, L, M, N, O) to a red (7) foreground and a white (16) background. Each character will look like a red letter on a white square. After the delay loop, line 180 changes the letters in Set 6 to a white foreground and a red background — now white letters on red squares. Line 190 branches to the delay loop in line 130, so the letters in Set 6 blink red on white then white on red.
Notice that as soon as you use a CALL COLOR statement, all characters in that set change color — those already on the screen and any that you may later print or draw on the screen. Careful planning is necessary so you know exactly which characters you are defining to be certain colors.
If you would like to change the screen color, use CALL SCREEN(c), where c is a color number from 1 to 16. For example, add line 90 and run your program:
90 CALL SCREEN(12)
Keep in mind that anywhere you have used the color number 1, for transparent, it really means the screen color.
Now try another special effect. Add line 125:
125 CALL COLOR(1,2,8)
This changes all characters in Set 1 to black on cyan (instead of black on transparent). RUN the program. The "space" is Character 32 in Set 1, and all spaces have been turned to cyan. The screen is light yellow from line 90, so you get a border around a cyan rectangle with various colors of letters from the rest of the program.
The default value of all character sets is black on transparent, so the letters on the screen are black on the screen color of yellow. If you would like a complete cyan rectangle with black letters on the cyan background, the character sets would need to be changed to black on cyan.
Keep in mind that it does make a difference in your programming whether you print first then define the colors, or define the colors and then print. Plan your program so that the computer will perform the actions in exactly the order you want.
Here is another sample program. Type NEW (enter), and then try this program. Watch carefully.
100 CALL CLEAR 110 CALL VCHAR(10, 5, 42, 9) 120 CALL VCHAR(10, 10, 42, 9) 130 CALL HCHAR(14, 6, 42, 4) 140 CALL VCHAR(10, 17, 42, 9) 150 CALL VCHAR(10, 24, 33, 6) 160 CALL VCHAR(18, 24, 33) 170 CALL COLOR(2, 7, 1) 180 GOTO 180
The computer is quite fast, but you can see that the screen clears, the characters are drawn in black, and then some of the characters turn red. If you prefer to have the asterisks printed in red from the start, the CALL COLOR statement must come before the CALL VCHAR and CALL HCHAR statements. Delete line 170 and add
105 CALL COLOR(2,7,1)
RUN the program and you can see the difference.
Another thing you can try is to draw your characters invisibly and then make them appear all at once. This is quite effective if you have a lot of CALL HCHAR and CALL VCHAR statements drawing an intricate picture. For this program, make the following changes:
105 CALL COLOR (2, 1, 1) 106 CALL COLOR (1, 1, 1) 170 CALL COLOR (2, 7, 1) 175 CALL COLOR (1, 2, 1)
First the characters in Sets 2 and 1 are made invisible by setting both foreground and background to transparent. Next the characters are drawn with CALL HCHAR and CALL VCHAR statements. You won't be able to see this process. Last, line 170 colors the asterisks red, and line 175 colors the exclamation points black so the greeting appears all at once.
When defining your own graphics characters, you may use any character number. If you want to keep the alphabet intact, you will probably use character numbers beyond 95. Group your characters so that all characters of the same color will be in the same set.
Remember that there are eight characters per set. If you are using many different colors or need to conserve memory, you will also need to plan the number of characters you can design in each set. For example, if you have a dog that uses nine characters, could you redraw him in eight characters so only one CALL COLOR statement would be needed?
Refer to the table to determine which characters are in which set. For example, if you are designing character number 134, it will be in Set 13, which contains characters 128-135. Your CALL COLOR statement will use set number 13.
If you are not using the small letters in character codes 97-122 (available on the TI-99/4A console, but not on the TI-99/4), use those numbers to define your graphics characters, then PRINT the characters rather than using HCHAR and VCHAR to draw them on the screen. PRINT TAB(10);"hikn" will be much faster than four separate CALL HCHAR statements to put up characters 104, 105, 107, and 110. By the way, your listing will say "hikn" with the small letters, but when your program is run those letters will be substituted by the graphics characters as you defined them. If you want to use the PRINT method on characters numbered higher than 126, you may use a statement such as PRINT CHR$ (132)&CHR$(133)&CHR$(137).
The following program illustrates the use of color sets in an educational program. "Teeth Wisdom" draws the teeth and their names on the screen in high resolution graphics. After the user knows the names, he or she presses ENTER and the labels clear. The names will be reprinted in a random order. For a quiz, certain teeth will "blink" and the user must press the correct answer. The order will be random.
The teeth are drawn white on a light red background, and the gums are light red on a transparent background. Although all the teeth are white, they are defined in different color sets so that only certain teeth will blink during the quiz. The central incisors use characters 96-100; the lateral incisors, 104-107; the cuspids, 112-117; the bicuspids, 120-127; and the molars 128-134. The gums use characters from 136 to 157.
Since so many graphics characters are defined, DATA statements rather than individual CALL CHAR statements are used. The DATA in lines 240 to 330 are character definitions. Be careful to type these lines exactly as shown. The round symbols are zeros and not the letter O. When there are two or more commas in a row, it means that a character is defined as a null string. At the end of a data list such as line 250, the "" (double quotes) marks are necessary to indicate a null string, but in a series such as in line 260, the quote marks may be omitted between commas. These null strings correspond to unused character numbers.
Lines 180-230 let the character number C vary from 94 to 157 and READ in a string then define character C with graphics definition C$. The CALL COLOR statements blink the asterisks on the title screen while the characters are being defined. Lines 340-390 define the colors for the teeth and gums.
Lines 590-690 PRINT the graphics on the screen, which is faster than using individual CALL HCHAR or CALL VCHAR statements for this many special characters. Within the quotation marks are the lowercase letters – release the ALPHA LOCK key to type these symbols in. Line 610 uses the symbol found on the face of the "C" key and is typed by pressing FCTN and C. Other symbols requiring the FCTN key are in lines 640 and 650.
For The TI-99/4 Console
If you have the TI-99/4 console, you will not be able to type in these lines. You can use the method found in line 600 to print the characters, listing each character number. Note: If a program like this has been typed in on the TI-99/4A console, it will work correctly on the TI-99/4 console (read it in from cassette or diskette).
In the quiz, lines 900 and 910 blink the particular teeth while the computer waits for a response. A random number (I) is chosen, and the corresponding color set is I + 8 for the CALL COLOR statements.
|110-170||Clear screen; print title screen.|
|180-230||Define graphics characters 94 through 157 by READing the definitions from DATA; blink asterisks on screen green and white.|
|240-330||DATA containing graphics definitions.|
|340-360||Define color sets 9 through 13 as white on light red for teeth.|
|370-390||Define color sets for light red on transparent for graphics surrounding teeth.|
|400-510||Clear screen; print instructions; define strings as groups of characters for later printing.|
|520-560||READ in names of five groups of teeth as N$ array and set the W$ array elements equal to the N$ array elements.|
|570||Prints message to press ENTER and waits for response.|
|580-690||Clear screen; print teeth with labels.|
|700||Prints message to press ENTER and waits for response.|
|710-760||Clear message and clear labels.|
|770||Prints quiz title.|
|780-850||Randomly print names of teeth on screen from the W$ array of five names. A(I) will be the correct corresponding answer.|
|870-880||Randomly choose teeth.|
|890-920||Blink teeth blue and white while waiting for response.|
|930-940||If number 1-5 is pressed, show which number was pressed, otherwise return to line 890.|
|950-990||If answer is incorrect, sound "uh-oh" and return for another response.|
|1000-1030||If answer is correct, play arpeggio.|
|1040||Clears answer chosen.|
|1050-1060||Set A element to zero so that tooth will not be chosen again; return to next problem.|
|1070-1100||Print option to try again; wait for response; branch appropriately.|
|1110-1140||If user wants to try again, set W$ array elements equal to names of teeth, branch to beginning of exercise.|
|1160-1190||Subroutine to print "PRESS <ENTER>" and wait for response.|
|1200-1210||Clear screen and END.|