Cool Twister Effect with Small Basic

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!

http://smallbasic.com/program/?FKF358

All Replies

• Friday, August 24, 2012 2:19 PM

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! (^_^)

• Friday, August 24, 2012 7:21 PM

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-7GraphicsWindow.Title = "Twister"GraphicsWindow.BackgroundColor = "Black"GraphicsWindow.Width  = 640GraphicsWindow.Height = 480gw = GraphicsWindow.Width  - 1gh = GraphicsWindow.Height - 1  '{Ajusted to For condition}set     = gw/2        'Set screen offsetsize    = 180         'Set sizetwist   = 315         'Set twist amplitudedelay   = 130         'Set DelayangMax  = 45          'Set max angle angMax  = angMax - 1  '{Ajusted to For condition}ruggy   = 9           'how rugged lines areGraphicsWindow.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 rowangStep     = 360/(colorsIndex)            'angle gap for lines of each colorcolorsIndex = 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  EndForGraphicsWindow.TextInput = Pause   'Turns pause & exit keys onGraphicsWindow.MouseDown = Pause   'Same for mouse clicks'Main twister routineTwist: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 animationSub 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! (^_^)

• Saturday, August 25, 2012 2:52 AM

oh nice!  Thanks for making this better :)
• Monday, August 27, 2012 12:20 AM