Truc marrant

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

Truc marrant

Message par bombseb »

Salut,

Aujourd'hui, j'ai fait ca :

Code : Tout sélectionner

If InitSprite () = 0 Or InitKeyboard () = 0
   MessageRequester ("Erreur", "Erreur lors de l'initialisation", #PB_MessageRequester_Ok)
   End
EndIf


#WindowWidth    = 800
#WindowHeight   = 600
OpenScreen (#WindowWidth, #WindowHeight, 32, "Implosion", #PB_Screen_WaitSynchronization)

UsePNGImageDecoder()

Result = LoadSprite (1, "logopb.png")
If Result = 0
  MessageRequester ("Erreur", "Erreur à l'ouverture du logo !", #PB_MessageRequester_Ok)
  End
EndIf


Structure Px
  coul.l
  DecalX.f
  DecalY.f
  CoefX.f
  CoefY.f
EndStructure


SpriteWidth  = SpriteWidth (1)
SpriteHeight = SpriteHeight(1)

xPos    = (#WindowWidth - SpriteWidth) / 2
yPos    = (#WindowHeight - SpriteHeight) / 2
xCentre = (SpriteWidth / 2)
yCentre = (SpriteHeight/ 2)


DisplaySprite (1, 1, 1)

RandomSeed (ElapsedMilliseconds ())

Dim Pixel.Px (SpriteWidth,SpriteHeight)
If StartDrawing (ScreenOutput ())
  For x = 0 To SpriteWidth -1
    For y = 0 To SpriteHeight -1
      Pixel(x,y)\coul     = Point (x,y)
      Pixel(x,y)\DecalX   = (Sign (x - xCentre) * (1 + Random (1) / 10)) + (Random (20) - 10) / 2
      Pixel(x,y)\DecalY   = (Sign (y - yCentre) * (1 + Random (1) / 10)) + (Random (20) - 10) / 2
      If Pixel(x,y)\DecalX = 0 : Pixel(x,y)\DecalX = 1 : EndIf
      If Pixel(x,y)\DecalY = 0 : Pixel(x,y)\DecalY = 1 : EndIf
      
      Pixel (x,y)\CoefX = 1.1 + Random (10) / 50 ; (1.07 + Random (100) / 30)
      Pixel (x,y)\CoefY = 1.1 + Random (10) / 50 ; (1.07 + Random (100) / 30)
      
      For i = 1 To 100
        Pixel (x,y)\DecalX = Pixel (x, y)\DecalX * Pixel (x, y)\CoefX
        Pixel (x,y)\DecalY = Pixel (x, y)\DecalY * Pixel (x, y)\CoefY
      Next
      
    Next
  Next
  StopDrawing ()
EndIf
ClearScreen(0)

;DisplaySprite (1, xPos, yPos)

FlipBuffers ()

;Delay (500)


Repeat
  ClearScreen (0)
  
  If StartDrawing(ScreenOutput())
    
    For xSprite = 0 To SpriteWidth - 1
      For ySprite = 0 To SpriteHeight - 1
        
        If Pixel (xSprite, ySprite)\coul = 8808794 : Continue : EndIf
          
          xScreen = (xPos + xSprite) + Pixel (xSprite, ySprite)\DecalX
          yScreen = (yPos + ySprite) + Pixel (xSprite, ySprite)\DecalY
          
          If xScreen > 0 And xScreen < #WindowWidth And yScreen > 0 And yScreen < #WindowHeight
            Plot (xScreen,yScreen, Pixel (xSprite,ySprite)\coul)
          EndIf
          
          ;         Pixel (xSprite, ySprite)\DecalX = Pixel (xSprite, ySprite)\DecalX * Pixel (xSprite, ySprite)\CoefX
          ;         Pixel (xSprite, ySprite)\DecalY = Pixel (xSprite, ySprite)\DecalY * Pixel (xSprite, ySprite)\CoefY
          
          Pixel (xSprite, ySprite)\DecalX = Pixel (xSprite, ySprite)\DecalX / Pixel (xSprite, ySprite)\CoefX
          Pixel (xSprite, ySprite)\DecalY = Pixel (xSprite, ySprite)\DecalY / Pixel (xSprite, ySprite)\CoefY
        ;EndIf
        
      Next
    Next
    
  EndIf
  
  StopDrawing ()
  FlipBuffers()
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)


et l'image qui va avec :

Image

Il y a surement des optimisations à faire, mais bon j'ai un peu la flemme :oops:
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Truc marrant

Message par Kwai chang caine »

Super joli 8O
Merci 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
boddhi
Messages : 604
Inscription : lun. 26/avr./2010 16:14
Localisation : S 48° 52' 31'' / O 123° 23' 33''

Re: Truc marrant

Message par boddhi »

+1 Très sympa comme effet.

Petite question (d'un mec qui n'y connait pas grand chose en graphisme :cry: :) ) : Est-il possible d'ajouter un phénomène d'accélération progressive de la périphérie vers le centre ?
bombseb
Messages : 445
Inscription : jeu. 25/août/2005 22:59
Localisation : 974
Contact :

Re: Truc marrant

Message par bombseb »

oui c'est ce que j'ai fait... je multiplie (enfin je divise plutot) par un coefficient
plus les points se rapprochent du centre plus ils ralentissent
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Truc marrant

Message par Ar-S »

Bien bien bien :D
~~~~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
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Truc marrant

Message par Backup »

Bien cool ; ça me rappel un code de SPH , qui avait fait une truc dans le genre, il me semble

avec un effet de rebond, :)
Répondre