Nahrada SCALE (Function Plotting Subroutine)
- Type
- Graphics
- Category
- Graphing utility subroutine
- Author
- Boris Letocha junior
- Published in
- Flop (Czech disk magazine for 8-bit Atari), issue 8 (1990)
- Year
- 1990
- Language
- Atari BASIC (also runs under Turbo BASIC XL)
- Requirements
- Any 8-bit Atari with Atari BASIC; 16K or more
About the program
Some BASICs of the era had a SCALE statement that let you plot in your own coordinate system. Atari BASIC has none, and this 44-line program is a náhrada, a "substitute", for it. It was written by Boris Letocha junior, who contributed several programs to the Czech disk magazine Flop, and appeared in Flop 8 in 1990. You set four variables, P/R (X minimum/maximum) and S/T (Y minimum/maximum), compute X and Y in "real" units, and call GOSUB 3000. The subroutine converts them to screen coordinates X1, Y1, sets up GRAPHICS 8 and draws the axes on the first call, and keeps everything inside the screen.
The Czech REMs
| REM | Meaning |
|---|---|
| NASTAVENI PARAMETRU | setting the parameters |
| INICIALIZACE | initialisation |
| KONTROLA | check (clipping) |
| OSY SOURADNICOVEHO SYSTEMU | axes of the coordinate system |
P=Xmin R=Xmax S=Ymin T=Ymax |
the four range variables |
Typing it in
Plain ASCII, nothing special. Although it is often filed as a Turbo BASIC XL program, it uses only standard Atari BASIC statements and runs under either.
How to use it
The demo (lines 10–90) plots Y=COS(X) for X from 0 to 22/7, a handy approximation of π, in steps of 0.2 radians, joining the points with DRAWTO. To plot your own function, keep lines 3000–3440 and write a loop like the demo:
20 P=-5:R=5:S=-2:T=10:GOSUB 3000
30 FOR X=-5 TO 5 STEP 0.1:Y=X*X/3
40 GOSUB 3000:IF X=-5 THEN PLOT X1,Y1
50 DRAWTO X1,Y1:NEXT X
(The first call to GOSUB 3000 opens the graphics screen and draws the axes, using the J7 flag.)
How it works
- 3100/3200: work out the scale factors (
DDX= 319/(R−P),DDY= 159/(T−S)) and the screen position of the origin (POX,POY). There are separate cases for ranges that straddle zero, lie entirely on one side of it, or start or end exactly at zero. - 3020–3030: map a point and flip Y, because screen rows grow downwards:
Y1=R2-(POY+Y*DDY). - 3300: clips the point to the 320×160 drawing area. It also gives a short beep on voice 0 or 1 whenever a point had to be clipped, a nice audible warning that your range is too small.
- 3400: draws the X and Y axes through the origin.
Listing
10 REM NAHRADA SCALE
20 P=0:R=22/7:S=-1:T=1:GOSUB 3000
25 REM P=Xmin R=Xmax S=Ymin T=Ymax
30 RAD
40 FOR X=0 TO 22/7 STEP 1/5:Y=COS(X)
50 GOSUB 3000
60 IF X=0 THEN PLOT X1,Y1
70 DRAWTO X1,Y1
80 NEXT X
90 END
3000 REM SCALE P,R,S,T
3010 IF J7=0 THEN GOSUB 3040
3020 X1=POX+X*DDX
3030 Y1=R2-(POY+Y*DDY):GOSUB 3300:RETURN
3040 REM NASTAVENI PARAMETRU
3050 GRAPHICS 8:SETCOLOR 2,0,0:COLOR 5:J7=111
3060 GOSUB 3100:GOSUB 3200:GOSUB 3400:RETURN
3100 REM INICIALIZACE
3110 R1=319:R2=159:DDX=R1/(R-P)
3120 IF P*R<0 THEN GOTO 3160
3130 IF P*R>0 THEN GOTO 3170
3140 IF P*R=0 AND P=0 THEN POX=0:RETURN
3150 IF P*R=0 AND R=0 THEN POX=R1:RETURN
3160 POX=R1*ABS(P)/(ABS(P)+ABS(R)):RETURN
3170 POX=P*(-DDX):RETURN
3200 REM INICIALIZACE
3210 DDY=R2/(T-S)
3220 IF T*S<0 THEN GOTO 3260
3230 IF T*S>0 THEN GOTO 3270
3240 IF T*S=0 AND S=0 THEN POY=0:RETURN
3250 IF T*S=0 AND T=0 THEN POY=R2:RETURN
3260 POY=R2*ABS(S)/(ABS(S)+ABS(T)):RETURN
3270 POY=S*(-DDY):RETURN
3300 REM KONTROLA
3310 IF X1<0 THEN X1=0:T1=50:SOUND 0,T1,10,6
3320 IF X1>=R1-0.5 THEN X1=R1-1:T1=50:SOUND 0,T1,10,6
3330 IF Y1<0 THEN Y1=0:T2=100:SOUND 1,T2,10,6
3340 IF Y1>=R2-0.5 THEN Y1=R2-1:T2=100:SOUND 1,T2,10,6
3350 SOUND 0,0,0,0:SOUND 1,0,0,0:RETURN
3400 REM OSY SOURADNICOVEHO SYSTEMU
3410 X=P:Y=0:GOSUB 3020:PLOT X1,Y1
3420 X=R:Y=0:GOSUB 3020:DRAWTO X1,Y1
3430 X=0:Y=T:GOSUB 3020:PLOT X1,Y1
3440 X=0:Y=S:GOSUB 3020:DRAWTO X1,Y1:RETURN
Credits
- Program listing: Nahrada SCALE (Function Plotting Subroutine) — program listing (Flop (Czech disk magazine for 8-bit Atari), issue 8 (1990)) — Boris Letocha junior
- Picture: The demo: cos(x) from 0 to 22/7, scaled to fill the hi-res screen. — Boris Letocha junior (program); screenshot by the site
- Gury's Atari 8-bit Forever — Nahrada Scale — Boris Letocha junior
