local Screen = require("screen") local sw, sh, iw, ih local anim, frame, scrn function _init() scrn = Screen:new("Rotate and zoom!", 10, 8) anim = image.load(_DIR .. "images/juggler.gif") trimanim() scrn:usepalette(anim[1]) scrn:autocolor() sys.stepinterval(1000 / 30) frame = 0 sw, sh = scrn:size() iw, ih = image.size(anim[1]) end function _step(t) scrn:step(t) view.active(scrn.mainvp) frame = frame + 1 if frame > #anim then frame = 1 end local a = t / 1000 local d = math.abs(math.sin(a * .3)) * iw * 4 local x1, y1 = iw / 2 + math.sin(a + math.pi * 0.0) * d, ih / 2 - math.cos(a + math.pi * 0.0) * d local x2, y2 = iw / 2 + math.sin(a + math.pi * 0.5) * d, ih / 2 - math.cos(a + math.pi * 0.5) * d local x3, y3 = iw / 2 + math.sin(a + math.pi * 1.0) * d, ih / 2 - math.cos(a + math.pi * 1.0) * d local x4, y4 = iw / 2 + math.sin(a + math.pi * 1.5) * d, ih / 2 - math.cos(a + math.pi * 1.5) * d image.tri(anim[frame], sw / 2 - sh / 2, 0, sw / 2 + sh / 2, 0, sw / 2 + sh / 2, sh, x1, y1, x2, y2, x3, y3) image.tri(anim[frame], sw / 2 + sh / 2, sh, sw / 2 - sh / 2, sh, sw / 2 - sh / 2, 0, x3, y3, x4, y4, x1, y1) if input.hotkey() == "q" then sys.exit() end end function trimanim() view.active(scrn.rootvp) iw, ih = image.size(anim[1]) local s = 1 while s < math.min(iw, ih) do s = s * 2 end while s > math.min(iw, ih) do s = s / 2 end for i, frm in ipairs(anim) do local _frm = image.new(s, s, 8) gfx.cls() image.usepalette(frm) image.draw(frm, 0, 0, iw / 2 - s / 2, ih / 2 - s / 2, s, s) image.copy(_frm, 0, 0, 0, 0, s, s) image.copypalette(_frm) image.forget(frm) anim[i] = _frm end end