Classic Computer Magazine Archive COMPUTE! ISSUE 72 / MAY 1986 / PAGE 102

Programming the TI

C. Regena

Animation In TI BASIC

The theme for this issue of COMPUTE! is graphics and animation, so we'll discuss some ways you can animate in TI BASIC. TI Extended BASIC adds really fun animation with the sprite features, but even in regular console BASIC you can make characters move. I'm going to suggest four ways you can animate your graphics.
    Perhaps the simplest way to move something on the screen upward is to use the PRINT statement. The short program below draws a rocket at the bottom of the screen. Lines 140-160 print blank lines which move the rocket toward the top of the screen. (You may also use PRINT with colons.) Of course, any other graphics you might have on the screen also move upward as you print. This method works best with larger objects that need to be moved upward because you don't need to redraw the graphics.

110 CALL CLEAR
120 CALL CHAR(130,"1038383E
    36387C44")
130 CALL HCHAR(24,15,130)
140 FOR P=1 TO 21
150 PRINT
160 NEXT P
170 END

    The next short program illustrates a way to move an object across the screen horizontally. This method involves erasing the object and then redrawing it-all the way across the screen. Unlike the previous method, this won't affect other graphics on the screen. Although it works with several characters, objects move more quickly and more smoothly if you use only one character.
    The program redefines character number 130 as an arrow. In a FOR-NEXT loop that changes the column number, first a space (character number 32) is placed in the previous column to erase the existing arrow, then the new arrow is drawn in the next column. This repeatedly erases and redraws the arrow one column to the right. Run the program to see how fast the arrow moves across the screen.

110 CALL CLEAR
120 CALL CHAR(130,"080C0EFF
    0E0008")
130 FOR C=3 TO 28
140 CALL HCHAR(8,C-1,32)
150 CALL HCHAR(8,C,130)
160 NEXT C
170 END

    This method is probably the most common way to move a character. You can move it in any direction by erasing the character in the present position, then changing the row and column and redrawing it in another position. In this short example, we've erased the character with a blank space. But if the character is moving over other graphics, you might need to erase it with the appropriate graphics characters to restore the background. Otherwise, the moving character would leave behind a trail of spaces. This method of animation is rather jerky if your object consists of several characters that need to be moved, but it can be fairly quick with just one character.

CALL COLOR Motion
The next example program illustrates a different way to move an object made up of several characters. Rather than moving one character at a time, we'll use CALL COLOR to make all the characters in the set invisible at once, then another CALL COLOR to make the object in the next position visible.
    This sample draws an eight-character horse. The horse is actually drawn eight times on the screen using eight different character sets. Lines 130-200 define strings for eight graphic character definitions. The loop in lines 210-250 defines the graphic characters. In each of the sets from number 9 to 16, the characters are defined using the strings A$.
    Lines 260-380 are another loop. Line 270 makes the characters invisible. Lines 280-290 determine a character number and a row number depending on the set number. Lines 300-370 draw the horse. This loop draws eight horses on the screen vertically, but they are all invisible.
    Lines 390-470 are the loops that create the movement. The CALL COLOR statement with a 14 defines the horse as color 14 for a particular color set. The horse moves up and down as the color set number varies and one set is made invisible and the next set made visible. All you need to do is add the rest of the carousel and the music!
    This example has only one horse moving up and down. You could draw more horses on the screen-for example, with the set number 9 horse at the bottom of the screen and the set 16 horse at the top. No matter how many horses are on the screen, the CALL COLOR statement changes all the horses in a particular set. You can have several objects moving at the same time by using the CALL COLOR loops in lines 390-470.

110 CALL CLEAR
120 CALL SCREEN(16)
130 A$(1)="2E3F3F7F7FFFE7E7
    "
140 A$(2)="00808000C0E0E0E"
150 AS(3)="07070707071F7FFF
    "
160 A$(4)="F1FFFFFFFFFFFF8"
170 A$(5)="FFFDFCFCFCFCF8F8
    "
180 A$(6)=110000E0E0E0602"
190 AE(7)="C060301A0E"
200 A$(8)="F8783C1830606"
210 FOR C=9 TO 16
220 FOR J=1 TO 8
230 CALL CHAR(C*8+23+J,A$(J
    ))
240 NEXT J
250 NEXT C
260 FOR C=9 TO 16
270 CALL COLOR(C,1,1)
280 CH=C*8+23
290 ROW=(C-8)*3-1
300 CALL HCHAR(ROW-1,14,CH+
    1)
310 CALL HCHAR(ROW-1,15,CH+
    2)
320 CALL HCHAR(ROW,14,CH+3)
330 CALL HCHAR(ROW,15,CH+4)
340 CALL HCHAR(ROW,16,CH+5)
350 CALL HCHAR(ROW,17,CH+6)
360 CALL HCHAR(ROW+1,14,CH+
    7)
370 CALL HCHAR(ROW+1,16,CH+
    8)
380 NEXT C
390 FOR C=9 TO 16
400 CALL COLOR(C-1,1,1)
410 CALL COLOR(C,14,1)
420 NEXT C
430 FOR C=16 TO 9 STEP -1
440 CALL COLOR(C,1,1)
450 CALL COLOR(C-1,14,1)
460 NEXT C
470 GOTO 390
480 END

CALL CHAR Animation
The last method of animation I'm going to discuss this month is using CALL CHAR. Just as CALL COLOR instantly changes the color of all characters on the screen in that color set, CALL CHAR redefines a graphic character definition of all characters of that number on the screen. For example, if you have something on the screen and execute CALL CHAR(32,"FF"), all of the characters with number 32 (all the spaces) instantly change to the new character definition, in this case a horizontal line.
    The following program illustrates this technique. Lines 110-180 clear the screen and draw a simple face using keyboard symbols. You can draw a much fancier face, but this is just a sample. To type the eyes, use the function key along with the C key to get the ' mark. This is character 96. Line 190 redefines character 96 for an open eye. Lines 200-210 create a delay loop while the eye is open, then line 220 redefines character 96 as a closed eye. Lines 230-240 create another delay loop. Line 250 branches back to line 190 to open the eye.

110 CALL CLEAR
120 PRINT TAB(61;"@@@@@@@@@
    @"
130 PRINT TAB(6);"@       
    @"
140 PRINT TAB(6);"@  '  ' 
    @"
150 PRINT TAB(6);"|     ^ 
    |"
160 PRINT TAB(6);"|     ~
    |"
170 PRINT TAB(6);"\      
    /"
180 PRINT TAB(7);"\______/"
    ::::
190 CALL CHAR(96,"18247A7A7
    A7E81")

200 FOR DELAY=1 TO 500
210 NEXT DELAY
220 CALL CHAR(96,"000000008
    37D2548")
230 FOR DELAY=1 TO 100
240 NEXT DELAY
250 GOTO 190
260 END

Latest TI News
Now a few comments on the TI-99/4A world. .I enjoyed a recent visit to Las Vegas to the Southern Nevada Users Group (SNUG, P.O. Box 26301) and also met several people from the Los Angeles and San Diego areas. Terri Masters, president of the L.A. 99er Computer Group (P.O. Box 3547, Gardena, CA 90247), was busy preparing for their Fest-West expo to be held March 1-2. It will be over by the time you read this, but you can plan on attending next year. Chicago holds an annual fest in October, and other groups have expos as well, so you can see the TI-99/4A is not dead.
    I also met Craig Miller of Millers Graphics (1475 W. Cypress Avenue, San Dimas, CA 91773), who demonstrated his GRAM Kracker, which will open up all sorts of possibilities for TI owners. This device can save a module (cartridge) program onto a disk or cassette. It also allows you to change or customize a module program-for example, change the title screen or default colors. Miller was also distributing his new book, The Orphan Chronicles, by Ron Albright. This book tells the history of the TI and includes a current list of TI dealers, manufacturers, and user groups.
    Les Merryman (Lancaster, California), a distributor for Myarc, was also at the SNUG meeting and showed several new Myarc products, including disk controllers, a hard disk drive, and their new Extended BASIC module.
    Please don't write to me about hardware products-write directly to the manufacturers and distributors. There are still companies making peripherals for the TI, and there are people who have as many as four disk drives hooked up to their machines. Even though Texas Instruments quit selling the TI-99/4A more than two and a half years ago, user groups are still going strong, and it's amazing what people are doing with their TIs.