--!movie
global $
----------------------------------------
--
----------------------------------------
on startMovie
-- CONFIG
DUR = 50 -- 50 ms = 20 fps
-- libs
$.import("console").show()
-- create an instance of the APNG lib
apng = $.include($.PATH&"apng.ls").new()
-- load background image from file
m = new(#bitmap)
m.importFileInto($.PATH&"input\lena.bmp")
lena = m.image
lena.setAlpha(255)
lena.useAlpha = TRUE
-- create image of blue circle with alpha channel
circle = image(100, 100, 32)
circle.fill(circle.rect, rgb(0,0,255))
m = new(#bitmap)
m.importFileInto($.PATH&"input\circle.bmp", [#trimWhitespace: FALSE])
alpha = image(100, 100, 8, #grayscale)
alpha.copyPixels(m.image, alpha.rect, alpha.rect)
circle.setAlpha(alpha)
circle.useAlpha = TRUE
ms = the milliseconds
-- initialize APNG (i.e. start creation of new APNG file)
apng.init(0) -- 0 = loop forever
-- add static background photo, immediately go to next frame (ms=0)
-- using filter "Up" reduces overall filesize from 830 to 638 Kb
apng.addFrame(lena, 0, 0, 0, 0, 0, apng.FILTER_UP)
-- add frames in a loop
repeat with i = 0 to 103
-- add circle image with alpha channel on top of photo
apng.addFrame(circle, DUR, i*4, i*4, apng.DISPOSE_OP_PREVIOUS, apng.BLEND_OP_OVER)
end repeat
ms = the milliseconds-ms
-- save the APNG as file
apng.writeFile($.PATH&"animation_circle.png")
out("Done. APNG was generated in "&ms&" milliseconds.")
end