Archimedes Spiral in BASIC
It's the famous "hat" image!
I’ve reviewing some of my ANALOG Computing magazines, starting with Issue 1 and have come up with a few things that I’ll be highlighting here. On of those things is a short BASIC program to display an Archimedes Spiral from ANALOG Computing Issue 7.
In the his column, Non-Tutorial VI, Charles Bachand includes this program to demonstrate both Atari graphics and then later how you might print it out.
This is the program:
The program takes a long time to run. According to the article, just under 3 hours! I typed it in and ran it on my 800XL and it definitely took a long time. Here is the finished image:
Running it on OSS BASIC XE in FAST mode was much faster, indeed. When I’m not using actual hardware, my emulator of choice is Atari 800MacX. When I let the emulator use the full speed of my Mac along with BASIC XE in FAST mode, it was drawing very quickly, finishing in about 15 minutes.
Turbo BASIC XL seemed even faster than BASIC XE.
If I also turn off the ANTIC screen updates (POKE 559,0 at start; POKE 559,34 at end), it finishes even quicker, about 10 minutes.
Since this BASIC program is both short and easily translated to other languages, I thought I would quickly throw together versions for Xojo and Python.
Here is the Xojo version
, which runs in about 1 second or less:// Archimedes Spiral
// Converted from Atari BASIC
// ANALOG Computing, Issue 7
// Non-Tutorial VI by Charles Bachand
g.DrawingColor = Color.White
g.FillRectangle(0, 0, g.Width, g.Height)
Const kSize = 144
Var xp As Integer = kSize
Var xr As Double = 4.71238905
Var xf As Double = xr / xp
For zi As Integer = -64 To 64
Var zt As Double = zi * 2.25
Var zs As Double = zt * zt
Var xl As Double = Round(Sqrt(kSize * kSize - zs) + 0.5)
For xi As Integer = 0 - xl To xl
Var xt As Double = Sqrt(xi * xi + zs) * xf
Var yy As Double = (Sin(xt) + Sin(xt * 3) * 0.4) * 56
Var x1 As Double = xi + zi + 160
Var y1 As Double = 90 - yy + zi
g.DrawingColor = Color.Black
g.DrawLine(x1, y1, x1, y1)
If Not TransparentCheck.Value Then
g.DrawingColor = Color.White
g.DrawLine(x1, y1 + 1, x1, 191)
End If
Next
Next
Download the the Xojo project: ArchimedesSpiral
Here is the Python version, which also finishes in about a second:
#!/usr/bin/env python3
from graphics import *
import math
win = GraphWin(width = 320, height = 200, autoflush=False)
win.setBackground("white")
kSize = 144
xp = kSize
xr = 4.71238905
xf = xr / xp
for zi in range(-64, 64):
zt = zi * 2.25
zs = zt * zt
xl = round(math.sqrt(kSize * kSize - zs) + 0.5)
for xi in range(0-xl, xl):
xt = math.sqrt(xi * xi + zs) * xf
yy = (math.sin(xt) + math.sin(xt * 3) * 0.4) * 56
x1 = xi + zi + 160
y1 = 90 - yy + zi
win.plot(x1, y1, "black")
aLine = Line(Point(x1, y1 + 1), Point(x1, 191))
aLine.setFill("white")
aLine.draw(win)
update()
win.getMouse() # pause before closing
I work for Xojo, so will likely often use it when showing sample code.
https://www.youtube.com/watch?v=M-BnxWd8yhA
ported to my PC_PIC board :)
I typed this program in a ran it on my Atari 400 back in the day. I did the first run the day that the Superman movie with Christopher Reeves debuted on TV. So I was running back and forth to check progress on every commercial break. At the end of the movie I ran in to be greeted by a blank screen because I had forgotten line 260.
I use the program as a speed test on all variety of period computers and languages. I don't really bother with running it on modern computers or with optimizing the program because it doesn't tell me anything about relative speeds of period computers or languages to do either.