Polar Plotter II

Type
Graphics
Category
Mathematical graphing — polar equations
Author
Dave Bader
Published in
ANALOG Computing No. 56 (July/August 1987); GIA Software version (1988) via Atari Zpravodaj Olomouc and the Czech disk magazine Flop, issue 5
Year
1987
Language
Atari BASIC (with a machine-language text routine)
Requirements
Any 8-bit Atari with Atari BASIC; 16K or more
An eight-petalled rose curve drawn in dark lines on a pink GRAPHICS 8 screen

About the program

Polar equations, which give the radius r as a function of the angle θ, produce roses, cardioids, spirals and lemniscates, some of the prettiest curves in mathematics. Dave Bader's Polar Plotter II lets you type up to four of them, in ordinary BASIC syntax, and draws them on a GRAPHICS 8 screen. Afterwards it can label the plot with your formulas and add reference circles. The REMs credit "(c) 1987 by Dave Bader, ANALOG Computing No.56, july/august 1987". They also say that GIA Software prepared this version in 1988 "for all ATARI XL/XE" and greet Atari Zpravodaj Olomouc, the Atari club newsletter from the Czech city of Olomouc. The program was reissued on the disk magazine Flop 5.

Typing it in

  • The REM banner (lines 10–30) and the label box in lines 820 and 850 use the line-drawing characters CTRL-Q, CTRL-R, CTRL-E, CTRL-Z and CTRL-C. In line 820 they're typed with inverse video on ({inverse}…{/inverse}).
  • {CLEAR} is ESC then SHIFT-CLEAR.
  • Keep lines 200–230 exactly as they are. They are placeholders that the program overwrites with your formulas.
  • Line 140 shows 0.8300000000000001. That's a PC conversion artefact, so type 0.83 (it squashes Y to correct the pixel aspect ratio).
  • The 168 DATA values in lines 1000–1060 are a machine-language routine that draws text on the hi-res screen. Check them carefully.

How to use it

  1. Enter how many formulas you want (1–4).
  2. For each one, type the right-hand side as a BASIC expression in D (θ in radians), starting with R=. For example: R=SIN(4*D) (an eight-petal rose), R=1+COS(D) (a cardioid) or R=D/3 (a spiral).
  3. Choose 1 for automatic scaling or 2 to enter the plot's absolute limit yourself.
  4. When the beep sounds, the plot is finished. Press START once to label it with the formulas and axes. Press START again to add circles at ¾, ½ and ¼ of the limit, with their radii printed. Press ESC to go back and enter new formulas.

How it works

  • Writing formulas into the program (lines 570–600): each formula is extended with :RETURN, printed on a cleared screen with line number 200, 210, 220 or 230 in front of it and CONT underneath, and then the program stops with POKE 842,13. This is the screen editor's forced-read mode. The editor "presses RETURN" over each screen line, so your formula becomes a real program line and CONT resumes the run. POKE 559,0 blanks the display meanwhile so you don't see it happen.
  • Plotting (lines 110–170): GOSUB 190+T*10 calls formula T for θ from 0 to 6.3 in steps of 0.075. Each point is converted to X/Y with COS and SIN and drawn with DRAWTO, and the pen is lifted whenever r runs outside the limit.
  • The circles trick (line 660): the reference circles reuse the same plotting loop. "Formulas" 52–54 are lines 710–730, which return constant radii, and the FOR Q loop is entered by jumping into line 120.
  • Labels (line 840): USR(ADR(Z$),X,Y,ADR(Q$),LEN(Q$)) calls the machine-language routine stored in Z$, which copies character shapes from the font into screen memory at a text-cell position.

Listing

10 REM {CTRL-Q}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-E}
20 REM | POLAR PLOTTER II |
30 REM {CTRL-Z}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-C}
40 REM for all ATARI XL/XE
50 REM (c) 1987 by Dave Bader
60 REM ANALOG Computing No.56
70 REM july/august 1987
80 REM (p) 1988 by GIA Software
90 REM Atari Zpravodaj Olomouc!
100 GOTO 500
110 XM=96/Z:FOR Q=1 TO NUM:T=Q
120 B=0:FOR D=0 TO 6.3 STEP 0.075:GOSUB 190+T*10
130 IF ABS(R)>Z THEN B=0:GOTO 170
140 R=R*XM:X=COS(D)*R:Y=SIN(D)*R*0.8300000000000001
150 IF B=0 THEN PLOT X+208,191-(80+Y):B=1
160 DRAWTO X+208,191-(80+Y)
170 NEXT D:NEXT Q:GOTO 400
200 REM Formula entered during RUN
210 REM Formula entered during RUN
220 REM Formula entered during RUN
230 REM Formula entered during RUN
300 ?:? "AUTO SCALING...":Z=0:FOR T=1 TO NUM:FOR D=0 TO 6.3 STEP 0.075:GOSUB 190+T*10:IF R>Z THEN Z=R
310 NEXT D:NEXT T:GOTO 640
400 SOUND 0,100,10,10:FOR T=1 TO 100:NEXT T:SOUND 0,0,0,0:POKE 764,255
410 T=PEEK(53279):IF T=6 THEN BD=BD+1:GOTO 650
420 REM for LOAD/SAVE routine
430 REM for HardCopy routine
440 IF PEEK(764)<>28 THEN 410
450 BD=0:GOTO 530
500 RAD:DIM Q$(49),W$(49),E$(49),R$(49),T$(49),Z$(169):GRAPHICS 24
510 DM=PEEK(88)+PEEK(89)*256:DM=DM+40*191
520 RESTORE 1000:FOR T=1 TO 168:READ Q:Z$(LEN(Z$)+1)=CHR$(Q):NEXT T
530 GRAPHICS 0:POKE 82,0:POKE 710,144:POKE 709,12:POSITION 0,0:? "{inverse}     DAVE BADER'S POLAR PLOTTER II      {/inverse}"
540 ? "NUMBER OF FORMULA'S TO ENTER";:INPUT NUM:IF NUM>4 THEN 530
550 FOR T=1 TO NUM
560 ?:? "{CLEAR}{inverse} FORMULA ENTRY SCREEN: {/inverse}":?:? "INPUT FORMULA AS R=IN TERMS OF 'D', WHERE 'D'=THETA"
570 ? "FORMULA # ";T:INPUT Q$
580 GOSUB 900+T*10:POKE 559,0:Q$(LEN(Q$)+1)=":RETURN":? "{CLEAR}":POSITION 0,6:? 190+T*10;Q$:?:? "CONT":POSITION 0,0
590 POKE 842,13:STOP
600 POKE 842,12:POKE 559,34:NEXT T
610 ?:? "{CLEAR}PLEASE CHOOSE |1] AUTOMATIC SCALING (ABS. BOUNDS) |2] MANUAL SETTING.":INPUT T:IF T=1 THEN 630
620 ?:? "ABSOLUTE ENDPOINTS";:INPUT Z
630 IF T=1 THEN GOSUB 300
640 GRAPHICS 24:POKE 710,58:POKE 712,58:POKE 709,0:COLOR 1:GOTO 110
650 IF BD=1 THEN GOSUB 800:TRAP 400:T=51:GOTO 120
660 IF BD=2 THEN PLOT 275,55:DRAWTO 141,167:PLOT 141,55:DRAWTO 275,167:GOSUB 860:FOR Q=1 TO 3:T=51+Q:GOTO 120
670 GOTO 400
700 R=Z:RETURN
710 R=3*(Z/4):RETURN
720 R=Z/2:RETURN
730 R=Z/4:RETURN
800 FOR T=1 TO NUM:GOSUB 940+T*10:IF LEN(Q$)>39 THEN Q$=Q$(1,39)
810 X=0:Y=(T-1):GOSUB 840:NEXT T:PLOT 112,111:DRAWTO 302,111:PLOT 208,32:DRAWTO 208,190
820 X=3:Y=6:Q$="{inverse}{CTRL-Q}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-E}{/inverse}":GOSUB 840:Y=7:Q$="{inverse}|ATARI|{/inverse}":GOSUB 840:Y=8:Q$="{inverse}{CTRL-Z}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-C}{/inverse}":GOSUB 840
830 X=0:Y=10:Q$="ABS.ENDPOINTS:":GOSUB 840:Q$=STR$(Z):X=(14-LEN(Q$))/2:Y=11:GOSUB 840:RETURN
840 Q=USR(ADR(Z$),X,Y,ADR(Q$),LEN(Q$)):RETURN
850 Q$="{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}":GOSUB 840:RETURN
860 X=0:Y=12:GOSUB 850:Y=13:Q$="RADII CIRCLES":GOSUB 840:Y=14:GOSUB 850
870 Q$=STR$(3*Z/4):Y=15:X=(14-LEN(Q$))/2:GOSUB 840:X=0:Y=16:GOSUB 850
880 Q$=STR$(Z/2):Y=17:X=(14-LEN(Q$))/2:GOSUB 840:X=0:Y=18:GOSUB 850
890 Q$=STR$(Z/4):Y=19:X=(14-LEN(Q$))/2:GOSUB 840:X=0:Y=20:GOSUB 850
900 RETURN
910 W$=Q$:RETURN
920 E$=Q$:RETURN
930 R$=Q$:RETURN
940 T$=Q$:RETURN
950 Q$=W$:RETURN
960 Q$=E$:RETURN
970 Q$=R$:RETURN
980 Q$=T$:RETURN
990 STOP
1000 DATA 104,201,4,240,9,170,240,5,104,104,202,208,251,96,104,133,215,104,133,214,104,104,168,104,133
1010 DATA 217,104,133,216,104,104,240,236,133,212,24,165,214,101,88,133,214,165,89,101,215,133,215,152,240,15
1020 DATA 165,214,105,64,133,214,165,215,105,1,133,215,136,208,241,132,221,160,0,132,220,177,216,160,0,170
1030 DATA 16,1,136,132,213,138,41,96,208,4,169,64,16,14,201,32,208,4,169,0,16,6,201,64,208,2
1040 DATA 169,32,133,218,138,41,31,5,218,133,218,169,0,162,3,6,218,42,202,208,250,109,244,2,133,219
1050 DATA 164,221,177,218,69,213,164,220,145,214,200,132,220,196,212,208,182,24,165,214,105,40,133,214,144,2
1060 DATA 230,215,230,221,169,8,197,221,208,159,96,207,96

Credits