Animierte Montage — 4 Effekte fliegen rein
Ein Quellbild, vier Effekt-Varianten (Grayscale, Sepia, Blur, Threshold), jede fliegt aus einer eigenen Richtung in ihren 2×2-Quadranten. Demonstriert Engine.animation: einen Mehrbild-Container, der als APNG oder WebP-animated exportiert wird und nativ in jedem modernen Browser läuft.
INPUT
Montage
JavaScript
// Animation demo — 2×2 effect-variant montage assembled from 4 sides.
// anim_montage_4way.js
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: STEPS:integer=24,min=1,max=200
//!PARAM: HOLD_MS:integer=1500,min=0,max=10000
// Takes one source image, builds four half-size effect variants
// (grayscale, sepia, gaussian blur, threshold), then animates each
// flying into its own quadrant on a 2×2 grid:
//
// ┌─────────┬─────────┐
// │ TL │ TR │ TL ← from top
// │ gray │ sepia │ TR ← from right
// ├─────────┼─────────┤ BL ← from left
// │ BL │ BR │ BR ← from bottom
// │ blur │ thresh. │
// └─────────┴─────────┘
//
// Canvas matches the original image size, so the four half-size
// quadrants tile it exactly. Each frame composites the four variants
// at their interpolated positions on a black canvas.
const src = Engine.loadImage(INPUT);
const w = src.width;
const h = src.height;
const halfW = Math.floor(w / 2);
const halfH = Math.floor(h / 2);
// Pre-compute the four effect variants once.
const tl = src.clone().resize(halfW, halfH).grayscale();
const tr = src.clone().resize(halfW, halfH).sepia();
const bl = src.clone().resize(halfW, halfH).gaussianBlur(8);
const br = src.clone().resize(halfW, halfH).threshold(0.5);
// Final resting positions for each variant on the canvas.
const FINAL = {
tl: { x: 0, y: 0 },
tr: { x: halfW, y: 0 },
bl: { x: 0, y: halfH },
br: { x: halfW, y: halfH },
};
// Off-canvas starting positions — each variant approaches from its
// own side so the four motions don't overlap at the start.
const START = {
tl: { x: 0, y: -halfH }, // from top
tr: { x: w, y: 0 }, // from right
bl: { x: -halfW, y: halfH }, // from left
br: { x: halfW, y: h }, // from bottom
};
const lerp = (a, b, t) => Math.round(a + (b - a) * t);
const anim = Engine.animation(w, h, { loop: 0 });
const blank = Engine.createImage(w, h);
for (let s = 0; s < STEPS; s++) {
const t = s / (STEPS - 1);
const frame = blank.clone()
.blendAt(tl, px(lerp(START.tl.x, FINAL.tl.x, t), lerp(START.tl.y, FINAL.tl.y, t)), 1.0)
.blendAt(tr, px(lerp(START.tr.x, FINAL.tr.x, t), lerp(START.tr.y, FINAL.tr.y, t)), 1.0)
.blendAt(bl, px(lerp(START.bl.x, FINAL.bl.x, t), lerp(START.bl.y, FINAL.bl.y, t)), 1.0)
.blendAt(br, px(lerp(START.br.x, FINAL.br.x, t), lerp(START.br.y, FINAL.br.y, t)), 1.0);
anim.addFrame(frame, { delay: 33 }); // ~30 fps
frame.free();
}
// Hold the assembled montage for HOLD_MS so the loop has a clear
// "rest" beat before the cycle restarts.
const final = blank.clone()
.blendAt(tl, px(FINAL.tl.x, FINAL.tl.y), 1.0)
.blendAt(tr, px(FINAL.tr.x, FINAL.tr.y), 1.0)
.blendAt(bl, px(FINAL.bl.x, FINAL.bl.y), 1.0)
.blendAt(br, px(FINAL.br.x, FINAL.br.y), 1.0);
anim.addFrame(final, { delay: HOLD_MS });
final.free();
// saveAPNG is also available; we use saveWebP lossy here so the
// gallery loads fast (~85% smaller than APNG, plays natively in
// every modern browser).
anim.saveWebP(OUTPUT, { lossy: true, quality: 85 });
anim.free();
blank.free();
tl.free(); tr.free(); bl.free(); br.free();
src.free();
// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0