Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Shearing images

edited January 2012 in Questions Posts: 2,820

Hello,
Is it possible to use something like shear(x,y)? As far as I can tell, it's impossible besides writing code that takes a strip of pixels of the image and shifts it over (which I could imagine is extremely slow).
Thanks!

Tagged:

Comments

  • Posts: 2,820

    Should I just write the function?

  • edited January 2012 Posts: 2,820

    Once thats done, it wouldn't be hard to do squease(top%,bottom%,left%,right%).

  • BortelsBortels Mod
    Posts: 1,557

    Not currently, not without doing what you suggest, which would indeed be slow. I suggested it a while ago - there's been talk about letting us do arbitrary transforms (which would include sheer), but nothing yet.

  • Posts: 2,820

    Hmm. If I have leftover time, I'll look into it... How hard could it be? But the speed... :0&

  • Posts: 2,820

    Thanks for answering @Bortels

  • BortelsBortels Mod
    Posts: 1,557

    Yeah, I did the Pic() library - it's gonna be slow. But - if you're only doing it in setup, maybe not so bad.

    There was some talk about making the new mesh() stuff in 1.3 be able to do that, maybe kinda sorta - but I don't think it made it in.

  • Posts: 2,820

    Alright. Thanks.

  • SimeonSimeon Admin Mod
    Posts: 5,029

    1.3 has the Mesh API, which will make shearing very easy.

  • Posts: 2,820

    Alright.Thanks!

  • Posts: 2,820

    @Simeon - What's this all about right here? If you could share whatever it is, please do so.
    Thanks!

  • SimeonSimeon Admin Mod
    Posts: 5,029

    Shearing images with mesh:

    function setup()
        m = mesh()
        m.texture = "Small World:Icon"
    
        w,h = spriteSize(m.texture)
    
        parameter("Shear",-100,100,0)
    end
    
    function setQuad(m, ll, tl, tr, br)
        local verts = { ll, tl, br, br, tl, tr }
        local tex = { vec2(0,1), vec2(0,0), vec2(1,1),
                      vec2(1,1), vec2(0,0), vec2(1,0) }
        m.vertices = verts
        m.texCoords = tex
    end
    
    function draw()
        background(40,40,50)
    
        fill(255)
        translate(WIDTH/2, HEIGHT/2)
    
        -- Sheared quad
        setQuad( m, vec2( -w/2 - Shear, -h/2 ), vec2( -w/2 + Shear, h/2 ),
                    vec2(  w/2 + Shear,  h/2 ), vec2(  w/2 - Shear, -h/2 ) )
    
        m:draw()
    end
    
  • Posts: 2,820

    AWSOME! Thanks! Posted it on Wiki. I think I'll turn it into a function and eventually add some other transitions like squeeze.
    Thanks!

Sign In or Register to comment.