Thanks for the suggestions I should have realized I needed it dynamic, I can't really prerender becuase there are so many images that can morph to eachother. I thought this would be easier.
I just made each pixel an object and had each one move to a random target position of the new image. But ofcourse it looks like sand now. Any ideas on how to make it look more like goo?
Strict
Graphics 555,555
Local i1:timage,i2:timage
i1=CreateImage(50,50)
i2=CreateImage(50,50)
SetColor 0,0,255
DrawOval 0,0,40,50
GrabImage i1,0,0
Cls
SetColor 255,100,0
DrawRect 0,30,50,50
GrabImage i2,0,0
Cls
Local m:tmorph
m=tmorph.make(i1,i2)
Local tog
Repeat
If m.update() Then
If tog Then
m=tmorph.make(i1,i2)
Else
m=tmorph.make(i2,i1)
EndIf
tog=Not tog
EndIf
m.draw(200,200)
SetColor 255,255,255
DrawImage i1,0,0
DrawImage i2,100,0
Flip
Cls
If KeyHit(key_escape) Then End
Forever
Type TMorph
Field Loops:Int=0
Field Image1:timage
Field Image2:timage
Field array1:tmorphpixel[,]
Field array2:Int[,]
Function Make:tmorph(image1:timage, image2:timage)
Local morph:tmorph
morph=New tmorph
morph.image1=image1
morph.image2=image2
morph.setup()
Return morph
EndFunction
Method Setup()
Local x,y,c
Local pixmap:TPixmap
'store pixel data of new image
array2=New Int[image2.width, image2.height]
pixmap=LockImage(image2)
For y=0 Until image2.height
For x=0 Until image2.width
c=ReadPixel(pixmap,x,y) & $FFFFFF
If c<>$FF00FF Then
array2[x,y]=c
EndIf
Next
Next
UnlockImage image2
'make pixs from old image
Local x2,y2
Local pix:tmorphpixel
array1=New tmorphpixel[image1.width, image1.height]
pixmap=LockImage(image1)
For y=0 Until image1.height
For x=0 Until image1.width
c=ReadPixel(pixmap,x,y) & $FFFFFF
If c<>0 Then
pix=New tmorphpixel
array1[x,y]=pix
pix.x=x
pix.y=y
pix.b=c & $FF
pix.g=c Shr 8 & $FF
pix.r=c Shr 16 & $FF
'Print pix.r+","+pix.g+","+pix.b+","+c
'give the pix a target pixel
Repeat
x2=Rand(0, image2.width-1)
y2=Rand(0, image2.height-1)
If array2[x2, y2] <> 0 Then Exit
Forever
pix.targetx=x2
pix.targety=y2
c=array2[x2,y2]
pix.targetb=c & $FF
pix.targetg=c Shr 8 & $FF
pix.targetr=c Shr 16 & $FF
EndIf
Next
Next
UnlockImage image1
EndMethod
Method Update()
loops:+1
If loops>=70 Then Return 1
Local x,y
Local pix:tmorphpixel
For y=0 Until image1.height
For x=0 Until image1.width
pix=array1[x,y]
If pix<>Null Then
movetovar(pix.r, pix.targetr, 3)
movetovar(pix.g, pix.targetg, 3)
movetovar(pix.b, pix.targetb, 3)
pix.speedx:+ Sgn(pix.targetx-pix.x)*.15
pix.speedy:+ Sgn(pix.targety-pix.y)*.15
'pix.speedx = Sgn(pix.targetx-pix.x)*.8
'pix.speedy = Sgn(pix.targety-pix.y)*.8
movetovarfloat(pix.speedx,0 , (1-1/loops)*.1)
movetovarfloat(pix.speedy,0 , (1-1/loops)*.1)
pix.x:+ pix.speedx
pix.y:+ pix.speedy
EndIf
Next
Next
EndMethod
Method Draw(pixelx,pixely)
Local x,y
Local pix:tmorphpixel
For y=0 Until image1.height
For x=0 Until image1.width
pix=array1[x,y]
If pix<>Null Then
SetColor pix.r, pix.g, pix.b
DrawRect pixelx+pix.x, pixely+pix.y, 1,1
EndIf
Next
Next
EndMethod
Function MoveToVarFloat(Number:Float Var,Target:Float,Speed:Float)
If Abs(number-target)<=speed Then
number=target
Return
EndIf
If number<target Then
number:+speed
Else
number:-speed
EndIf
EndFunction
Function MoveToVar(Number:Int Var, Target:Int, Speed:Int)
If Abs(number-target)<=speed Then
number=target
Return
EndIf
If number<target Then
number:+speed
Else
number:-speed
EndIf
EndFunction
EndType
Type TMorphPixel
Field x:Float,y:Float
Field targetx,targety
Field r,g,b
Field targetr,targetg,targetb
Field speedx:Float, speedy:Float
EndType