Code : Tout sélectionner
;***********************************************
;Titre : Water Ripples
;Date : 03/07/2021
;Version PB : PureBasic 5.70 LTS (Windows - x64)
;
;Info : ne fonctionne qu'avec des images 32bits
; la fonction "load_image" convertis les images 24bits en 32bits
;***********************************************
EnableExplicit
UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
UseGIFImageDecoder()
; charge une image et la convertie en 32bit
;-------------------------------------------------------------------
Procedure load_image(nom,file$)
Protected nom_p.i , temps_p.i , x.l , y.l , r.l,g.l,b.l , i.l
Protected lg.l , ht.l , depth.l , temps.i , dif.l , dif1.l
LoadImage(nom,file$)
If Not IsImage(nom) : ProcedureReturn 0 : EndIf
StartDrawing(ImageOutput(nom))
Depth=OutputDepth()
StopDrawing()
If Depth=24
CopyImage(nom,temps)
FreeImage(nom)
StartDrawing(ImageOutput(temps))
temps_p = DrawingBuffer()
lg = ImageWidth(temps)
ht = ImageHeight(temps)
dif = DrawingBufferPitch() - (lg*3)
StopDrawing()
CreateImage(nom,lg,ht,32)
StartDrawing(ImageOutput(nom))
nom_p = DrawingBuffer()
StopDrawing()
For y=0 To ht-1
For x=0 To lg-1
i = ((y*lg)+x)*3
r=PeekA(temps_p + i + 2 + dif1)
g=PeekA(temps_p + i + 1 + dif1)
b=PeekA(temps_p + i + 0 + dif1)
PokeL(nom_p + ((y*lg)+x)*4 , r<<16 + g<<8 + b)
Next
dif1 = dif1 + dif
Next
FreeImage(temps) ; supprime l'image 24bits
EndIf
ProcedureReturn 1
EndProcedure
;------------------------------------------------------------------
Procedure main( source , cible , radius.f , amp.f , wavelength.f , t=0)
Protected lg ,ht , taille
Protected source_p , cible_p
Protected x , y, dx , dy , dis , var , am.f , xx , yy , pos , pos2
StartDrawing(ImageOutput(source))
lg = ImageWidth(source)
ht = ImageHeight(source)
taille=lg*ht*4
source_p=DrawingBuffer()
StopDrawing()
StartDrawing(ImageOutput(cible))
lg = ImageWidth(cible)
ht = ImageHeight(cible)
taille=lg*ht*4
cible_p=DrawingBuffer()
StopDrawing()
For y=0 To ht-1
For x=0 To lg-1
dx = x - lg/2
dy = y - ht/2
dis = Sqr(dx*dx+dy*dy)
pos = (y*lg+x)*4
If dis>radius
var = PeekL(source_p + pos)
PokeL(cible_p + pos , var)
Else
am = amp * Sin((dis / wavelength )+Radian(t/6.28))
am = am * (radius-dis)/radius
If dis<>0
am = am * wavelength / dis
xx = x + dx * am
yy = y + dy * am
If xx<0 : xx=0 : EndIf
If yy<0 : yy=0 : EndIf
If xx>lg-1 : xx=lg-1 : EndIf
If yy>ht-1 : yy=ht-1 : EndIf
pos2 = (yy*lg+xx)*4
var = PeekL(source_p + pos2)
PokeL(cible_p + pos , var)
EndIf
EndIf
Next
Next
EndProcedure
Global imgx=800
Global imgy=600
If OpenWindow(0, 0, 0, imgx, imgy+60, "Water Ripples...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define source , cible , t , t1 , t2 ,ti , file$
; Détermine le rayon où sera l'affect
TrackBarGadget(1, 0, 0, imgx, 19, 1, imgx )
; selectionne "le nombre de vagues"
TrackBarGadget(2, 0, 20, imgx, 19, 1, imgx )
; selectionne "la force de la vague"
TrackBarGadget(3, 0, 40, imgx, 19, 1, imgx )
source = 4
cible = 5
file$ = OpenFileRequester("Image","","",0)
If Not Load_Image(source,file$) ; <- commande differente de "LOADIMAGE"
MessageRequester("load_image","erreur de chargement",#PB_MessageRequester_Ok | #PB_MessageRequester_Error)
End
EndIf
ResizeImage(source,imgx,imgy,#PB_Image_Smooth)
CreateImage(cible,imgx,imgy,32)
t2=ElapsedMilliseconds()+100
Repeat
t=ElapsedMilliseconds()
main(source,cible,GetGadgetState(1),GetGadgetState(2)/50,GetGadgetState(3)/10,ti)
t1=ElapsedMilliseconds()-t
StartDrawing(WindowOutput(0))
DrawImage(ImageID(cible),0,60)
;DrawText(5,5,Str(t1))
StopDrawing()
If ElapsedMilliseconds()>t2
t2=ElapsedMilliseconds()+100
ti=t+1
If t>360 : t=0 : EndIf
EndIf
Delay(1)
Until WindowEvent() = #PB_Event_CloseWindow
EndIf