10 KEY OFF
20 W%=40
30 SCREEN 1:COLOR 1
50 WID%=W%-8:HGHT%=25-4
90 DIM A$(51)
91 DIM X(121),Y1(121),Y2(121),Y3(121),Y4(121),Y5(121)
99 K%=0
100 GOSUB 7000
5000 REM *** INITIALIZE PRINTER ARRAY ***
5100 FOR I%=1 TO HGHT%
5110 A$(I%)=" |"+SPACE$(120):NEXT I%
5120 A$(0)= " +"+STRING$(120,"-")
5200 REM *** FIND MIN AND MAX VALUES FOR BOTH AXIES ***
5210 XMIN=X(0):XMAX=X(0):YMIN=Y1(0):YMAX=Y1(0)
5220 FOR I%=0 TO WID%
5230 IF X(I%)=-32768! THEN GOTO 5290
5232 IF X(I%)-32768! THEN XMIN=X(I%):GOTO 5250
5234 IF X(I%)>XMAX THEN XMAX=X(I%)
5250 IF Y1(I%)=-32768! THEN PRINT "MISSING `Y' VALUE ERROR - PROGRAM TERMINATED":GOTO 9999 ELSE YCHK%=0
5252 IF Y1(I%)-32768! THEN YMIN=Y1(I%):YCHK%=1
5254 IF Y2(I%)-32768! THEN YMIN=Y2(I%):YCHK%=1
5256 IF Y3(I%)-32768! THEN YMIN=Y3(I%):YCHK%=1
5258 IF Y4(I%)-32768! THEN YMIN=Y4(I%):YCHK%=1
5260 IF Y5(I%)-32768! THEN YMIN=Y5(I%):YCHK%=1
5270 IF YCHK%=1 THEN GOTO 5281
5272 IF Y1(I%)>YMAX AND Y1(I%)<>-32768! THEN YMAX=Y1(I%)
5274 IF Y2(I%)>YMAX AND Y2(I%)<>-32768! THEN YMAX=Y2(I%)
5276 IF Y3(I%)>YMAX AND Y3(I%)<>-32768! THEN YMAX=Y3(I%)
5278 IF Y4(I%)>YMAX AND Y4(I%)<>-32768! THEN YMAX=Y4(I%)
5280 IF Y5(I%)>YMAX AND Y5(I%)<>-32768! THEN YMAX=Y5(I%)
5281 NEXT I%
5290 IF XMIN=XMAX AND YMIN=YMAX THEN PRINT "MAXIMUM AND MINIMUM VALUES FOR BOTH AXIES ARE THE SAME - PROGRAM TERMINATED":GOTO 9999
5300 REM *** FIND THE INCREMENT VALUE FOR EACH AXIS AND SCALE THE AXIES ***
5305 MAX=XMAX:MIN=XMIN:SIZ%=WID%:GOSUB 5310:XINCR=INCR:XB=BASE
5306 MAX=YMAX:MIN=YMIN:SIZ%=HGHT%:GOSUB 5310:YINCR=INCR:YB=BASE
5309 GOTO 5330
5310 REM *** SUBROUTINE TO FIND BEST INCREMENT AND BASE VALUES ***
5311 INCR=1/(SIZ%/(MAX-MIN))
5312 F=1!
5313 IF (F*INCR)<1 AND 1=CINT(-1*(32767!>(F*INCR))*(F*INCR)) THEN INCR=1/F:GOTO 5320
5314 IF (F*INCR)<.5 AND (F*INCR)>.1 THEN INCR=1/(2*F):GOTO 5320
5315 IF INCR<1 THEN F=F*10 ELSE F=F/10
5316 GOTO 5313
5320 BASE=INCR*INT(MIN/INCR):RETURN
5330 FOR I%=0 TO HGHT% STEP 10
5340 MID$(A$(I%),2,6)=RIGHT$(SPACE$(5)+STR$(CINT(I%*YINCR+YB%))+"+",6)
5350 NEXT I%
5400 XLABEL$=SPACE$(7+WID%)
5410 FOR I%=0 TO WID% STEP 10
5420 MID$(A$(0),(7+I%),1)="+"
5430 MID$(XLABEL$,(3+I%),5)=RIGHT$(SPACE$(5)+STR$(CINT(I%*XINCR+XB)),5)
5440 NEXT I%
5500 REM *** PLACE POINTS INTO PLOT ARRAY IN APPROPRIATE LOCATIONS ***
5510 FOR I%=0 TO WID%
5520 IF X(I%)=-32768! THEN GOTO 5600 ELSE XP%=7+CINT((X(I%)-XB)/XINCR)
5530 IF Y1(I%)=-32768! THEN GOTO 5600 ELSE MID$(A$(CINT((Y1(I%)-YB)/YINCR)),XP%,1)="*"
5540 IF Y2(I%)=-32768! THEN GOTO 5600 ELSE MID$(A$(CINT((Y2(I%)-YB)/YINCR)),XP%,1)="+"
5550 IF Y3(I%)=-32768! THEN GOTO 5600 ELSE MID$(A$(CINT((Y3(I%)-YB)/YINCR)),XP%,1)="O"
5560 IF Y4(I%)=-32768! THEN GOTO 5600 ELSE MID$(A$(CINT((Y4(I%)-YB)/YINCR)),XP%,1)="#"
5570 IF Y5(I%)=-32768! THEN GOTO 5600 ELSE MID$(A$(CINT((Y5(I%)-YB)/YINCR)),XP%,1)="."
5600 NEXT I%
6000 REM *** OUTPUT THE FINISHED PLOT ***
6001 IF K%<=1 THEN GOTO 6005
6002 FOR X%=1 TO 15:Y$=INKEY$:NEXT X%
6003 IF INKEY$="" THEN 6003
6005 CLS
6010 FOR I%=0 TO HGHT%
6020 PRINT LEFT$(A$(HGHT%-I%),WID%+7)
6030 NEXT I%
6040 PRINT LEFT$(XLABEL$,WID%+7)
6050 PRINT SPACE$(WID%\2)+LABL$
6999 GOTO 100
7000 REM *** LOOP THROUGH POSSIBLE CURVES FOR PLOTTING ***
7005 FOR I%=0 TO 120:X(I%)=-32768!:Y1(I%)=-32768!:Y2(I%)=-32768!:Y3(I%)=-32768!:Y4(I%)=-32768!:Y5(I%)=-32768!:NEXT I%
7010 IF K%=0 THEN 7050 ELSE IF K%=1 THEN 7060 ELSE IF K%=2 THEN 7070 ELSE IF K%=3 THEN 7100
7040 FOR X%=1 TO 15:Y$=INKEY$:NEXT X%
7041 IF INKEY$="" THEN 7041
7042 GOTO 9999
7050 FOR I%=0 TO 30:X(I%)=I%:Y1(I%)=3*I%:NEXT I%
7051 LABL$="LINEAR PLOT":K%=1:GOTO 5000
7060 FOR I%=0 TO 30:X(I%)=I%:Y1(I%)=((I%-15)/1.5)^2:NEXT I%
7061 LABL$="PARABOLIC PLOT":K%=2:GOTO 5000
7070 FOR I%=0 TO 30:X(I%)=I%:Y1(I%)=50+50*SIN(I%/2):NEXT I%
7071 LABL$="TRIGONOMETRIC PLOT":K%=3:GOTO 5000
7100 FOR I%=0 TO 30:X(I%)=I%:Y1(I%)=3*I%:Y2(I%)=((I%-15)/1.5)^2:Y3(I%)=50+50*SIN(I%/2):NEXT I%
7101 LABL$="COMBINATION PLOT":K%=999:GOTO 5000
9999 SCREEN 1,0:COLOR 1:CHAIN "A:LOGOC