Here's a little Code Snippet of a Plasma which I learnt from Shockwaves BB Tutorials. With a few additions for a FB TinyPTC adaption from yours truely, with routines I developed whilst learning FreeBasic. And may prove useful to you in your demo coding quests.
Enjoy and Hope it helps.
'-------------------------------------
' Plasma Effect
' By Clyde Radcliffe May 2006.
' Adaption And Modifications from
' Shockwaves Fast Plasma BB Tutorial
' http://www.dbfinteractive.com/plasmatutorial.htm
'---------------------------------------------------
Option Static
Option Explicit
'-------------------------------------
' Includes.
'-------------------------------------
#Include Once "Tinyptc.bi"
'-------------------------------------
' Constants.
'-------------------------------------
Const XRES=320
Const YRES=240
Const PI = 3.141593
Const ARES=XRES*YRES
Const KEY_ESC=27
Const KEY_TAB= 9
'-------------------------------------
' Know what I mean 'Arry.
'-------------------------------------
Dim Shared ScreenBuffer( ARES-1 ) As Integer
Dim Shared RGBScreen( XRES, YRES )
Dim Shared PlasmaPal(1024)
Dim Shared sintable(2880) As Single
Dim Shared costable(2880) As Single
'-------------------------------------
' Meet the Globals.
'-------------------------------------
Dim Shared PlasmaAdd1, PlasmaDir1
Dim Shared PlasmaAdd2, PlasmaDir2
Dim Shared RunningTime As Double
Dim Shared PlasmaTimer As Double
Dim Shared PlasmaDuration
'-------------------------------------
' Sub / Function Initializing.
'-------------------------------------
Declare Sub CreatePal( ByVal RedInc As UByte=1, ByVal GrnInc As UByte=2, ByVal BluInc As Ubyte=3,_
            ByVal RedDec As Ubyte=3, ByVal GrnDec As Ubyte=2, ByVal BluDec As Ubyte=1 )
Declare Sub FeedPixels( Buffer(), Byval x As Integer, Byval y As Integer, Byval col As Integer)
Declare Sub InitializePlasma()
Declare Sub RunPlasma()
Declare Sub UpdatePlasma()
Declare Function Millisecs( Byval TimeVal As Double ) As Double
'-------------------------------------
' Running Order.
'-------------------------------------
InitializePlasma()
RunPlasma()
End
Sub CreatePal( ByVal RedInc As UByte=1, ByVal GrnInc As UByte=2, ByVal BluInc As Ubyte=3,_
        ByVal RedDec As Ubyte=3, ByVal GrnDec As Ubyte=2, ByVal BluDec As Ubyte=1 )
 Â
  Dim A, Red, Grn, Blu
  Dim RedDir, GrnDir, BluDir
Â
  For A=1 To 1024
   Â
    If RedDir=0 And A>512 Then
   Â
      Red=Red+RedInc
     Â
      If Red>255 Then
        Red   = 255
        RedDir = 1
      End If
     Â
    End If
    If GrnDir=0 Then 'And A>512 Then
     Â
      Grn=Grn+GrnInc
     Â
      If Grn>255 Then
        Grn   = 255
        GrnDir = 1
      End If
   Â
    End IF
    If BluDir=0 Then
     Â
      Blu=Blu+BluInc
     Â
      If Blu>255 Then
        Blu   = 255
        BluDir = 1
      End If
   Â
    End If
   Â
   Â
    If RedDir=1 Then
     Â
      Red=Red-RedDec
     Â
      If Red<0 Then
        Red   = 0
        RedDir = 0
      End If
   Â
    End If
    If GrnDir=1 Then
     Â
      Grn=Grn-GrnDec
     Â
      If Grn<0 Then
        Grn   = 0
        GrnDir = 0
      End If
     Â
    End If
   Â
    If BluDir=1 Then
     Â
      Blu=Blu-BluDec
     Â
      If Blu<0 Then
        Blu   = 0
        BluDir = 0
      End If
   Â
    End If
    '
    ' Calculate colour and store.
    '
    PlasmaPal(A)=( Red Shl 16) Or ( Grn Shl 8) Or ( Blu Shl 0 )
  Next
 Â
End Sub
Sub FeedPixels( Buffer(), Byval x As Integer, Byval y As Integer, Byval col As Integer)
   Â
    If x>0 and x<XRES-1 and y>0 and y<YRES-1 then
   Â
      Buffer(y * XRES + x) = col
   Â
    End If
   Â
End Sub
Sub InitializePlasma()
 Â
  '
  ' Setup Screen.
  '
  If( ptc_open( "Cool Plasma V1", XRES, YRES ) = 0 ) Then
End -1Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
End if
 Â
  Randomize Timer()
 Â
  Dim a
  For a=1 To 2880
    sintable(a) = Sin((a * PI/180))
    costable(a) = Cos((a * PI/180))
  Next
 Â
  CreatePal( Int(Rnd*5)+1, Int(Rnd*5)+1, Int(Rnd*5)+1,_
        Int(Rnd*5)+1, Int(Rnd*5)+1, Int(Rnd*5)+1 )
 Â
  PlasmaDir1= Int(Rnd*5)+2
  PlasmaDir2= Int(Rnd*5)+2
 Â
End Sub
Sub RunPlasma()
 Â
  Dim Key As String
 Â
  PlasmaTimer   = Millisecs( Timer() )
  PlasmaDuration = 4000
 Â
  While Key<>Chr(KEY_ESC)
   Â
    RunningTime = Timer()
   Â
    UpdatePlasma()
   Â
    Ptc_Update @ScreenBuffer(0)
   Â
    If Key=Chr(KEY_TAB) Then
     Â
      CreatePal( Int(Rnd*5)+1, Int(Rnd*5)+1, Int(Rnd*5)+1,_
            Int(Rnd*5)+1, Int(Rnd*5)+1, Int(Rnd*5)+1 )
     Â
    End If
   Â
   Â
    If (PlasmaTimer + PlasmaDuration) <=Millisecs( RunningTime ) then
       Â
        PlasmaTimer = Millisecs( RunningTime )
       Â
        CreatePal( Int(Rnd*5)+1, Int(Rnd*5)+1, Int(Rnd*5)+1,_
              Int(Rnd*5)+1, Int(Rnd*5)+1, Int(Rnd*5)+1 )
       Â
        PlasmaDir1=Int(Rnd*5)+2
        PlasmaDir2=Int(Rnd*5)+2
       Â
    End If
   Â
    Key=Inkey()
  Wend
 Â
End Sub
Sub UpdatePlasma()
 Â
  Dim x,y
  Dim cv1,cv2,ca1,ca2                  ' Used in calculations.
 Â
  PlasmaAdd1=PlasmaAdd1+PlasmaDir1           ' These additions are
  PlasmaAdd2=PlasmaAdd2+PlasmaDir2           ' For different speeds X+Y.
  If PlasmaAdd1>360 Then PlasmaAdd1=PlasmaAdd1-360
  If PlasmaAdd2>360 Then PlasmaAdd2=PlasmaAdd2-360
  ca1 = 50+49*costable( PlasmaAdd1 )          ' You can play with these vars.
  ca2 = 50+49*sintable( PlasmaAdd2 )          ' Strange things may happen though.
  '
  ' Calculate the plasma and store it, it's stored in case
  ' you want to do any pixel wise effects in the same screen
  ' array so it only needs to be drawn once.
  '
  For y = 1 To YRES - 1
   Â
    cv1 = 205+Int(ca1*sintable( PlasmaAdd2+y ))
   Â
    For x = 1 To XRES - 1
     Â
      cv2 = 400+Int(ca2*costable( PlasmaAdd1+x ))
     Â
      RGBScreen(x,y) = cv1+cv2
 Â
    Next
 Â
  Next
  '-------------------------------------------------
  ' Feed Pixels To ScreenBuffer()
  '-------------------------------------------------
  For y = 1 To YRES - 1
    For x = 1 To XRES - 1
      FeedPixels( ScreenBuffer(), x, y, PlasmaPal( RGBScreen( x, y )))
    Next
  Next
End Sub
Function Millisecs( ByVal TimeVal As Double ) As Double
 Â
  Return ( TimeVal * 1000.00 )
   Â
End Function
Cheers and all ze best,
Clyde.