Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: Rbz on May 04, 2006
-
*** From DBF ezboard ***
rbraz
CBM 128
Posts: 172
(17/4/06 2:26)
Reply
 Plasma Effect
--------------------------------------------------------------------------------
It looks alot better than the B+ version Â
Enjoy!
'-------------------------------------
' FreeBasic Plasma - 640x480
' Â Â Â Â by Rbraz - 2006
'-------------------------------------
'Windowed
'#define PTC_WIN
'-------------------------------------
' Includes.
'-------------------------------------
#Include Once "tinyptc.bi"
Const Scr_Width=640, Scr_Height=480
Const W1 = Scr_Width * 2, H1 = Scr_Height * 2
Const Pi As Double = 3.1415
Const KEY_ESC Â Â Â = 27
Dim Key$
Dim Shared plasma1(Scr_Width * Scr_Height * 4) as integer
Dim Shared plasma2(Scr_Width * Scr_Height * 4) as integer
Dim Shared r(256), g(256), b(256) as integer
Dim Shared buffer(Scr_Width * Scr_Height) as integer
Dim Shared  x1, y1, x2, y2, x3, y3 as integer
Dim Shared dst, src1, src2, src3 as integer
Dim Shared i, j as double
Dim Shared CTime as double
Declare Sub Precalculate()
Declare Sub Update_Buffer()
Declare Sub WritePixelFast( Byval intX As Integer, Byval intY As Integer, Byval intC As Integer )
Declare Function Millisecs( ByVal fltTimeValue As Double ) As Double
Precalculate()
If( ptc_open( "FreeBasic Plasma Example", Scr_Width, Scr_Height ) = 0 ) Then
  End -1
End if
While Key$ <> Chr$( KEY_ESC )
Â
 Key$=Inkey$()
 Â
 CTime = millisecs( Timer ) shr 2
 For i=0 To 255
 r(i) = ((128 + 127 * cos( i * PI / 128 + CTime/37 )) ) and 255
 g(i) = ((128 + 127 * sin( i * PI / 128 + CTime/35 )) ) and 255
 b(i) = ((128 - 127 * cos( i * PI / 128 + CTime/41 )) ) and 255
 Next
 x1 = 160 + (159 * Cos( (CTime/412 )))
 x2 = 160 + (159 * Sin( (-CTime/580)))
 x3 = 160 + (159 * Sin( (-CTime/601)))
 y1 = 100 + (99  * Sin( (CTime/470 )))
 y2 = 100 + (99  * Cos( (-CTime/590)))
 y3 = 100 + (99  * Cos( (-CTime/645)))
 src1 = (y1 * (Scr_Width*2)) + x1
 src2 = (y2 * (Scr_Width*2)) + x2
 src3 = (y3 * (Scr_Width*2)) + x3
 dst = 0
 For j=0 To Scr_Height-1
  For i=0 To Scr_Width-1
   buffer(dst) = (plasma1(src1) + plasma2(src2) + plasma2(src3)) And 255
   dst = dst + 1
   src1 = src1 + 1
   src2 = src2 + 1
   src3 = src3 + 1
  Next
   src1 = src1 + Scr_Width
   src2 = src2 + Scr_Width
   src3 = src3 + Scr_Width
 Next
 Update_Buffer()
 Ptc_Update @buffer(0)
Â
Wend
ptc_close()
Sub Update_Buffer()
 Dim pixel,x,y as integer
 For y = 0 To Scr_Height-1
 For x = 0 To Scr_Width-1
   pixel = buffer(x + (y * Scr_Width))
   WritePixelFast ( x, y, (r(pixel) Shl 16) Or (g(pixel) Shl 8 )  Or b(pixel) )
 Next
 Next
End Sub
Sub Precalculate()
  For j=0 To H1-1
    For i=0 To W1-1
     plasma1(dst) =  ((Sin(((i*2+j*2)*Pi/180))*15 + Sin((j*Pi)/180)*90)) And 255
     plasma2(dst) =  ((Sin(((i+j)*Pi)/180)*25 + Cos((i*Pi)/180)*90)) And 255
     dst = dst + 1
    Next
  Next
End Sub
Sub WritePixelFast( Byval intX As Integer, Byval intY As Integer, Byval intC As Integer )
  If ( intX>0 And intX<Scr_Width-1 ) And ( intY>0 And intY<Scr_Height-1 ) Then
    buffer( intX + (intY * Scr_Width) ) = intC
  End If Â
End Sub
Function Millisecs( ByVal fltTimeValue As Double ) As Double
  Return ( fltTimeValue * 1000.00 )
End FunctionEdited by: rbraz at: 17/4/06 2:28
5H0CKW4VE
*Administrator*
Posts: 8001
(17/4/06 11:03)
Reply
ezSupporter
 Re: Plasma Effect
--------------------------------------------------------------------------------
Nice plasma pattern Rbraz. Â
--------------------------------------------------------------------------------
¤´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·`¤... SHOCKWAVE / DBF...¤
VISIT DARK BIT FACTORY INTERACTIVE! (please!)
-
Nice one Rbraz and thanks for sharing a neat plasma with nice and vibrant colours.
Cool and Cheers,
Clyde.