Plasma

Programmation d'applications complexes
bombseb
Messages : 445
Inscription : jeu. 25/août/2005 22:59
Localisation : 974
Contact :

Plasma

Message par bombseb »

Aller, aujourd'hui je me lâche...
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 ()
Avatar de l’utilisateur
MLD
Messages : 1097
Inscription : jeu. 05/févr./2009 17:58
Localisation : Bretagne

Re: Plasma

Message par MLD »

Super. Merci du partage
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Plasma

Message par Kwai chang caine »

Waoooouuuh !!! :D
Image
Merci du partage 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
Ar-S
Messages : 9472
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Plasma

Message par Ar-S »

Salut Bombseb,
content de te revoir :)

Joli plasma, l'ajout d'un DisableDebugger en début de code est tout de même vivement conseillé sinon ça rame (testé en 5.62x64) même avec ma config portée par un i5 et une 1080;)
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Répondre