' !!! FBSL BASIC !!!
#Option Implicit
#Include "mingfx.inc"
Dim cList[32]
For i = 0 To 15
cList[i] = RGB(255, (i * 16), 0)
cList[i + 16] = RGB(255, 240 - (i * 16), 0)
Next
Let(xc, yc, Pen, Angle, Heading) = 0
// =============================
Width = 600
Height = 600
Window(Width, Height, FALSE, "Peter's Gone West!")
Message(100, 250, 14, "Wait while MIDI loads...", 255)
Redraw()
LoadMusic("psbgw.mid")
PlayMusic()
Animate
Cycle(0, 0, 31, 1)
For y = 0 To Height * 2
v = y Mod 32
Ink = cList[v]
DrawLine(-1, Cos(y), Width, y)
DrawLine(Width, Cos(y), -1, y)
Next
Star()
Redraw()
Wait(20)
Forever
// =============================
Sub Cycle(d, i, f, b)
If d = 1 Then
t = cList[i]
For e = i To f - 1
cList[e] = cList[e + 1]
Next
If b = 1 Then cList[f] = t
Else
t = cList[f]
For e = f To i + 1 Step - 1
cList[e] = cList[e - 1]
Next
If b = 1 Then cList[i] = t
End If
End Sub
Sub Star()
Let(x, y, xc, yc) = 0
Let r = 400 * Sin(2 * Rad(Angle))
Let a = r * Sin(Rad(Angle))
Let b = r * Cos(Rad(Angle))
DrawWidth(10)
PenStop(): PenUp(): TurnEast(Angle)
Repeat 7
GoWest(a): TurnEast(-108.9)
GoWest(b): TurnEast(-108.9)
Incr(x, xc)(y, yc)
End Repeat
Advance(-x / 7, -y / 7)
PenStop(): PenDown(): TurnEast(Angle)
Repeat 7
Ink(255, 0, 0)
GoWest(a): TurnEast(-108.9)
Ink(255, 255, 0)
GoWest(b): TurnEast(-108.9)
End Repeat
Angle = Incr(Angle) Mod 360 // be nice!
DrawWidth(1)
End Sub
// =============================
// In Situ Polar Turtle Graphics
// =============================
Macro PenUp() = Poke(@Pen, FALSE)
Macro PenDown() = Poke(@Pen, TRUE)
Macro PenStop() = Poke(@Heading, 0)
Sub Advance(x, y)
If Pen Then DrawLine(Width / 2 + xc, Height / 2 - yc, Width / 2 + x, Height / 2 - y)
List(xc, yc) = {x, y}
End Sub
Sub TurnEast(degs)
Heading = Incr(Heading, degs) Mod 360 // ditto!
End Sub
Sub GoWest(dist)
Advance(xc + (dist * Sin(Rad(Heading))), yc + (dist * Cos(Rad(Heading))))
End Sub