--!movie
global $
----------------------------------------
--
----------------------------------------
on startMovie
-- CONFIG
DUR = 50 -- 50 ms = 20 fps
-- libs
$.import("console").show()
-- create an instance of the AWEBP lib
awebp = $.include($.PATH&"awebp.ls").new()
-- load background image from file
m = new(#bitmap)
m.importFileInto($.PATH&"input\lena.bmp")
lena = m.image
-- create blue square image
blue_square = image(100, 100, 32)
blue_square.fill(blue_square.rect, rgb(0,0,255))
-- create a circle mask
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_mask = alpha.createMask()
ms = the milliseconds
-- initialize AWEBP (i.e. start creation of new WebP file)
awebp.init(0) -- 0 = loop forever
-- add frames in a loop
repeat with i = 0 to 103
frame_image = lena.duplicate()
frame_image.copyPixels(blue_square, blue_square.rect.offset(i*4, i*4), blue_square.rect, [#maskImage:circle_mask])
awebp.addFrame(frame_image, DUR)
end repeat
-- save the WebP file
ok = awebp.writeFile($.PATH&"animation_circle.webp")
ms = the milliseconds-ms
if ok then
out("Done. Animated WebP file was generated in " & ms & " milliseconds.")
else
out("Error: failed to generate animated WebP file.")
end if
end