Übergang: Stern-Blende

Das neue Bild öffnet sich durch einen wachsenden Stern. Ein Canvas-Pfad wird mit `applyMask` zur Maske; jede Form, die sich zeichnen lässt, taugt als Blende.

A
A — Übergang: Stern-Blende
B
B — Übergang: Stern-Blende
Animation
Animation — Übergang: Stern-Blende
JavaScript
// Star wipe — one transition between two photos, exported as a looping animated WebP.
//
// Everything specific sits in transition(from, to, T): it takes two images it may change and a
// progress T from 0 to 1, and returns one new frame. Video tools can call exactly that for each
// frame of a cut; the rest of this script only builds the animation.

//!INPUT: A, B
//!OUTPUT: OUT
//!PARAM: STEPS:integer=18,min=2,max=120
//!PARAM: DELAY_MS:integer=50,min=10,max=2000
//!PARAM: HOLD_MS:integer=700,min=0,max=5000
//!PARAM: POINTS:integer=5,min=3,max=12
//!PARAM: INNER:number=0.5,min=0.2,max=0.9,step=0.05

function transition(from, to, T) {
  const ease = T * T * (3 - 2 * T);
  const w = to.width, h = to.height, cx = w / 2, cy = h / 2;
  // At T = 1 even the inner radius reaches the corners, so the image is fully covered.
  const outer = (ease * Math.hypot(w, h)) / 2 / INNER;
  let star = "";
  for (let i = 0; i < 2 * POINTS; i++) {
    const angle = -Math.PI / 2 + (i * Math.PI) / POINTS;
    const r = i % 2 ? outer * INNER : outer;
    star += `${i ? "L" : "M"} ${cx + r * Math.cos(angle)},${cy + r * Math.sin(angle)} `;
  }
  const cv = Engine.createCanvas(w, h);
  cv.fill("#000").drawPathStr(`M 0,0 L ${w},0 L ${w},${h} L 0,${h} Z`);
  cv.fill("#fff").drawPathStr(star + "Z");
  const mask = cv.toImage();
  to.applyMask(mask);
  from.blendAt(to, px(0, 0), 1, Blend.Over);
  [mask, cv, to].forEach((handle) => handle.free());
  return from;
}

const imgA = Engine.loadImage(A);
const imgB = Engine.loadImage(B);
if (imgB.width !== imgA.width || imgB.height !== imgA.height) {
  imgB.resize(imgA.width, imgA.height);
}
const anim = Engine.animation(imgA.width, imgA.height, { loop: 0 });
const p = Engine.progress("Transition frames", { total: STEPS * 2 });

// There and back: the loop closes without a jump, and both directions show the effect.
for (const [first, second] of [[imgA, imgB], [imgB, imgA]]) {
  for (let i = 0; i < STEPS; i++) {
    const T = i / (STEPS - 1);
    const frame = transition(first.clone(), second.clone(), T);
    anim.addFrame(frame, { delay: i === STEPS - 1 ? HOLD_MS : DELAY_MS });
    frame.free();
    p.step(1, `frame ${i + 1}/${STEPS}`);
  }
}

anim.saveWebP(OUT, { lossy: true, quality: 62 });
anim.free();
imgA.free();
imgB.free();

// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0