Microsoft Small Basic

Program Listing: FKF358-4
' Twister (v2.0)
' program by tonyrocks
' modded by GoToLoop

' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
'/thread/abc69be0-b2a9-4bb2-b5aa-c652f4258308

' FKF358-4

GraphicsWindow.Title = "Twister"
GraphicsWindow.BackgroundColor = "Black"

GraphicsWindow.Width = 640
GraphicsWindow.Height = 480
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height

set = gw/2 'Set screen offset
size = 180 'Set size
twist = 10 'Set twist
angMax = 90 'Set max angle
delay = 120 'Set Delay

sharp = 8 'Set For y's Step
GraphicsWindow.PenWidth = sharp + 1

'Set color to each line:
colors = "0=DarkRed;1=Red;2=Tomato;3=Cyan;4=DodgerBlue;5=Blue;6=Navy;7=DarkRed;"
colorsIndex = Array.GetItemCount(colors) - 2 '# of colors = # of lines to draw at each row
angStep = 360/(colorsIndex + 2) 'Set angle step diff. for all lines

'Store all calcs in array x[ang][y][line]:
For ang=0 To angMax 'Angle loop
amp = Math.Sin(ang)*gh + twist 'Set the amplitude and change it based on gh & ang

For y=0 To gh Step sharp 'Row loop
calc = y/amp + ang 'Pre-calc

For line=0 To colorsIndex - 1 'Line loop
x[ang][y][line] = Math.Sin(calc + angStep*line)*size + set 'Set coordinates to draw each line
EndFor

x[ang][y][line] = x[ang][y][0] 'Last line = 1st line
EndFor

EndFor

'Main twister routine
Twist:

For ang=0 To angMax
For y=0 To gh Step sharp
xx = x[ang][y] 'Creates a 1D sub-array outta x[ang][y]
x1 = xx[0] '1st coordinate
For line=0 To colorsIndex
x2 = xx[line+1]

If x1 GraphicsWindow.PenColor = colors[line]
GraphicsWindow.DrawLine(x1,y x2,y)
EndIf

x1 = x2 'Now 1st coordinate = last used 2nd coordinate
EndFor
EndFor

'Delay before clearing the screen:
Program.Delay(delay)
GraphicsWindow.Clear()
EndFor

'Do it again!:
Goto Twist