Using Colour (or COLOR)
First the listing then a description of the program.
This simple graphics demonstration program uses several of the
features of TI BASIC described in the preceding article.
The descriptive text which follows will help you to follow the
To enter this program, select TI BASIC, then ENTER the word NUM.
This will automatically provide the line numbers and you will only
have to type in the remainder of the lines.
100 REM DEMO OF COLOUR
110 REM IN TI BASIC
140 PRINT " "::::"ONE MOMENT..."::::::
150 DIM F(100)
160 DEF RAN(A)=INT(A*RND)+1
180 FOR CHARR=32 TO 152 STEP 8
190 CALL CHAR(CHARR,M$)
200 NEXT CHARR
210 FOR SET=1 TO 16
220 CALL COLOR(SET,16,SET)
230 CALL VCHAR(1,2*SET-1,24+SET*8,48)
240 NEXT SET
250 FOR SET=1 TO 9
260 CALL HCHAR(22,2*SET,48+SET)
270 NEXT SET
280 CALL HCHAR(22,20,48)
290 FOR SET=11 TO 16
300 CALL HCHAR(22,2*SET,38+SET)
310 NEXT SET
320 FOR SET=10 TO 16
330 CALL HCHAR(22,2*SET-1,49)
340 NEXT SET
350 FOR X=1 TO 1000
360 NEXT X
370 FOR SET=3 TO 14
380 CALL HCHAR(2*SET-5,1,24+SET*8,32)
390 NEXT SET
400 FOR X=1 TO 4000
410 NEXT X
420 INPUT " ENTER TO CONTINUE":A$
430 CALL CLEAR
440 CALL SCREEN(12)
450 FOR X=1 TO 150
490 CALL HCHAR(R,VR,24+SET*8)
500 NEXT X
510 FOR X=1 TO 50
560 CALL HCHAR(R,VR,SET,NO)
570 CALL HCHAR(25-R,33-VR,24+8*RAN(14),NO)
580 CALL VCHAR(1+VR/2,R/1.5+1,SET,3/4*NO)
590 NEXT X
600 FOR COUNT=32 TO 152 STEP 8
610 CALL CHAR(COUNT,"88CCEEFF88CCEEFF")
620 CALL CHAR(COUNT+1,"80C0E0F0F8FCFEFF")
630 CALL CHAR(COUNT+2,"7F3F1F0F070301")
640 CALL CHAR(COUNT+3,"FF3C181818183CFF")
650 CALL CHAR(COUNT+4,"00C3E7E7E7E7C3")
660 CALL CHAR(COUNT+5,"FFFEFCF8F0E0C080")
670 CALL CHAR(COUNT+6,"000103070F1F3F7F")
680 CALL CHAR(COUNT+7,"183C7EFFFF7E3C18")
690 NEXT COUNT
700 FOR COUNT=1 TO 100
710 CALL HCHAR(RAN(24),RAN(31),RAN(129)+31)
720 NEXT COUNT
750 FOR COUNT=1 TO 100
770 NEXT COUNT
780 FOR COUNT=1 TO 100
790 CALL SOUND(100,F(RAN(100)),1)
800 CALL COLOR(RAN(16),RAN(16),RAN(16))
810 IF RAN(10)>3 THEN 830
820 CALL SCREEN(RAN(16))
830 NEXT COUNT
840 FOR Z=1 TO 5
850 FOR COUNT=3 TO 30
860 CALL VCHAR(8,COUNT,RAN(129)+31,2)
870 CALL VCHAR(5,COUNT,RAN(129)+31,2)
880 CALL SOUND(-100,F(RAN(100)),1)
890 NEXT COUNT
900 FOR COUNT=30 TO 3 STEP -1
910 CALL COLOR(RAN(16),RAN(16),RAN(16))
920 CALL VCHAR(12,COUNT,RAN(127)+32,2)
930 CALL VCHAR(15,COUNT,RAN(127)+32,2)
940 CALL SOUND(-110,F(RAN(100)),1)
950 NEXT COUNT
960 NEXT Z
970 FOR Z=1 TO 26
980 FOR X=1 TO 28
1000 NEXT X
1010 PRINT M$
1030 CALL SOUND(-400,F(RAN(100)),1)
1040 NEXT Z
1050 FOR X=1 TO 100
1060 CALL COLOR(RAN(16),RAN(16),RAN(16))
1070 NEXT X
1100 FOR Z=1 TO 8
1110 FOR CT2=1 TO 16
1130 CALL SOUND(-100,RAN(200)+110,RAN(10))
1140 NEXT CT2
1150 FOR CT=1 TO 8
1160 CALL CHAR(8*CT+24+X,P$)
1170 NEXT CT
1200 NEXT Z
1220 CALL SCREEN(RAN(16))
1230 FOR X=1 TO 100
1240 CALL HCHAR(RAN(24),RAN(32),RAN(127)+32)
1250 CALL SOUND(-50,F(RAN(100)),RAN(20))
1260 CALL COLOR(RAN(16),RAN(16),RAN(16))
1270 NEXT X
1280 CALL SCREEN(RAN(16))
1290 FOR X=1 TO 100
1300 CALL COLOR(RAN(16),RAN(16),RAN(16))
1310 CALL SOUND(-20,110+20*RAN(40),3)
1320 NEXT X
1330 CALL SCREEN(RAN(16))
1350 FOR Z=1 TO 26
1360 FOR CT=1 TO 28
1380 NEXT CT
1390 PRINT M$
1410 CALL SCREEN(RAN(16))
1420 CALL COLOR(RAN(16),RAN(16),RAN(16))
1430 NEXT Z
1440 FOR CT2=1 TO 100
1450 CALL COLOR(RAN(16),RAN(16),RAN(16))
1460 NEXT CT2
1470 CALL SCREEN(RAN(16))
The use of brackets after RAN in line 160:
does NOT indicate that RAN is a variable array. They inform
the computer that when the newly created FUNCtion RAN is used
in a program, a variable will be passed to the definition by means
of the brackets.
e.g. 460 R=RAN(24)
The computer replaces RAN(24) with the defined statement
using the value 24 in place of X.
The use of brackets does not always imply an array!
Explanation of the Colour Demonstation program:
This program has been provided to give a practical
demonstration of some of the features of TI BASIC described
The program has been written in small blocks, and each block
will be described separately.
The first section, lines 100 to 420 form the start of the
program. The first block is intended to display the colours
available, and by making them cross over each other, show the
Because some random patterns are created later, RANDOMIZE has
been used to provide different patterns each time the program is
run. The array F contains frequency values for use with CALL
SOUND later on. As it will contain 100 values, DIM is used to
instruct the computer to allocate memory to hold the values.
The DEF function is used to create a new random function,
which will provide integer (eg no fraction) numbers from 1 to
the figure used with the new function in the program: watch out
for the new function RAN(X) in the program.
M$ has been set to "0" (a string with a zero in it) for use
in defining all the characters as blanks (eg spaces) in the
following loop in lines 180 to 200. The string "0" could have
been placed in the definition function in line 190, instead of
the string variable.
NB: Although the TI99/4A distinguishes the number 0 from the
letter O on screen by squaring the O, in listings a slashed 0
usually represents the number.
Each group of eight characters is in a separate character
set, and each set may be a different colour. Lines 210 to 240
change the colour of each set: TI Basic has 16 sets, and 16
colours. The foreground colour of every set has been set to
WHITE( code 16).
Line 230 places a number of vertical stripes on the screen,
each a different colour. As the screen is 32 columns wide, the
stripes have been set to 2 columns wide each, and therefore each
CALL VCHAR uses 48 characters (2x the 24 rows).
So that we know which colours are which, they are labelled by
the routine in lines 250 to 340.
Lines 350-360 give a small delay.
It is not possible to provide 16 horizontal bands with a space
between each, as the screen only has 24 rows, but lines 370 to
390 cross the screen with as many rows as can fit.
In lines 430 to 500, random characters are placed on a blank
screen, and in lines 510 to 590, random stripes and columns are
placed on screen.
Lines 600 to 690 redefine the characters for the purposes of
the following sections of the program. Remember that the strings
used with CALL CHAR can only contain the numbers 0 to 9 and the
letters A to F.
700 to 720 again place random characters on screen.
Lines 730 to 770 fill the F array with values to be used with
subsequent CALL SOUNDs. Line 730 sets the lowest possible
frequency, and line 740 sets the basis for the tones: the
formula used creates what is known as 'microtonal' music, with
very little difference between adjacent tones.
Then, accompanied with random tones, the character colours
are varied at random in lines 780 to 830.
Lines 840 to 960 provide sound, colour changes, and small
bars of random characters.
Lines 970 to 1040 use the PRINT routine to place random
characters on screen, and the colour is varied in 1050 to 1070.
In lines 1080 to 1200, characters are given a random
definition and in 1220 to 1260, the colours are varied, random
chracters placed and tones generated.
1270 to 1310 again varies the colours, and uses a different
random tone generation method (line 1300).
The remainder of the program again uses PRINT to provide a
random display and the colours are varied.
Note in particular the usefulness of the DEF statement in this
There are many 'loops', and some loops contain other loops :
see for example lines 840 to 960. These loops are 'nested', with
the COUNT loop inside the Z loop.
An ARRAY is used to store frequencies.
The loop counters (eg CHARR, SET and so on) also function as
numeric variables in the loops. Their value increases by one for
each cycle of the loop until the maximum value (set by the TO X
in FOR TO NEXT ) has been reached.
In line 1120, SEG$ is used with the string variable M$ (set in
1080) to create a random definition of a character. A letter is
chosen at random from the string variable M$, and used to create
the definition in the variable P$.
Note that P$ is reset to a 'nul' (empty) string after each
character has been defined. Then it is reused with different
letters to form a new definition.
TI BASIC GLOSSARY
A list of all the commands and functions available in TI BASIC,
with brief descriptions.
Used to obtain an ABSolute value - eg it ignores
the + or - sign.
Used to extend files when using the disk system
or mini memory module.
Provides the arctangent : this is a
trigonometrical function. ATN(X) provides the
angle in radians whose tangent is X.
Used in a program to temporarily halt execution.
A message is placed on screen. The program is
continued by typing in CONTINUE
Used to return to the master screen. Preferable
to the use of the QUIT key, as only BYE will
properly close any open files, and ensure no
data is lost.
Used to define character N by means of a
hexadecimal string STRING$.
Used to clear the screen.
Used to defing the foreground (FG) and
background (BG) colours of each of 16 sets of
characters. Sixteen colours, including
transparent are available.
Places in the variable CH the ASCII code of the
character on the screen in ROW, COLumn.
Used to display a character CH in ROW, COLumn.
When a number or variable in the position NO is
used, the character is repeated horizontally NO
Returns X and Y values for Joystick NO.
Interrogates the keyboard. If a key is depressed
the ASCII code is placed in variable CODE.
STATUS indicates if a key is pressed, and if it
is the same key when two adjacent CALL KEYs
detect a key pressed. NO indicates the key unit,
and is used to split the keyboard and to switch
the codes returned by the Function and Control
Used to change the colour of the screen.
Used to generate sound. Up to three tones may be
used with an optional noise channel. TIME is in
milliseconds and F1,F2 and F3 are the
frequencies in cycles per second.
As CALL HCHAR, but the character CH is repeated
vertically NO times.
Used to make a character CODE available as a
Used to close a data file.
Used to resume a program when execution has been
halted with the CLEAR key or a BREAK command.
Provides the cosine of angle X, where X is in
Used as a heading on lines containing values to
Used to DEFine a function of your own.
Used with the disk system to DELETE a file.
Used to DIMension an Array.
i. Same effect as PRINT
ii.One of two file storage formats. DISPLAY uses
the same codes and format as the computer
uses for screen displays.
One method of entering EDIT mode.
An optional marker for the end of your program.
'End Of File' used with disk files.
The inverse of the natural logarithm function
LOG. Thus X=EXP(LOG(X))
Used to define data files. The alternative, not
available with cassettes, is VARIABLE.
Used to establish loops which execute until the
counter reaches the value following TO.
Used for a line transfer when the program is to
RETURN to the line following the GOSUB line
after the section transferred to is completed.
Used to make a simple line transfer.
Used to make conditional line transfers, with an
optional alternative transfer if ELSE is used.
i. Used to fill a variable from the keyboard,or
other device if a data file is used.
ii.Used to specify a file is to be used for
Used to provide the INTeger of a number NO.
eg any fraction is removed.
Used to specify the format of a data file.
INTERNAL specifies the codes used by the
processor internally. The alternative is
Used to provide the LENgth of the string
Optional. LET A=2 and A=2 are both accepted.
Lists a program on screen or other device.
Provides the natural logarithm of number NO.
Used to clear the console memory in preparation
for a new program.
NUM / NUMBER
Provides line numbers automatically when a
program is to be keyed in. Starting number and
increment may be defined. Default is to start at
100 and increase each line number by 10.
Used to load a program from cassette or other
Used for GOSUB transfers when the value
following ON determines which of the line
numbers following GOSUB are to be used.
Similar to the above, but for simple line
transfers when it is not wished to RETURN to the
line following the transfer.
Used to OPEN a file to a device.The format of
the file is specified after the OPENcommand.
Used to set the minimum value of an array to
zero or one.
Used to specify a data file is to be used for
Used to obtain the first occurrence in STRING$
i. Used to display characters on the screen and
to scroll the screen upwards.
ii. Used to send data to an external storage
device when used with files.
Used to obtain a RaNDom number. The same
sequence of numbers is generated every time a
program is RUN.
Used to set the initial number used by RND to be
different each time a program is RUN.
Used to place the values in DATA statements into
Used with the disk system to specify a specific
RECord in the file.
Used with the disk system for random access to
data on a file by using RECord numbers.
Used to add REMarks to programs.
RES / RESEQUENCE
Used to resequence a program, that is, change
the line numbers. Default is to start the
program at line 100 and use increments of 10,
but start number and increment may be specified.
Used to reset the DATA pointer, either to the
first data item, or to data on a particular
Any line transfer by GOSUB must be terminated
with RETURN. The program then transfers to the
line following the GOSUB.
Instructs the computer to RUN the program in its
Used to SAVE a PROGRAM to a storage device.
Used to specify that file data is recorded in
the order it is output. The alternative is
RELATIVE, which is not available with cassette
Used to obtain the SiGN of the number NO.
Indicates if NO is zero,negative or positive.
Provides the SINe of the angle X where X is in
Provides the SQuare Root of the number X.
Used to STOP program execution. A STOPped
program may only be resumed by re-RUNning it.
Used to change a number or numeric variable into
a string. The converse is VAL.
Used when PRINTing to print at from a specified
Provides the TANgent of angle X where X is in
Causes the computer to list on screen the number
of each line as a program is executed. Switched
off with UNTRACE.
Used in command mode to remove BREAK commands
which have been placed in command mode.
Switches TRACE off.
Used with disk file processing to enable a file
to be read or written to.
Used to obtain the numeric equivalent to a
string. The string must be composed only of
Used with disk files to indicate the file is to
be as long as the item to be stored, which may