--------------------------------------------------- 
-- FBA Tutorials
--
-- Tutorial / 15 / Stretching and rotating images
--
--------------------------------------------------- 
--
-- This sample shows how to stretch and rotate images
--
--------------------------------------------------- 


local source = loadimage("back.png")
local source2 = loadimage("woodbox.jpg")

local v1 = 0
local s1 = 10
local angle = 0

local s2 = 30
local v2 = 0

function onmainloop()

        
        clear(0,0,0)
        
        -- draw a stretched image: we have to specify source coordinates where we want to cut source image
        -- and dest coordinates for final stretched image
        --
        drawstretchimage(source, 0, 0, 
                imagewidth(source), imageheight(source), 
                0, 0, s1, s1)
                
        if v1 == 0 then
                s1 = s1 + 1
                if s1 > 200 then
                        v1 = 1
                end
        else
                s1 = s1 - 1
                if s1 < 10 then
                        v1 = 0
                end
        end
        
        
        -- draw a rotate image. We specify destination coordinate and angle degrees rotation. The image will be
        -- rotated around its center
        --
        drawrotateimage(source2, 200,200, angle)
                
        -- draw and stretch an image, we need to specify a destination image where FBA will stretch the source one
        --
        -- be careful with realtime image creation/destroying and in general with all rotate/stretch functions, 
        -- because they could eat a lot of cpu/time 
        --
        local temp=createimage(s2, s2)
        drawrotatestretchimage(source2, temp, 50, 200, angle, 0, 0, imagewidth(source2), imageheight(source2))
        destroyimage(temp)
        
        if v2 == 0 then
                s2 = s2 + 1
                if s2 > 100 then
                        v2 = 1
                end
        else
                s2 = s2 - 1
                if s2 < 30 then
                        v2 = 0
                end
        end
        
        angle = angle + 1
        if angle > 359 then
                angle =0
        end

        if (mousedown() > 0) then
                quit()
        end

end
