Drawing a Spiral in GFA BASIC on the Atari ST
BASIC on the Atari ST
Welcome back to the Goto 10 Free Friday post! This post is significant because it is the 100th post! In not quite a year, I’ve published regularly enough to hit 100 a bit earlier than expected. In these busy times, really appreciate you taking the time to read Goto 10.
Of course, if you’re a free subscriber you’ve only seen about half of the Goto 10 posts (and are missing out on perks). If you’d like even more Goto 10 content, with extra posts on Mondays, please consider becoming a paid subscriber. Thanks for reading!
Last year I showed how to draw a spiral in Atari BASIC, but I thought it would be neat to compare that to what the Atari ST could do with GFA BASIC.
This is the original Atari BASIC code:
10 GRAPHICS 15+16
50 PLOT X,Y-R
80 FOR A=0 TO SPIRALS*TWOPI STEP 0.01
110 DRAWTO NX,NY
130 IF LASTNX<X AND NX>X THEN C=C+1:IF C>3 THEN C=1
140 COLOR C
160 NEXT A
180 DUR=(TIME2-TIME1)/60/60:REM MINUTES
190 GOTO 190
I used GFA BASIC 3.6 since that is the latest version available for the ST. The general concept will be the same in that we want to use trigonometry to draw a shrinking circle.
The Atari ST’s low-resolution mode is 320x200 in 16 colors, so this should look much better than the 8-bit version which ran in 160x92 with 4 colors.
It ought to be much faster as well!
Here is the GFA BASIC converted code:
c=1 x=160 y=100 r=100 PLOT x,y-r twopi=3.14*2 spirals=11 FOR a=0 TO spirals*twopi STEP 0.01 nx=x+r*SIN(a) ny=y-r*COS(a) DRAW TO nx,ny r=r-0.01 IF lastnx<x AND nx>x THEN c=c+1 ENDIF COLOR c lastnx=nx NEXT a
The first thing to notice is that GFA BASIC does not use line numbers and its code is (automatically) indented.
I’m torn on line numbers. On the one hand, they totally scream BASIC! when you see them. On the other hand, they are really there because full-screen text editors were not a thing when BASIC was originally designed and also not a thing on the early low-memory personal computers. You needed the line numbers to indicate what bit of code you were editing. Plus, it worked well with GOTO.
But once computers had full-screen text editors, using a line-based editor is a royal pain.
Without line numbers you can still use GOTO by adding a label (usually text followed by a color, so “START:” for example.
Of course once more and more structure commands got added to BASIC, the need for GOTO mostly disappeared.
The math stuff is exactly the same. The drawing code is quite similar actually, with just DRAWTO becoming two words.
The above code took about 35 seconds to run on my 1040ST, which is a vast improvement over the 8-bit which took 21(!) minutes in Atari BASIC. Plus it does look better, as expected:
Update: A ready has informed me that the above GFA BASIC program also works unchanged on GFA BASIC for the Amiga.
Thanks for reading! Be sure to sign up for the FREE email newsletter to get new posts sent directly to your Inbox!