The Fluid Brush

Al Baker

Picasso would have liked this one! Computers won't be replacing canvas and paint immediately, but nobody is placing bets on the limits of computer graphics.

This month I got carried away. I had so much fun changing and improving this program that it incorporates several hints on how to use the Atari plus another way to use the joysticks. Before digging into the program, though, let us see what it does.

Type in the program and run it. All but the bottom four lines of the screen turn black. Near the center of the black area is a white dot. Move joystick 0 and you can paint with the dot, just as if it were a brush dipped in white paint. The motion of the dot on the screen is quite slow. This is intentional. If the dot moved too fast, it would be hard to control. As your skill increases, you can speed the dot up.

Hold down the joystick button and move the joystick. Now the dot moves much faster, but it doesn't paint. It erases. You have a paint brush which moves quickly from one area of the screen to another, and yet paints slowly enough to give you complete control!

Unless you are Tom Sawyer, painting with a white brush can be quite boring. Let's change colors. As you probably know, you have three color registers available in graphics mode 7. When the program starts, you are painting with register 1 set to white. To pick another register, press either the 1, 2, or 3 key. You are now using this register. But before you can paint, you must choose a color. Type in a color number between 0, for white, and 15, for light gold. Press RETURN. Table 1 lists the 16 color possibilities. Now, as you move the joystick, you are painting with this new color.

What's Going On

The program is initialized between lines 1000 and 2030. The beginning location of the dot is position (X = 90, Y = 48); its color, C, is 0; its color register, R, is 1; and its brightness, L, is 10.

Line 1090 opens the keyboard for input. This statement is necessary if you want to read single ASCII characters from the keyboard without using the INPUT statement. The number 1 is my choice for the file number. I could have chosen anything between 1 and 5. The 4 means input, the 0 is required, and the "K:" means the input is from the keyboard.

Look at Diagram 1. The joystick returns numbers between 5 and 15 depending on its position. The actual number is used as the subscript of arrays XD and YD to determine how the X and Y positions of the dot on the screen are to be changed. For example, if the joystick is pushed away from the user and to the right, the number is 6. XD(6) is equal to 1 and YD(6) equals -1. The dot would move one position right (+ 1) and one position up (-1) on the screen. The arrays XD and YD are initialized in lines 1110 to 2030.

The main program loop starts at line 150. Look closely at line 160. This statement determines the speed of the dot on the screen. If the button on joystick zero is pushed, STRIG(0) = 0 and S will be 0. If the button isn't pressed, STRIG = 1 and S = 100. Line 170 uses the variable S as the alarm on the delay timer. Finally, lines 150 and 180 cause the dot to blink. Line 200 makes sure that if the button is pressed, then the dot erases, or leaves a black spot, when the joystick is moved.

The rest of the program loop is between lines 250 and 310. Line 250 gets the value of the joystick. This value is used to modify the X and Y positions of the dot as previously discussed. Once these values are computed, line 290 places the dot in its new location.

The statement on line 280 keeps the dot from running off the TV screen. If the PLOT statement tries to put the dot off the screen, an error results. The trap on line 280 branches the computer to the routine at line 3000. That routine adds one to Y if Y is above the screen (Y<0) or subtracts one from Y if Y is below the screen (Y>79). Likewise, it adjusts X if X is to the left (X<0) or right (X>159) of the screen. Finally, the routine jumps back to line 280 to set the trap again and plot.

The user can type in a new register number and color. Line 300 scans the keyboard each time the program loops to see if the artist is ready to change colors. If location 764 isn't equal to 255, then a key has been pressed. The routine beginning on line 4000 is called on to respond to the artist's request.

The first thing done by the keyboard routine is get the ASCII value of the key pressed. The GET statement must use the same number as the open statement on line 1090 and it puts the value of the key in the variable R. The ASCII value for a one is 49 and for a three is 51. If the key is not between these two, it is ignored and another is required. Once a proper key has been pressed, line 4020 converts it into the numbers 1, 2, or 3 and line 4030 sets plotting to that color register.

The POSITION statement does not control the location of print statements in the text window when graphics mode 1 through 8 are chosen. This is done by poking values into memory locations 656 and 657. Poking a number between 0 and 3 into location 656 will position a statement vertically on the bottom four text lines. Poking a number between 0 and 39 into location 657 will position a print statement between columns 0 and 39 horizontally on the screen. Line 4040 positions the next print statement on the third line of the text area at the bottom of the screen.

Since the print statement on line 4050 is always printed in the same location, it is necessary to erase any previous answers. This is done by including four spaces followed by four backarrows after the word COLOR. To insert a back-arrow, or any arrow, in a print statement, press the ESC key before typing the arrow key.


I would like to thank Dick Ainsworth for his idea about using two different speeds on the joystick to control different functions, and I'd also like to thank William Bailey for his idea on using arrays to simplify the conversion of joystick values into directions. If you would like to share your ideas with other readers, send them in. If I use them, you will also be acknowledged.

Al Baker, Programming Director, The Image Producers, Inc.

Table 1: The Atari Colors

  0     Gray                8    Blue
  1     Gold                9    Gray blue
  2     Orange             10    Turquoise
  3     Red                11    Olive Green
  4     Pink               12    Green
  5     Violet             13    Yellow green
  6     Purple             14    Brown
  7     Light blue         15    Light gold

Diagram 1: The Joystick Control Arrays

XD(10) = -1   XD(14) = 0   XD(6) =  1
XD(11) = -1   XD(15) = 0   XD(7) =  1
XD(9)  = -1   XD(13) = 0   XD(5) =  1
YD(10) = -1   YD(14) =-1   YD(6) = -1
YD(11) =  0   YD(15) = 0   YD(7) =  0
YD(9)  =  1   YD(13) = 1   YD(5) =  1

Listing: The Fluid Brush

Download (Saved BASIC)
Download / View (Listed BASIC)

Return to Table of Contents | Previous Section | Next Section