Const winw%=1024*0.5
Const winh%=768*0.5
Global clock%,frame%,fpsc%,ox%,oy%,oa#
Graphics winw%,winh%,32,2
HidePointer
Local colormap%=LoadImage("bilda.jpg")
Local backgrnd%=LoadImage("color01.jpg")
Local alphamap%=LoadImage("alpha03.png")
Local image%=CreateImage(ImageWidth(colormap%),ImageHeight(colormap%))
Local alpha#=0.5
ResizeImage(alphamap%,ImageWidth(colormap%),ImageHeight(colormap%))
SetBuffer BackBuffer()
ClsColor 220,250,240
While KeyHit(1)=False
Cls
TileImage backgrnd%,0,0
alpha#=Limit(alpha#+MouseZSpeed()*0.1,0,1)
DrawAlphaImage(image%,colormap%,alphamap%,winw%*0.5+Sin(MilliSecs()/6)*80-150,winh%*0.5+Cos(MilliSecs()/6)*50-104,Abs(Sin(MilliSecs()/12))*0.75+0.25)
FPS()
Flip
Wend
End
;FUNCTIONS------------------------------------------------------------------
Function FPS()
If MilliSecs()>clock%+1000 Then
fpsc%=frame%
frame%=0
clock%=MilliSecs()
Else
frame%=frame%+1
End If
Color 0,0,0
Text 10,10,fpsc%+" FPS"
End Function
Function DrawAlphaImage(img%,cimg%,aimg%,x%,y%,alpha#)
If alpha#=0 Then Return
Local argb0%,argb1%,argb2%,a#,iy%,ix%
If ox%<>x% Or oy%<>y% Or oa#<>alpha# Then
Local iw%=ImageWidth(cimg%)
Local ih%=ImageHeight(cimg%)
LockBuffer GraphicsBuffer()
LockBuffer ImageBuffer(img%)
LockBuffer ImageBuffer(aimg%)
LockBuffer ImageBuffer(cimg%)
For iy%=0 To ih%
For ix%=0 To iw%
If ix%+x%=winw%-1 Or iy%+y%>winh%-1 Then Exit
a#=Float(1)/Float(255)*GetR(ReadPixelFast(ix%,iy%,ImageBuffer(aimg%)))
If a#>0 Then
argb0%=ReadPixelFast(ix%,iy%,ImageBuffer(cimg%))
argb1%=ReadPixelFast(ix%+x%,iy%+y%,GraphicsBuffer())
argb2%=GetH(GetR(argb1%)*(1-a#*alpha#)+GetR(argb0%)*a#*alpha#,GetG(argb1%)*(1-a#*alpha#)+GetG(argb0%)*a#*alpha#,GetB(argb1%)*(1-a#*alpha#)+GetB(argb0%)*a#*alpha#)
WritePixelFast(ix%,iy%,argb2%,ImageBuffer(img%))
End If
Next
Next
UnlockBuffer ImageBuffer(cimg%)
UnlockBuffer ImageBuffer(aimg%)
UnlockBuffer ImageBuffer(img%)
UnlockBuffer GraphicsBuffer()
End If
DrawImage(img%,x%,y%)
ox%=x%
oy%=y%
oa#=alpha#
End Function
Function Limit#(value#,min#,max#)
If value#>max# Then value#=max#
If value#