News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Cross Fade (By Pixel)

Started by kevin, February 25, 2010, 07:18:19 PM

Previous topic - Next topic

kevin

 Cross Fade (By Pixel)

  This little effect that fades one image into another, by changing it pixel by pixel.

  Note: You Need to supply the routine with two images.    


PlayBASIC Code: [Select]
   Setfps 60

Width=GetSCreenWidth()
Height =getScreenHeight()

// The NUmber Of Seconds the effect should take
NumberOFSeconds=2

// The location of two different images --------------------< READ HERE >
Frame1$="Your_Image_Here1.bmp"
Frame2$="Your_Image_Here2.bmp"


Img1=LoadNewFXImage(Frame1$)
Img2=LoadNewFXImage(Frame2$)

// Scale the two images so they're the same size
Scaleimage Img1 , Width,Height,1+2
Scaleimage Img2 , Width,Height,1+2


// Create an array to hold the XY coords as well the colour of
// each pixel at each XY coord

Dim PixelsXY(Width*Height)
Dim PixelsRGB(Width*Height)


// Run through the IMG2 and grab the pixel colours and store them
// in the PixelsRGB array with their cords
rendertoimage Img2
Lockbuffer
ThisPixel=Point(0,0)
For Ylp=0 to Height-1
For Xlp=0 to Width-1
PixelsXY(Index)=(Ylp*$10000)+Xlp
PixelsRGB(Index)=FastPOint(Xlp,ylp)
inc index
next
next
unLockbuffer
rendertoscreen

// Set the Current Pixel to the END OF SEQUENCE
CurrentPixel=WidTh*Height



// Calc the Number of Pixels that need to be rendered per frame
// for the cross fade to be completed on time
PixelsPerFrame =(Width*Height)/(getFps()*NumberOFSeconds)




Do


drawimage img1,0,0,true
rendertoimage img1

Size=PixelsPerFrame
If (CurrentPixel-Size)<0
Size=CurrentPixel
endif

Lockbuffer
ThisPixel=Point(0,0)
For count =0 to Size

// Current pixel (from the end of the sequence)
Index=CurrentPixel-Count

// Pick a pixel
SwapIndex =Int(Rnd#(CurrentPixel-Count))

// Swap the XY coordinates.
Temp=PixelsXY(Index)
PixelsXY(Index)=PixelsXY(SwapIndex)
PixelsXY(SwapIndex)=Temp

// Swpa This Colour also
Temp=PixelsRGB(Index)
PixelsRGB(Index)=PixelsRGB(SwapIndex)
PixelsRGB(SwapIndex)=Temp

// Draw This pixel..
XY=PixelsXY(Index)
Xpos=XY&$ffff
YPos=XY/$10000
FastDot Xpos,Ypos,PixelsRGB(Index)
next
unlockbuffer



RenderToScreen

CurrentPixel=CurrentPixel-PixelsPerFrame
if CurrentPixel<0 Then CurrentPixel=0
SetCursor 0,0

Sync
loop







Related To:  Time Based Reveal Effects

Crystal Noir