Cool Twister Effect with Small Basic RRS feed

  • General discussion

  • 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!


    Friday, August 24, 2012 5:06 AM

All replies

  • 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 4:30 PM More versions!
    Friday, August 24, 2012 2:19 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

    ' 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
        x[ang][y][line] = x[ang][y][0] 'Extra redundant line = 1st line

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

    'Main twister routine

    For ang=0 To angMax
      While isPaused
        Program.Delay(150)             'Resume/Halt execution by key presses
      GraphicsWindow.Title = "Twister    •••    Angle = " + ang
      Program.Delay(delay)             'Delay before clearing the screen:
      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)
          x1 = x2                      'Now 1st coordinate = last used 2nd coordinate

    'Do it again!:
    Goto Twist

    'Pause animation
    Sub Pause
      If GraphicsWindow.LastKey = "Escape" Then
      ElseIf isPaused Then
        isPaused = "False"
        isPaused = "True"

    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
  • oh nice!  Thanks for making this better :)
    Saturday, August 25, 2012 2:52 AM
  • 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! (^_^)

    Monday, August 27, 2012 12:20 AM