Fast Atari Circles
Owen Sexsmith
Draw circles, stars, diamonds, and other geometric shapes in Atari BASIC quickly and easily, all with a single subroutine written in machine language. For the Atari 400/800, XL, and XE computers.
Unlike some newer versions of the language, Atari BASIC has no CIRCLE statement, so drawing circles can be a slow and cumbersome process. But with "Fast Atari Circles," you can easily draw circles, ellipses, stars, and a galaxy of other shapes. The routine is written in machine language for maximum speed, but you don't need to understand ML to use the routine in your own programs.
Type in and save Fast Atari Circles. When you run it, you'll see a pattern of finely drawn, elliptical lines. After that, the program generates colored disks, open stars, hexagons, diamonds, and other complex shapes in various graphics modes.
Believe it or not, all these shapes were created with just one routine. As you can see from the program, GOSUB 900 is used whenever graphics are generated. Line 900 consists of a single USR statement (which calls the machine language subroutine), followed by RETURN. The USR statement includes several descriptively named variables, such as XCENTER and YRADIUS. To create a shape, you simply assign values to these BASIC variables, then call the Fast Circles routine with USR.
Defining The Variables
XCENTER and YCENTER locate your shape on the screen. XCENTER defines the X coordinate, or horizontal location. Give XCENTER a small value to put the shape near the left of the screen, and larger values to move it to the right. YCENTER defines the Y coordinate, or vertical location. Smaller YCENTER values put the shape higher on the screen, and larger values move it down. XRADIUS and YRADIUS define the shape's width and height, respectively.
To learn how these four variables interact, look at lines 165–220. In line 165, XCENTER and YCENTER are given values that place the shape in the middle of the screen. In lines 205–220, a FOR-NEXT loop increases the values of XRADIUS and YRADIUS each time the loop is executed. Since XRADIUS is always greater than YRADIUS, the shape is wider than it is high, forming an ellipse. In lines 225–240, the process is repeated, giving YRADIUS greater values than XRADIUS, so the ellipse is higher than it is wide.
By changing the STEP values in lines 205 and 225, you can change the distance between the lines. For example, try STEP 3 instead of STEP 5 in line 205, and STEP 1 instead of STEP 5 in line 225. You'll see an interesting moiré effect in areas where the two shapes overlap. If you'd like to experiment further, add these two lines:
201 XRADIUS=96: YRADIUS=96: GOSUB 900 202 GOTO 202
When you run the program again, it draws one shape and pauses in an endless loop at line 202. Since XRADIUS and YRADIUS are equal, the shape is a circle (some TV sets and monitors may be mildly distorted, making the circles look slightly elliptical).
Press BREAK to stop, and edit line 175 so that DELTA = 32. When the program runs, you should see an octagon. When DELTA = 64, it becomes a diamond. If you change DELTA to an odd value such as 81, the program draws a complex series of lines that eventually overlap to form a thick doughnut shape. When you're done experimenting with this section, delete lines 201 and 202.
A small example of some shapes you can draw with "Fast Atari Circles."Using The Routine
The demonstration program contains REMarks explaining what each section does. By studying the program and experimenting with other sections, you can quickly learn how to handle all the variables used by the Atari Fast Circles routine.
To use this routine in your own programs, you'll need to include lines 50–60, 70, 900, and 1000–1135. Lines 50–60 create a table of sine values in SINE$. Line 70 builds the machine language routine in CIRCS. Line 900 contains the line-drawing USR call, and lines 1000–1135 are the machine language data. Put the lines that create CIRCS and SINES in the setup portion of your program. Once the setup is complete, you're ready to create your own graphics masterpieces.
Fast Atari Circles
Please refer to "COMPUTE!'s Guide to Typing In Programs" before entering this listing.
PL 10 GRAPHICS 2+16:POSITION 5,4:? #6;"PLEASE WAIT":? #6:? #6;" {7 SPACES}loading" EI 40 REM HM 42 REM BUILD A SINE TABLE IN SINE$ EN 45 REM HM 50 DEG : DIM SINE$ (65): FOR I= 0 TO 64:X=INT(256*S IN(90/64*I)+0.5) IL 55 IF X>255 THEN X=255 FI 60 SINE$ < (I + 1 )=CHR* (X) :NEXT I EP 65 REM EA 66 REM PUT M.L. ROUTINE IN CIRC$ FB 67 REM PG 70 DIM CIRC$(280):FOR I = 1 TO 280:READ X:CIRC$(I)= CHR$(X):NEXT I HK 150 REM OA 155 REM ELLIPSES HL 160 REM IJ 165 XCENTER=160:YCENTER=96 LN 170 ARCSTART=0:ARCEND=0 KF 175 KOLOR=1:DELTA=2 KN 200 GRAPHICS 8+16 LE 205 FOR I=0 TO 75 STEP 5 DG 210 XRADIUS=5+2*I : YRADIUS = 5+I LB 215 GOSUB 900 BK 220 NEXT I LD 225 FOR I=1 TO 45 STEP 5 DI 230 XRADIUS=5+I : YRADIUS=5 + 2*I LD 235 GOSUB 900 BO 240 NEXT I DB 245 FOR I=1 TO 300:NEXT I HL 250 REM PO 255 REM DISKS HM 260 REM PI 265 KOLOR=1:DELTA=1:GRAPHICS 7+16 LH 270 FOR I=6 TO 27 STEP 3 OJ 275 XCENTER=10 + 4*I : YCENTER=10+2*I CE 280 FOR J=0 TO I IH 285 XRADIUS=J: YRADIUS=J: ARCEND= NOT J LE 290 GOSUB 900 CJ 295 NEXT J BP 300 KOLOR=KOLOR + 1 : IF KOLOR>3 THEN KOLOR=1 CA 305 NEXT I HI 310 REM KB 315 REM SQUARES HJ 320 REM PL 325 GRAPHICS 3+16:DELTA=64 FL 330 REM SIXTY-FOUR IS A QUARTER ARC EH 335 XCENTER=20: YCENTER=12 MD 337 FOR K=0 TO 1 : ARCSTART =32*K:ARCEND=32*K NC 340 FOR I=0 TO 5:KOLOR=KOLOR+1:IF KOLOR>3 THEN KOLOR=1 AO 345 FOR J=0 TO 1 MB 350 XRADIUS=2* I+J : YRADIUS =2*I+J LC 360 GOSUB 900 KJ 370 NEXT J:NEXT I:NEXT K DF 375 FOR I=1 TO 300:NEXT I HP 380 REM PD 385 REM VARIOUS OTHER SHAPES IA 390 REM LI 400 GRAPHICS 7+16:KOLOR = 0 :DIM S(4) ,E (4) , I(4) IP 405 S(1)=0: E(1)=0: I(1)=64 :S(2)=193:E(2)=191:I(2)=102 MG 410 S(3)=16:E(3)=16:I(3)=32:S(4)=0:E (4)=0:I(4)= 1 EN 420 XRADIUS=10: YRADIUS=10 CM 430 FOR I=0 TO 3:S=4-I:FOR J=0 TO 3 CE 440 KOLOR=KOLOR + 1 : IF KOLOR>3 THEN KOLOR=1 FS 450 S=S+1: IF S>4 THEN S=1 EJ 460 XCENTER=20+40*J:YCENTER=12 + 20*I AO 470 ARCSTART = S(S) : ARCEND = E(S):DELTA=I(S) LF 480 GOSUB 900 DI 490 NEXT J: NEXT I DI 495 FOR I=1 TO 300:NEXT I GD 500 GOTO 500 ED 900 X=USR (ADR (CIRC$) , ADR (SINE$), XCENTER, YCENTER, XRADIUS, YRADIUS, ARCSTART, ARCEND,256*KOLOR+DELTA):RETURN EF 1000 DATA 104, 104, 133, 231, 104, 133, 230, 104, 133, 217 FJ 1005 DATA 104, 133, 216, 104, 133, 228, 133, 229, 104, 133 EK 1010 DATA 218, 104, 104, 133, 219, 104, 104, 133, 220, 104 EI 1015 DATA 104, 133, 221, 104, 104, 133, 222, 104, 141, 251 JB 1020 DATA 2, 104, 133, 223, 162, 0, 134, 227, 165, 227 OB 1025 DATA 56, 233, 64, 133, 227, 165, 221, 56, 229, 227 CP 1030 DATA 133, 224, 144, 240, 165, 227, 41, 128, 133, 225 FE 1035 DATA 165, 227, 41, 64, 240, 7, 169, 64, 56, 229 PK 1040 DATA 224, 133, 224, 165, 227, 240, 6, 201, 192, 240 AG 1045 DATA 2, 162, 128, 134, 226, 164, 224, 177, 230, 133 PH 1050 DATA 214, 165, 220, 133, 215, 169, 0, 133, 212, 162 CN 1055 DATA 8, 70, 214, 144, 3, 24, 101, 215, 106, 102 NA 1060 DATA 212, 202, 208, 243, 166, 225, 240, 5, 73, 255 DP 1065 DATA 24, 103, 1, 24, 101, 218, 133, 84, 169, 64 EH 1070 DATA 56, 229, 224, 168, 177, 230, 133, 214, 165, 219 DL 1075 DATA 133, 215, 169, 0, 133, 212, 162, 8, 208, 2 JG 1080 DATA 208, 138, 70, 214, 144, 3, 24, 101, 215, 106 GC 1085 DATA 102, 212, 202, 208, 243, 133, 227, 166, 226, 240 OJ 1090 DATA 16, 165, 216, 56, 229, 227, 133, 85, 165, 217 EA 1095 DATA 233, 0, 133, 86, 24, 144, 13, 165, 216, 24 JK 1100 DATA 101, 227, 133, 85, 165, 217, 105, 0, 133, 86 OC 1105 DATA 166, 228, 208, 40, 162, 96, 134, 228, 169, 11 LF 1110 DATA 157, 66, 3, 169, 0, 157, 72, 3, 157, 73 BK 1115 DATA 3, 173, 251, 2, 32, 86, 228, 169, 17, 157 LE 1120 DATA 66, 3, 169, 12, 157, 74, 3, 169, 0, 157 PB 1125 DATA 75, 3, 240, 9, 162, 96, 32, 86, 228, 166 PF 1130 DATA 229, 208, 16, 165, 221, 24, 101, 223, 133, 221 EF 1135 DATA 197, 222, 208, 142, 202, 134, 229, 208, 137, 96