Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A distorted image
#1
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


Reply
#2
Thumbs Up 
Oh there's Pete!
   

Pretty cool @Petr
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#3
LOL!  It's like looking into a funhouse mirror... or tripping on LSD.  Maybe both.

As an old 8 & 16 bit computer nerd it sometimes amazes me how fast and smooth stuff like this can be on modern hardware.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NEW IMAGE CONVERTOR FOR THE COMMANDER X16 Platform ahenry3068 0 238 11-30-2025, 02:08 PM
Last Post: ahenry3068
Photo symmetric craziness out of one image hsiangch_ong 1 301 11-07-2025, 09:35 PM
Last Post: bplus
  A little demo for camera and zoomer on image TempodiBasic 4 1,011 03-16-2025, 12:01 PM
Last Post: TempodiBasic
  pan around a large image for video creation hsiangch_ong 0 506 01-09-2025, 01:32 AM
Last Post: hsiangch_ong
  ImagePop - puts image on screen with a little popup effect Dav 2 1,023 05-29-2024, 03:45 PM
Last Post: Dav

Forum Jump:


Users browsing this thread: 1 Guest(s)