Classic Computer Magazine Archive COMPUTE! ISSUE 30 / NOVEMBER 1982 / PAGE 221

A Fill-In On XIO(FILL)

Gretchen Schabtach
Alexandria, VA

This tutorial article presents several interesting extensions for the XIO(FILL) program on page 54 of the Atari BASIC Reference Manual.

Your Atari readily fills line drawings of figures with color using a special application of the XIO statement. However, the example in the BASIC Reference Manual (see page 54) can be expanded upon to demonstrate the strengths and limitations of this application. A critical point about XIO filling is that filling stops when a pixel which has been previously filled with color is encountered. Thus, interesting effects occur when the Atari is commanded to fill overlapping figures with color.

To get the most from the following short programs, begin by running the demonstration program on page 54 of the BASIC Reference Manual. Then run Program 1. Program 1 generates three rectangles, randomly positioned, with random proportions, and fills them from top to bottom and left to right with three different colors. Observe what happens when the figures overlap.

Moving line by line, from top to bottom and left to right, the fill stops when a colored pixel is encountered. Thus, when the program generates two overlapping rectangles, filling of the second rectangle stops whenever the first filled rectangle is encountered – and does not resume even if the second rectangle extends to the right beyond the first rectangle.

With a few modifications, Program 1 is not only illuminating with regard to the XIO(FILL) function, but also much more interesting. First, randomly change the colors to be used in filling. Second, generate rectangles continuously. To do this, make the following changes:

 20 N = INT(RND(0)*3 + 1)
160 (i.e., delete)
170 GOTO 20

After you've modified the program as specified above, run it and admire the changes. Now, add a little music to your life. This is easily accomplished by adding the following statements:

81 I = INT(RND(0)*256)
82 SOUND 1,I,10,4
84 SOUND 2,255-I,10,4

Try this, and then delete line 150. This will speed things up a little and make them even more interesting.

Finally, black backgrounds can become tiresome. To randomly change the background color, type in the following:

 11 REM : CHANGE BACKGROUND
 12 B = INT(RND(0)*16)
 13 SETCOLOR 4,B,2
166 REM : CHANGE BACKGRD SO GOTO 12
170 GOTO 12

Your final program listing should look like that shown in Program 2.

There are further simple and interesting modifications. For example, vary the constants in statements which include random number generators – those containing (RND(0)); or delete + 16 in line 10 and provide yourself with a text window in which you can write commentary on what the viewer sees; or change the characteristics of the shapes generated to be filled with color (lines 40 through 80). Your imagination will suggest other possibilities.

Program 1.

3 REM : DEMO OF XIO FILLING 5 REM : BY GRETCHEN SCHABTACH 6 REM : AND MERLIN (ATARI 800) 8 REM : SUPPRESS WINDOW IN GR. 7 10 GRAPHICS 7 + 16 15 REM : ESTABLISH 3 FILL COLORS 20 FOR N = 1 TO 3 STEP 1 30 COLOR N 35 REM : GENERATE FIGURE TO FILL 40 X1 = INT(RND(0)*80) 50 Y1 = INT(RND(0)*48) 60 X2 = X1 + INT(RND(0)*80) 70 Y2 = Y1 + INT (RND(0) *48) 80 IF X1 = X2 OR Y1 = Y2 THEN 40 90 PLOT X2, Y2 100 DRAWTO X2, Y1 110 DRAWTO XI, Y1 115 REM : FILL FIGURE 120 POSITION X1, Y2 130 POKE 765, N 140 XI0 18, #6, 0, 0, "S:" 150 FOR W = 1 TO 400 : NEXT W 155 REM : CHANGE COLOR FOR NEXT FIGURE 160 NEXT N 165 REM : GENERATE NEW FIGURE 170 GOTO 10

Program 2.

3 REM : DEMO OF XIO FILLING #2
5 REM : BY GRETCHEN SCHABTACH6 REM : AND MERLIN (ATARI 800)
8 REM : SUPPRESS WINDOW IN GR.7
10 GRAPHICS 7 + 16
11 REM :CHANGE BACKGROUND
12 B = INT(RND(O)* 16)
13 SETCOLOR 4, B, 2
15 REM : ESTABLISH 3 FILL COLORS
20 N = INT(RND(O)*3+1)
3O COLOR N
35 REM : GENERATE FIGURE TO FILL
40 X1 = INT(RND(O)*80)
50 Y1 = INT(RND(O)*48)
60 X2 = X1+INT(RND(O)*80)
70 Y2 = Y1+INT(RND(O)*48)
S0 IF X1 = X2 OR Y1 = Y2 THEN 40
81 I = INT(RND(O)*256)
82 SOUND 1, 1, 10, 4
84 SOUND 2, 255-1, 10, 4
90 PLOT X2, Y2
100 DRAWTO X2, Y1
110 DRAWTO XI, Y1
115 REM : FILL FIGURE
120 POSITION X1, Y2
130 POKE 765, N
140 XIO 18, #6, 0, 0, "S:"
155 REM : CHANGE COLOR FOR NEXT FIGURE
165 REM : GENERATE NEW FIGURE
166 REM : CHANGE BACKGRD SO GOTO 12
170 GOTO 12