Microsoft Small Basic

Program Listing: FKF358-6
' Twister (v2.2)
' date @ 2012/Aug
' program by tonyrocks
' modded by GoToLoop

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

' FKF358-6

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

GraphicsWindow.Width = 640
GraphicsWindow.Height = 480
gw = GraphicsWindow.Width - 1
gh = GraphicsWindow.Height - 1 '{Ajusted to For condition}

set = gw/2 'Set screen offset
size = 180 'Set size
twist = 315 'Set twist amplitude
delay = 130 'Set Delay

angMax = 45 'Set max angle
angMax = angMax - 1 '{Ajusted to For condition}

ruggy = 9 'how rugged lines are
GraphicsWindow.PenWidth = ruggy + 1

'Set color to each line:
colors = "0=Maroon;1=DarkRed;2=Red;3=SkyBlue;4=DodgerBlue;5=Blue;6=Navy;7=Indigo;"
colorsIndex = Array.GetItemCount(colors) '# of colors = # of lines to draw at each row
angStep = 360/(colorsIndex) 'angle gap for lines of each color
colorsIndex = colorsIndex - 1 '{Ajusted to For condition}

'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 ruggy 'Row loop
calc = y/amp + ang 'Pre-calc

For line=0 To colorsIndex 'Coordinates to draw each line
x[ang][y][line] = Math.Round( Math.Sin(calc + angStep*line) * size ) + set
EndFor

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

EndFor

GraphicsWindow.TextInput = KeyPressed 'Turns pause & exit keys on
GraphicsWindow.MouseDown = MousePressed 'Same for mouse clicks

'Main twister routine
Twist:

For ang=0 To angMax

While isPaused
Program.Delay(150) 'Resume/Halt execution by key presses
EndWhile

GraphicsWindow.Title = "Twister --- Angle = " + ang

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

For y=0 To gh Step ruggy
xx = x[ang][y] 'Create a 1D sub-array outta 3D x[ang][y][line]
x1 = xx[0] '1st horizontal coordinate

For line=0 To colorsIndex
x2 = xx[line+1] 'Destination horizontal coordinate

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

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

EndFor

'Do it again!:
Goto Twist

'Pause animation
Sub KeyPressed

If GraphicsWindow.LastKey = "Escape" Then
Sound.PlayClickAndWait()
Program.End()
ElseIf isPaused Then
isPaused = "False"
Else
isPaused = "True"
EndIf

EndSub

Sub MousePressed

KeyPressed()

EndSub