0 Members and 1 Guest are viewing this topic.
rbrazCBM 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=480Const W1 = Scr_Width * 2, H1 = Scr_Height * 2Const Pi As Double = 3.1415Const KEY_ESC    = 27Dim Key$Dim Shared plasma1(Scr_Width * Scr_Height * 4) as integerDim Shared plasma2(Scr_Width * Scr_Height * 4) as integerDim Shared r(256), g(256), b(256) as integerDim Shared buffer(Scr_Width * Scr_Height) as integerDim Shared  x1, y1, x2, y2, x3, y3 as integerDim Shared dst, src1, src2, src3 as integerDim Shared i, j as doubleDim Shared CTime as doubleDeclare 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 DoublePrecalculate()If( ptc_open( "FreeBasic Plasma Example", Scr_Width, Scr_Height ) = 0 ) Then   End -1 End ifWhile 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)  Wendptc_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  NextEnd SubSub 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   NextEnd SubSub 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 SubFunction Millisecs( ByVal fltTimeValue As Double ) As Double   Return ( fltTimeValue * 1000.00 )End Function
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!)