05-29-2023, 10:10 PM
This is just an example of how you can deform images using maptriangle 2D. On line 10, just overwrite the image name with a valid name for your image. Then after launch just move with the mouse.
Code: (Select All)
'image deform demo by Petr
$NoPrefix
Screen NewImage(1024, 768, 32)
DOWN = Height * .7
UP = Height * .3
Gstep = 3 '1 is smoothest cut, best output but "low" speed
ASize = Fix(Width / Gstep)
image& = LoadImage("img.jpg", 32)
v& = _NewImage(1024, 768, 32) 'set image to the same width and height as screen to handle v&
PutImage , image&, v&
FreeImage image&
Dim As Integer XX(ASize), YY(ASize), YY2(ASize)
Do
While MouseInput
Wend
Cls
i = 0
XSTEPL = Gstep * Pi / 2 / MouseX ' program use for deformations SINUS so is image width and height recalculated to radians here
XSTEPR = Gstep * Pi / 2 / (Width - MouseX)
YP = (-Height / 2 + MouseY)
For XD = 1 To MouseX Step Gstep
X = XD
Y = DOWN + Sin(XP) * YP
Y2 = UP + Sin(XP) * -YP
XP = XP + XSTEPL
XX(i) = X
YY(i) = Y
YY2(i) = Y2
i = i + 1
Next
For XD = MouseX To Width - 1 Step Gstep
X = XD
Y = DOWN + Sin(XP) * YP
Y2 = UP + Sin(XP) * -YP
XP = XP + XSTEPR
XX(i) = X
YY(i) = Y
YY2(i) = Y2
i = i + 1
Next
i = i - 1
XP = 0
For MPT = 0 To i - 1
XS = MPT * Gstep 'step in x in 2d
XS2 = (MPT + 1) * Gstep
ScrX = XX(MPT)
ScrX2 = XX(MPT + 1)
ScrY2 = YY(MPT)
ScrY = YY2(MPT + 1)
MapTriangle (XS, 0)-(XS2, 0)-(XS, 768), v& To(ScrX, ScrY)-(ScrX2, ScrY)-(ScrX, ScrY2), 0
MapTriangle (XS2, 0)-(XS, 768)-(XS2, 768), v& To(ScrX2, ScrY)-(ScrX, ScrY2)-(ScrX2, ScrY2), 0
Next
Display
Limit 120
Loop