Classic Computer Magazine Archive COMPUTE! ISSUE 56 / JANUARY 1985 / PAGE 141


C Regena

Mixing Graphics And Music

I've talked about combining graphics with music in a TI program before. This month I'll add a few more ideas and techniques to try to help you in your programming. Remember, there are many ways to do the same thing, and the important idea is to enjoy your computer!

Clear-Screen Effects

The command CALL CLEAR is the usual way to quickly clear the screen. For a different effect, try:

CALL HCHAR(1, 1, 32, 768)


CALL VCHAR(1, 1, 32, 768)

These statements tell the computer to start with the first row and first column and fill the screen with 768 spaces (ASCII character 32).

If you want to fill the screen with a color, try the following example. Set the variable C to the desired color number:



100 CALL COLOR(9, C, C)
110 CALL HCHAR(1, 1, 96, 768)

Following is a sample program segment that illustrates another way to clear the screen—by starting at the center and moving outward.

110 CALL COLOR (9, 14, 14)
120 C = 13
130 T = 8
140 U = 0
150 FOR R = 12 TO 1 STEP -1
160 CALL HCHAR (R, C, 96, T)
170 CALL VCHAR (R + 1, C, 96, U)
180 CALL VCHAR (R + 1, C + T - 1, 96, U)
190 CALL HCHAR (R + 1, U, C, 96, T)
200 C = C - 1
210 T = T + 2
220 U = U + 2
230 NEXT R
240 GOTO 240

Another effect is to change all the spaces to a different color by redefining the color for color set 1:

CALL COLOR(1, 2, 7)

This definition will retain the default foreground color of black (color 2) for the symbols in set 1, but will change the background color to 7. Since the space character is blank, the background color shines through wherever there's a space.

Making The Invisible Visible

The CALL COLOR statement changes the color of any characters in the specified set on the screen. For example, try writing a program to print a message on the screen, then follow the message with this statement:

200 CALL COLOR(5,10,1)

All the characters in set 5 will change from black to red.

Remember that the number 1 in a color definition means transparency, or the current screen color. Try drawing something on the screen transparently, then use a different CALL COLOR statement to make the object appear all at once.

For example:

110 CALL COLOR (6, 1, 1)
120 PRINT "HI JIM"  =   =   =
130 CALL COLOR (6, 13, 1)
140 GOTO 140

Line 100 clears the screen, then line 110 defines the colors for set 6 to be transparent. Line 120 prints a message and scrolls it upward. Line 130 makes the printing visible by changing the color set to dark green. Line 140 keeps the color on the screen until you press CLEAR.

Changing Character Shapes

Another technique you may have fun with is to change a character definition while the character is on the screen. For example, suppose you have a lot of printing on the screen, then you use CALL CHAR to redefine the letter E as a straight line. Wherever there is an E on the screen, it will suddenly appear as a straight line. The following sample program illustrates what happens when you change the definition of the space character. The GOSUB statement is a simple delay loop to pause between definitions.

100 CALL CHAR (32, "FF")
110 GOSUB 190
120 CALL CHAR (32, "010204081020408")
130 GOSUB 190
140 CALL CHAR (32, "101010101010101")
150 GOSUB 190
160 CALL CHAR (32, "8040201008040201")
170 GOSUB 190
180 GOTO 100
190 FOR D=1 TO 200
200 NEXT D=1 TO 200
220 END

Graphics can be a lot of fun. If you like to use graphics, you really need to just sit at the computer and try different things. See what happens if you define the colors first, then display the characters, or if you change the colors after the graphics are on the screen. Try defining the characters before or after printing them on the screen. Look at the difference between using PRINT and CALL HCHAR or CALL VCHAR statements.

A Holiday Greeting

This month I've included a program which is my holiday greeting to you. This program combines sound and graphics using some of the techniques previously discussed. Here's a breakdown of the program.

Line 100 clears the screen, then line 110 changes the screen color to dark blue. The default values of a CALL COLOR statement are black printing on a transparent (screen color) background. Line 140 will change all the spaces to a blue background rather than screen color. The CALL COLOR statements in lines 150–190 change the color sets for graphics to be solid blue squares—the graphics will be drawn invisibly at first. The CALL COLOR statements in lines 200–240 change the printing to white letters on a blue background.

Lines 320–440 print the graphics on the screen. These lowercase letters and symbols need to be typed with the ALPHA LOCK key released. Turn the ALPHA LOCK key back on to type the rest of the program. Since the letters are blue with a blue background on a blue screen, you won't see anything yet.

Line 480 changes the screen color to black. In effect, this puts a black border around the screen (recall that all spaces and other characters are blue). The extra PRINT statements and colons format an attractive left and right margin.

Lines 490–860 define the graphics characters while music is set up and playing. Remember, the graphics are already on the screen, but are invisible because they are blue. Lines 870–890 change the colors of sets 10, 11, and 12 to red with a blue background, making the sleigh appear. Line 920 changes the colors of set 9 so all the reindeer appear instantly.

If you'd like the message to blink, you can add some CALL COLOR statements for sets 5 through 8 among the CALL SOUND statements in lines 930–1170.

Adding The Sound Track

After the graphics in this program were completed, I added the SOUND statements for the music. Line 120 sets a tempo or time of 440. By using the variable T at the beginning of the program and expressing all durations as a function of T, you can change the tempo of the whole song by simply adjusting the value of T in line 120.

When writing the program, I tried only the melody notes of the song first to make sure the graphics did not interfere with the tempo of the music. Later I added two accompaniment notes for each statement.

Sometimes when you have two CALL SOUND statements with the same note and volume, the resulting sound is one long note rather than two shorter notes. To make sure you get distinct notes, you can change the volume numbers slightly. If you want to make two different chords sound like they have a common tied note, keep the frequency and volume the same for that note.

To make the melody heard over the accompaniment, use a louder volume for the melody notes. For example, use a volume of 2 for the melody, 5 for the middle note, and 8 for the bottom note:

CALL SOUND(T, 466, 2, 294, 5, 175, 8)