Une version optimisée du plasma que j'avais fait il y a longtemps
Le sinus est précalculé dans une table...
Code : Tout sélectionner
InitSprite() : InitKeyboard()
#ScrWidth = 800
#ScrHeight = 600
#BPPx = 4
OpenScreen(#ScrWidth, #ScrHeight,#BPPx * 8,"")
Structure px
bleu.b
vert.b
rouge.b
alpha.b
EndStructure
Procedure PrintFPS()
Static sek, FPS, FPS$
If Val (FormatDate ("%ss", Date ())) = sek
FPS + 1
Else
FPS$ = Str (FPS)
FPS = 0
EndIf
sek=Val (FormatDate ("%ss", Date ()))
DrawText (0,0, FPS$ + " fps")
EndProcedure
Procedure Plasma ()
; ------ Definition de la palette --------------
Dim mapal.px(255)
For i = 0 To 255
angle.f = (i * (2 * #PI ) / 255)
mapal(i)\rouge = Abs (Cos (angle + (2 * #PI) / 3) * 255)
mapal(i)\vert = Abs (Cos (angle + #PI / 2) * 255)
mapal(i)\bleu = Abs (Cos (angle) * 255)
Next
; ----------------------------------------------
; ------ Precalc sinus ------
nbSin = 1024
Dim sintab.u(nbSin)
For i = 0 To nbSin - 1
sintab(i) = Sin (i * (2 * #PI) / 1024) * 32767 + 32767
Next
; ---------------------
ClearScreen(0)
Repeat
ExamineKeyboard()
If StartDrawing(ScreenOutput())
*BufferVideo.px = DrawingBuffer()
TailleBufferX = DrawingBufferPitch()
angle3 + 20
angle2 + 30
angle1 + 40
For y = 0 To #ScrHeight - 1
*b2.px = *BufferVideo + TailleBufferX * y
a2 = ((y + angle2) >> 8) + sintab ((angle2 + y ) % nbSin) >> 8
col2 = sintab (a2 % nbSin)
tmp = sintab ((angle3 + y) % nbSin) >> 8
For x = 0 To #ScrWidth - 1
*b2 + #BPPx
a1 = ((x + angle1) >> 8) + sintab ((angle1 + x) % nbSin) >> 8
col1 = sintab (a1 % nbSin)
a3 = (((x + y) << 5 + angle3) >> 5) + tmp
col3 = sintab (a3 % nbSin)
col = (col1 + col2 + col3) >> 10
;*b2\alpha = 255
*b2\rouge = mapal(col)\rouge
*b2\vert = mapal(col)\vert
*b2\bleu = mapal(col)\bleu
Next
Next
PrintFPS()
StopDrawing()
EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
Plasma ()