Page 1 sur 1

[DEMO 2D] PIXEL 2 LOGO

Publié : dim. 26/avr./2020 11:21
par Ar-S
Bonjour à tous.
Je suis en train de m'amuser à faire des effets de pseudo morphing avec des pixels.
Le principe. Stocker les PIXELS blancs du logo dans une liste, randomiser leur apparition sur l'ecran puis les faire revenir à leur état initial.
Pour les effets verticaux/horizontaux pas de prob, mais pour faire un effets type distance A vers B via pythagore, ça passe du random au logo d'un coup. J'ai du me planter quelque part.
J'ai utilisé la proce Distance de Falsam mais j'ai du me queuter (je vois plus grand chose avec toutes ces coords :) )

En gros vous pouvez modifier IlikeToMoveItMoveIt(1) en allant de 1 à 4 (ligne 75)
Le soucis vient de l'effet 4

Merci pour votre aide.

Code : Tout sélectionner

; ===============================================================
;
; PIXELS 2 LOGO FX by Ar-S
; 
; ===============================================================


UseLZMAPacker()
UsePNGImageDecoder()
InitSprite()



*Buffer = AllocateMemory(2587)
If *Buffer
  UncompressMemory(?ldvmlogo, 2209, *Buffer, 2587, #PB_PackerPlugin_Lzma)
  Global logo = CatchImage(#PB_Any, *Buffer, 2587)
  FreeMemory(*Buffer)
Else
  Debug "erreur image"
EndIf


Global Speed.f = 10
Global Lwin = 800, Hwin = 600


Declare CatchPixels(img, color)
Declare IlikeToMoveItMoveIt(FX)
Declare.d Distance(ORIx,DESTx,ORIy,DESTy)


; Structure des coordonnées
Structure SP
  Xori.d
  Yori.d
  Xrnd.d
  Yrnd.d
EndStructure

; Liste chainée pour stoquer les coords d'un sprite N fois
Global NewList sprite.sp()




If OpenWindow(0, 0, 0, Lwin, Hwin, " ", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0),0,0,Lwin,Hwin)
  
  CreateSprite(1,1,1)
  StartDrawing(SpriteOutput(1))
  Box(0,0,1,1,$FFFFFF)
  StopDrawing()
  
  CatchPixels(Logo, $FFFFFF)
  
  ; Vitesse d'affichage (IPS)
  SetFrameRate(20)

  Repeat
    Repeat
      Event = WindowEvent()
      
      Select Event
          
        Case #PB_Event_CloseWindow
          End 
           
      EndSelect
      
    Until event=0
    
    ; 2D
    ;- MODIFIER LES EFFETS ICI : De 1 à 4
    IlikeToMoveItMoveIt(1) ;<-------- --- 
    
    FlipBuffers()
    ClearScreen(0)

    Delay(1)
    
  ForEver
  
  
  
EndIf




Procedure CatchPixels(img, Color)
  Shared iW, iY
  Protected PoX, PoY
  
  
  ; Taille de l'image
iW = ImageWidth(img)
iY = ImageHeight(img)

  
;Stockage des données des pixels blancs
StartDrawing(ImageOutput(img))

; Points d'origines X et Y pour centrer le dessin
PoX = (ScreenWidth()/2) - (iW/2)
PoY = (ScreenHeight()/2) - (iY/2)

For y = 0 To iY-1
  For x = 0 To iW-1
    
    If Point (x,y) = Color

    AddElement (sprite())
    sprite()\Xori = X+PoX
    sprite()\Yori = Y+PoY
    sprite()\Xrnd = Random(ScreenWidth()-1)
    sprite()\Yrnd = Random(ScreenHeight()-1)

  EndIf

  Next x
Next y      

StopDrawing()
FreeImage(Logo)

EndProcedure


; FX movements
Procedure IlikeToMoveItMoveIt(FX)

    ForEach Sprite()
      DisplaySprite (1, Sprite()\Xrnd , Sprite()\Yrnd )
      
      
      Select FX
          
          Case 1 ; Diag
      
      If Sprite()\Xrnd > Sprite()\Xori Or Sprite()\Yrnd > Sprite()\Yori
        Sprite()\Xrnd - speed
        If Sprite()\Xrnd <= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf
        
        Sprite()\Yrnd  - speed
        If Sprite()\Yrnd <= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf
        
      
      ElseIf  Sprite()\Xrnd < Sprite()\Xori Or Sprite()\Yrnd < Sprite()\Yori
        Sprite()\Xrnd  + speed
        If Sprite()\Xrnd >= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf
        
        Sprite()\Yrnd  + speed
        If Sprite()\Yrnd >= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf
        
      EndIf
      
    Case 2 ; H & V
      
       If Sprite()\Xrnd > Sprite()\Xori 
        Sprite()\Xrnd - speed
        If Sprite()\Xrnd <= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf
        
      ElseIf Sprite()\Yrnd > Sprite()\Yori
        Sprite()\Yrnd  - speed
        If Sprite()\Yrnd <= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf

      ElseIf  Sprite()\Xrnd < Sprite()\Xori 
        Sprite()\Xrnd  + speed
        If Sprite()\Xrnd >= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf

      ElseIf Sprite()\Yrnd < Sprite()\Yori
        Sprite()\Yrnd  + speed
        If Sprite()\Yrnd >= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf
        
      EndIf
      
    Case 3 ; H & V Electric
        
       If Sprite()\Xrnd > Sprite()\Xori Or Sprite()\Yrnd > Sprite()\Yori
        Sprite()\Xrnd - Random( speed+5,5)
        If Sprite()\Xrnd <= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf
        
        Sprite()\Yrnd  - Random( speed+5,5)
        If Sprite()\Yrnd <= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf
        
      
      ElseIf  Sprite()\Xrnd < Sprite()\Xori Or Sprite()\Yrnd < Sprite()\Yori
        Sprite()\Xrnd  + Random( speed+5,5)
        If Sprite()\Xrnd >= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf
        
        Sprite()\Yrnd  + Random( speed+5,5)
        If Sprite()\Yrnd >= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf
        
      EndIf
      DisplaySprite (1, Sprite()\Xrnd-Random(20,5)+Random(20,5) , Sprite()\Yrnd-Random(20,5)+Random(20,5) )
      
      
      ;- SOUCIS ICI
    Case 4

      Distance.f = Distance(Sprite()\Xori,Sprite()\Xrnd,Sprite()\Yori,Sprite()\Yrnd)

     T.f = Sqr(Distance) / Speed
      
      Sprite()\Xrnd = (Sprite()\Xrnd - Sprite()\Xori) / T;
      Sprite()\Yrnd = (Sprite()\Yrnd - Sprite()\Yori) / T;
      
       If Sprite()\Xrnd <= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf

        If Sprite()\Yrnd <= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf
        
         If Sprite()\Xrnd >= Sprite()\Xori
          Sprite()\Xrnd = Sprite()\Xori
        EndIf
        
        If Sprite()\Yrnd >= Sprite()\Yori
          Sprite()\Yrnd = Sprite()\Yori
        EndIf

  EndSelect

    Next    
EndProcedure



; Thks to Falsam (and Pythagore :) )
Procedure.d Distance(ORIx,DESTx,ORIy,DESTy)
  Protected Distance.d, dx.d, dy.d
 
  dx = ORIx - DESTx   
  dy = ORIy - DESTy

  Distance = Sqr(dx*dx + dy*dy )
 
  ProcedureReturn Distance
EndProcedure




DataSection
  ldvmlogo:
  Data.q $944400040000005D,$89EEF7F6277AC405,$1BCCAAB38890508E,$0B479037DF2CDA2E,$23D86D6CAE02BE41,$4451EA65BB83AE31,
         $5D414C7BA1970709,$D384FBFE084F3390,$308718F11EA1022F,$61B42D4BE0E77962,$A0E216E4A43CEF4B,$E5CFF97C92E6BAAC,
         $3CA928311DC3135C,$1AE0EFCD8D60E5E2,$D13CC0B7681F128A,$AB5845389399AAC8,$C131E00B12D3AD95,$B83B301C492AD083,
         $DC169A5E307CBDD4,$469927ADCEDDCC13,$2AC0253AB2CED826,$CCB30A8F88219D8A,$0E676F3D98AA53D2,$BC0774049BDED9B3,
         $AA7C0BB687EF6459,$30A785E9D1AAD811,$1AA24D423F41B0E4,$836F6E9D3F84F6DC,$1FF70CF82E20084B,$1AFFB5DD1483F702,
         $531A8358430A8B13,$F308FD741CD8DF6C,$D91D833D2A139B98,$745D9BD91BEB3209,$1F8B61E932DBD72B,$E1527BD2E5AF6653,
         $8D8A4D2F1B677F18,$FAFA8C0D4EA34590,$CA8F2B403C7B8E9E,$FA9D158CD0C52717,$CDBA6552179C09B5,$2D562712AAF46E9C,
         $E77B2DC0DBE2F71F,$6A7B2400AD88148B,$F2300B3265E858CA,$54EE008144236987,$9D85C292F648ECBE,$5D86D4F2D67057A3,
         $E42B5F7015BED5A6,$CC176F415502C552,$BE2B065AF1A1BA41,$EEEBCC4474A8ED1D,$902471879A200868,$6C9122604D45B7AD,
         $ACE0555DFC45785F,$B607CF6C076720C1,$0143702C493B93EF,$A92B0BB358309FB5,$ECD9B280EE5FBCFE,$97042E049A872200,
         $FC79CFD73BFFCEEA,$00F88693F9F3DE35,$45147CA044BC2835,$21E162634093F74D,$D025A76C6BCA4C2D,$8B82099434BCBB32,
         $6E17ADE7B81A2E9A,$EEC40C27A93AACDE,$C72C38C427367FBC,$47416EB8CA5D4696,$4875ACDB2CC15089,$DF25A93536917D8B,
         $821CFC69078CAC05,$36EA4C92FA82D2AA,$339A98F85CB4BAC6,$5B8603586B0B9424,$D7C9C70F29129445,$3714AA1CDE380213,
         $CEAAFE9FDEDB99A4,$625AE37815EA4B4A,$3816C594370F124A,$EF680F1B7E5A4193,$AA6390E77B322BBB,$5F1C2EFA0C3AD154,
         $1F6F5A967227D9B7,$3F5505AAEBFA9286,$6943EA807BC462A2,$092D1B9FE218C1D5,$D6D8D8F7E5A815E9,$58130FCDD6D0451A,
         $EF386683B526B6B3,$55C6ADB84470A09A,$26988D96BAEC23F1,$ABE2CDB1FF08D2C9,$44DD40810B57E80F,$480772DD6AAA5D87,
         $4E4CB7DF9E9136DA,$487C931E90F5277E,$AC385B7BF944FBAD,$53DDD884B407C9E3,$6FE5010B3A3CCF07,$75080A1DAAC8F5E7,
         $F27EACFF4BEA97B4,$73668A4176724428,$EDF716829B2C9267,$EA3FE503B1FC0CA9,$140C0D94D5E8A756,$EB33BFFB921975E0,
         $992C5CC7B428FD1B,$D9D6AAC69CBFA59E,$505DB419DC12D595,$FDA042AD7FAC0496,$44118DA1AB17FABD,$7148615CC70B4AEA,
         $A91878C3AE8D0BB0,$B0158B4A862CA364,$BED9E9205F248331,$75807582B1D4B3BD,$A69F4551731C4F47,$FE6134B756C79293,
         $1C3F1A1828E04A68,$C605F21784DCC737,$B91BB116CED7CE1B,$AAB7FFC0E21012A2,$607ADB6BE8E2A343,$2B4A2E7A2D49C814,
         $61111B294BE474FD,$A584BD225674F416,$7ED82A969A6FF537,$E61D1F52814550F6,$D51371C72BAB1949,$1803202EC6B148ED,
         $A1485951C427DBD8,$E81968D790846E01,$07D84CE270C6081A,$5A649D1CCCA5C618,$25DBA95EF315AA3B,$162AF6243074EE17,
         $9D27CBC76CA2D398,$23F3574062B5F6EF,$7374610A598B3FBB,$075BADE7ADE78559,$6B780F1834577C85,$66554A2DDB86A440,
         $D25C0BE95CF74A8F,$748807A20F3FBF82,$5A56141982679189,$3C00FC33835725DA,$8C5CFF67F661039B,$1225E803399B5E79,
         $A13B695643C9CFE7,$7BB56A80A7DF88D3,$F8B065E5C76E6A43,$02CE48CA1A5788C8,$526517AC59F0FFF0,$23FA162260BEA06F,
         $6667FEAFE0D56112,$56019BF12A3FE594,$87714A417CA0D7A5,$41EBDCA383F8A285,$D53093CDBF077385,$9BD5BA075F822F65,
         $CAD9D3C026986FA8,$D30A2C504D9FDA79,$B48A23862F694B16,$7A46CA4A03D8872F,$6F572CB8145BE481,$BDC7BFBD877E8574,
         $7C3E233C822DBFDB,$EA37BB69D576B681,$22369EF6514EBF45,$3F25257E89225A7C,$6AF2BF51A3A9CD93,$23E824F866FD02A6,
         $C15AC3BB5301748A,$AD0B4516B65E1D7A,$9C08390C1B88AFCD,$7F3522AC36C7D2EC,$1CF818BC1CD8043A,$ED95D568F0979B5A,
         $D64373402C99BE95,$91729337B83229F9,$FF5B7C69C84ADF2E,$3A5D1016683E6518,$5EE1BA7C2D97F2D0,$F74389CBDBE1F0D5,
         $45598E3FB29DECD9,$EE8705D11EC65158,$400415916BDF76A9,$E3BD97F1D3B42B77,$59464CB26D291B31,$B9CC857E8B1B5D04,
         $5674969CDDD09AE6,$BBE8D807A2488674,$B6552129F8196E9B,$EA4F932A96E3F928,$5299A59CA7A8F194,$928716AF8D8847E0,
         $ACAE9B32AD22FE30,$34A7B654F56FC4A1,$C5202C56638D6773,$415CAB05053BD016,$BF2B8277C3F675B3,$148C531CF416B6F6,
         $E189E17CAE6406AB,$9761690DB32FD690,$426BFD205D3C863A,$84F24076E58964B8,$680A6DB9283D93E6,$8007C4D161DCB75F,
         $696428F3B16F1409,$49DC32339A0D0963,$A7E21D73D4081B8E,$4B6CFC142A616EB2,$F2A86F5A8577C931,$11357114A6DD9BF4,
         $1C45C6ED4BB3FBE8,$F12D4295C9D3054D,$E4C3FB45B46F3A4C,$5E4CCC22D32883AF,$A40668974DC5D461,$750708E67D300E8D,
         $4B740DB5330EAB12,$E0D955E17BCEB5D6,$DFD8EB80A8060BEA,$1E57202461330F85,$03F6C69AECD91849,$778EB2F11E7E5C81,
         $454694672A313C41,$DC573CE682DBDCC6,$0E20ABA22F223253,$DB95135CCAF685CC,$D28D52CC4B7F42EA,$463E49A0CF2E421B,
         $4B2A65A43C57A029,$D82917FAB0F7F6FD,$18C82CA908FE5215,$B1B94E5ED020BF60,$E7E0B33BD33823EB,$3185C9B56448CB3F,
         $4B298833A2EC3DB0,$7A7E997451137973,$973D1819E31899C0,$AD26B023B173A1A4,$9E2FCB2D9CEA834B,$179BD258875643C3,
         $5CF07B3A6CC6EEEC,$6E2B9D1B83FB9EF4,$B797E6CAC6C2A998,$44848A4651E07F14,$9100AD14E899FC5B,$2FBEBCB0B4243FC3,
         $DBA4ED6316D28D31,$1ED037AB7ED6FAEF,$EA7C641E9E110C9D,$444F04E6EF3C653A,$1255D297A7E1F2B1,$A161B7D1D3D35371,
         $D1774C248BDC16F5,$A00F52017B04F752,$0390B3916BB40E56,$CEED6E3F61AFF329,$A336CB8DDA4D16A4,$AC8DD40C75E24695,
         $B9EBF1A62B0B4019,$6D4043DA93515C72,$E1F3A2A4FA26C0E8,$E80F171DF4D1E934,$466F5491E7F72F9A,$002C8B6B8F5C84C3,
         $A97AF7FE71B9B83D,$93455EE7C6297093,$022721D1D40C84D8,$9B9580C02288737C,$8A3D94BFFA73ED98,$C74199FF876B441C
  Data.b $00
EndDataSection


Re: [DEMO 2D] PIXEL 2 LOGO

Publié : dim. 26/avr./2020 13:34
par Ollivier

Code : Tout sélectionner

Case 4
   Ralentisse = 100
   Sprite()\Xrnd + (Sprite()\Xori -Sprite()\Xrnd) / Ralentisse
   Sprite()\Yrnd + (Sprite()\Yori -Sprite()\Yrnd) / Ralentisse
Case 5

Re: [DEMO 2D] PIXEL 2 LOGO

Publié : dim. 26/avr./2020 13:50
par Ar-S
C'est beau ! :)

Re: [DEMO 2D] PIXEL 2 LOGO

Publié : dim. 26/avr./2020 18:38
par Kwai chang caine
J'adore 8O
Merci à vous deux pour le partage 8)

Re: [DEMO 2D] PIXEL 2 LOGO

Publié : dim. 26/avr./2020 20:01
par venom
Sympa ces effets. Merci Ar-S

Sympa aussi Ollivier 8)






@++

Re: [DEMO 2D] PIXEL 2 LOGO

Publié : lun. 27/avr./2020 10:07
par MLD
Chouette.Merci du partage

Re: [DEMO 2D] PIXEL 2 LOGO

Publié : lun. 27/avr./2020 11:51
par Micoute
Génial cet effet.