Cool Twister Effect with Small Basic
-
Friday, August 24, 2012 5:06 AM
I've been following the demoscene for years. I wanted to contribute some Small Basic code here that uses a twister effect that is seen in many of the demos.
Though this version is not the most efficient, it does illustrate the use of SIN when to come up with some cool graphical effects. The next version I plan on prerendering the SIN data into an Array and then draw the frames from the coordinates in the array (much faster than calculating each row before drawing :) )
Let me know what you think!
All Replies
-
Friday, August 24, 2012 2:19 PMAnswerer
Hello tonyrocks!
I've liked a lot your math graph demo!
Here's a modded version using GraphicsWindow.PenWidth to draw thicker lines to fill up the void left by skipping lines due to Step 3.
Twister 1.2 -> FKF358-1 : 4 color lines
Twister 1.3 -> FKF358-2 : 8 color lines
Twister 1.5 -> FKF358-3 : using arrays
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Friday, August 24, 2012 2:20 PM
- Edited by GoToLoopEditor Friday, August 24, 2012 2:33 PM some corrections
- Edited by GoToLoopEditor Friday, August 24, 2012 3:30 PM
- Edited by GoToLoopEditor Friday, August 24, 2012 4:30 PM More versions!
-
Friday, August 24, 2012 7:21 PMAnswerer
Finally I got all calculations stored up inside a 3D array ( x[ang][y][line] ) !
Twister 2.0 -> FKF358-4
Twister 2.2 -> FKF358-7
' 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-7
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 = Pause 'Turns pause & exit keys on
GraphicsWindow.MouseDown = Pause '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<x2 Then
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 Pause
If GraphicsWindow.LastKey = "Escape" Then
Sound.PlayClickAndWait()
Program.End()
ElseIf isPaused Then
isPaused = "False"
Else
isPaused = "True"
EndIf
EndSub
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Friday, August 24, 2012 7:21 PM
- Edited by GoToLoopEditor Friday, August 24, 2012 7:22 PM
- Edited by GoToLoopEditor Monday, August 27, 2012 12:15 AM New corrected version
- Edited by GoToLoopEditor Monday, August 27, 2012 12:32 AM Newest version
- Edited by GoToLoopEditor Wednesday, October 10, 2012 9:38 PM
- Edited by GoToLoopEditor Wednesday, October 10, 2012 9:41 PM
- Edited by GoToLoopEditor Thursday, October 11, 2012 6:53 PM
-
Saturday, August 25, 2012 2:52 AMoh nice! Thanks for making this better :)
-
Monday, August 27, 2012 12:20 AMAnswerer
There were some bugs I had to iron out!
Small Basic version -> FKF358-7
I've just started learning a Java/JS-based language called Processing. As an exercise, I've converted Twister 2.1 to it!
Processing version -> Twister
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Monday, August 27, 2012 12:36 AM
- Edited by GoToLoopEditor Monday, August 27, 2012 12:37 AM
- Edited by GoToLoopEditor Friday, August 31, 2012 10:59 PM
- Edited by GoToLoopEditor Wednesday, October 10, 2012 4:10 PM Update
- Edited by GoToLoopEditor Wednesday, October 10, 2012 9:32 PM
- Edited by GoToLoopEditor Wednesday, October 10, 2012 9:41 PM
- Edited by GoToLoopEditor Thursday, October 11, 2012 6:53 PM

