1. --!movie
  2.  
  3. global $
  4.  
  5. ----------------------------------------
  6. --
  7. ----------------------------------------
  8. on startMovie
  9.  
  10.     -- CONFIG
  11.     DUR = 50 -- 50 ms = 20 fps
  12.  
  13.     -- libs
  14.     $.import("console").show()
  15.  
  16.     -- create an instance of the AWEBP lib
  17.     awebp = $.include($.PATH&"awebp.ls").new()
  18.  
  19.     -- load background image from file
  20.     m = new(#bitmap)
  21.     m.importFileInto($.PATH&"input\lena.bmp")
  22.     lena = m.image
  23.  
  24.     -- create blue square image
  25.     blue_square = image(100, 100, 32)
  26.     blue_square.fill(blue_square.rect, rgb(0,0,255))
  27.  
  28.     -- create a circle mask
  29.     m = new(#bitmap)
  30.     m.importFileInto($.PATH&"input\circle.bmp", [#trimWhitespace: FALSE])
  31.     alpha = image(100, 100, 8, #grayscale)
  32.     alpha.copyPixels(m.image, alpha.rect, alpha.rect)
  33.     circle_mask = alpha.createMask()
  34.  
  35.     ms = the milliseconds
  36.  
  37.     -- initialize AWEBP (i.e. start creation of new WebP file)
  38.     awebp.init(0) -- 0 = loop forever
  39.  
  40.     -- add frames in a loop
  41.     repeat with i = 0 to 103
  42.         frame_image = lena.duplicate()
  43.         frame_image.copyPixels(blue_square, blue_square.rect.offset(i*4, i*4), blue_square.rect, [#maskImage:circle_mask])
  44.         awebp.addFrame(frame_image, DUR)
  45.     end repeat
  46.  
  47.     -- save the WebP file
  48.     ok = awebp.writeFile($.PATH&"animation_circle.webp")
  49.  
  50.     ms = the milliseconds-ms
  51.  
  52.     if ok then
  53.         out("Done. Animated WebP file was generated in " & ms & " milliseconds.")
  54.     else
  55.         out("Error: failed to generate animated WebP file.")
  56.     end if
  57. end
  58.  
[raw code]