10 PRINT "PLOT OF POLAR EQUATION"
20 PRINT
28 REM - COORDINATE ARRAYS SET FOR 90 POINTS;
30 DIM X(91),Y(90)
39 REM - NUMBER OF POINTS TO BE CALCULATED
40 N=90
49 REM - ABSOLUTE VALUE OF ALL ENDPOINTS ARE EQUAL
50 PRINT "ABSOLUTE VALUE OF ENDPOINT";
60 INPUT Z
70 PRINT
79 REM - CALCULATE INCREMENTS OF AXES ACCORDING TO CHARACTERS PER AXIS
84 PRINT "INCREMENT OF X-AXIS =";Z/30
90 PRINT "INCREMENT OF Y-AXIS =";Z/18
100 PRINT
110 FOR I=1 TO N
119 REM - CONVERT DEGREES TO RADIANS
120 D=.06981317*I
130 REM - ENTER FUNCTION HERE (F="FUNCTION")
135 F=2*(1-COS(D))
138 REM - CALCULATE EACH CARTESIAN COORDINATE, ROUND OFF TO NEAREST
139 REM - INCREMENT ON AXIS
140 X(I)=INT(((F*COS(D)/Z+1)*30)+.5)
150 Y(I)=INT(((-F*SIN(D)/Z+1)*18)+.5)
160 NEXT I
169 REM - SORT COORDINATES; REORDER Y(n) SMALLEST OT LARGEST
170 FOR J=1 TO N
180 FOR I=1 TO N-J
190 A=X(I)
200 B=Y(I)
210 IF B<=Y(I+1) THEN 260
220 X(I)=X(I+1)
230 Y(I)=Y(I+1)
240 X(I+1)=A
250 Y(I+1)=B
260 NEXT I
270 NEXT J
279 REM - NEXT POINT TO BE PLOTTED STORED IN T
280 T=1
289 REM - SKIP POINTS OUT OF Y-POSITIVE RANGE
290 FOR P=0 TO N-1
300 IF Y(P+1)>=0 THEN 320
310 NEXT P
319 REM - LOOP TO CALL UP EACH Y-INCREMENT FOR LINES OF PRINT
320 FOR I=0 TO 36
330 T=T+P
339 REM - NUMBER OF POINTS TO BE PLOTTED ON EACH LINE STORED INP
340 P=0
349 REM - ALL POINTS PLOTTED?
350 IF T>N THEN 370
359 REM - Y-VALUE ON Y-LINE?
360 IF Y(T)=I THEN 420
369 REM - PRINT X-AXIS?
370 IF I=18 THEN 400
379 REM - PRINT Y-AXIS
380 PRINT TAB(30);"*";
390 GOTO 860
400 S=N+1
410 GOTO 740
420 FOR L=T TO N
429 REM - NEXT POINT TO BE PLOTTED ON SAME LINE?
430 IF Y(L)>Y(T) THEN 460
440 P=P+1
450 NEXT L
460 IF P=1 THEN 560
468 REM - LOOP TO SORT X-COORDINATES WITH EQUAL Y-COORDINATES;
469 REM - REORDER SMALLEST TO LARGEST
470 FOR J=1 TO P
480 FOR L=1 TO P-J
490 C=X(T+L-1)
500 A=X(T+L)
510 IF C<=A THEN 540
520 X(T+L-1)=A
530 X(T+L)=C
540 NEXT L
545 FOR J=1 TO P
550 NEXT J
559 REM - PRINT X-AXIS?
560 IF I=18 THEN 730
570 L=-1
580 S=0
590 FOR K=0 TO P-1
599 REM - MORE THAN ONE POINT TO BE POTTED AT SAME POINT ON GRAPH?
600 IF X(T+K)=L THEN 690
610 L=X(T+K)
619 REM - PLOT POINT ON Y-AXIS?
620 IF L=30 THEN 660
629 REM - PLOT POINT TO THE LEFT OF Y-AXIS?
630 IF L<30 THEN 670
640 IF S=1 THEN 670
649 REM - PRINT Y-AXIS
650 PRINT TAB(30);"+";
660 S=1
669 REM - POINT OUTSIDE OF POSITIVE X-RANGE?
670 IF L>60 THEN 860
679 REM - PLOT POINT
680 PRINT TAB(L);"+";
690 NEXT K
700 IF S=1 THEN 860
709 REM - PRINT Y-AXIS
710 PRINT TAB(30);"*";
720 GOTO 860
730 S=T
739 REM - LOOP TO PRINT LINE OF X-AXIS
740 FOR J=0 TO 60
750 IF X(S)<>J THEN 830
759 REM - PLOT POINT ON X-AXIS
760 PRINT "+";
770 FOR K=S TO T+P-1
780 IF X(K)=X(S) THEN 810
790 S=K
800 GOTO 840
810 NEXT K
820 GOTO 840 
829 REM - PRINT X-AXIS
830 PRINT "*";
840 NEXT J
849 REM - LABEL X-AXIS
850 PRINT "X";
860 PRINT
870 NEXT I
879 REM - LABEL Y-AXIS
880 PRINT TAB(30);"y"
890 END
