Übergang: Kippen

Das alte Bild kippt nach hinten, bis es auf der Kante steht, das neue kommt aus derselben Drehung nach vorn. Eine Karte, ein `stampAt`, getauscht in dem Moment, in dem es niemand sieht.

A
A — Übergang: Kippen
B
B — Übergang: Kippen
Animation
Animation — Übergang: Kippen
JavaScript
// Tip over — 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: BACKGROUND:color=#101418
//!PARAM: PERSPECTIVE:number=0.9,min=0.3,max=3,step=0.1
//!PARAM: RECEDE:number=0.9,min=0,max=2,step=0.05

function transition(from, to, T) {
  if (T <= 0 || T >= 1) {
    (T <= 0 ? to : from).free();
    return T <= 0 ? from : to;
  }
  const NEARLY_EDGE = 0.98;                       // never quite 90°: A quad without area fails
  const w = to.width, h = to.height;
  const focal = PERSPECTIVE * w;
  const firstHalf = T < 0.5;
  const q = firstHalf ? T * 2 : (1 - T) * 2;      // 0 = flat, 1 = on its edge
  const angle = ((firstHalf ? 1 : -1) * q * q * Math.PI * NEARLY_EDGE) / 2;
  const depth = RECEDE * w * Math.sin(Math.PI * T);

  const corner = (x, y) => {
    const z = y * Math.sin(angle) + depth;
    const k = focal / (focal + z);
    return px(w / 2 + x * k, h / 2 + y * Math.cos(angle) * k);
  };
  const image = firstHalf ? from : to;
  image.brightness(Math.max(0.4, Math.cos(angle)));   // darker towards the edge
  const out = Engine.createColoredImage(w, h, BACKGROUND);
  out.stampAt(image, [
    corner(-w / 2, -h / 2),
    corner(w / 2, -h / 2),
    corner(w / 2, h / 2),
    corner(-w / 2, h / 2),
  ]);
  to.free();
  from.free();
  return out;
}

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