kinetograph.

Animation and timing

Animate with the frame number, using interpolate, spring, Easing and random, and place scenes in time with Sequence.

A frame is a function of its number. Read the number with useCurrentFrame(), and compute every animated value from it.

src/Pop.tsx
import { Rect, interpolate, spring, useCurrentFrame, useVideoConfig } from '@kinetographdev/core';

export const Pop = () => {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();
  const x = interpolate(frame, [0, 30], [0, 600], { extrapolateRight: 'clamp' });
  const scale = spring({ frame, fps, config: { damping: 14 } });
  return <Rect x={x} y={200} width={200} height={200} fill="#f6c177" origin="center" scale={scale} />;
};

interpolate

interpolate(frame, inputRange, outputRange, options) maps a number from one range to another. Without extrapolateLeft and extrapolateRight set to 'clamp', values keep going past the ends.

src/Fade.tsx
import { Easing, interpolate, interpolateColors, useCurrentFrame } from '@kinetographdev/core';

const frame = useCurrentFrame();
const opacity = interpolate(frame, [0, 20, 40, 60], [0, 1, 1, 0], { easing: Easing.inOut(Easing.cubic) });
const colour = interpolateColors(frame, [0, 60], ['#14171f', '#f6c177']);

The output range can be numbers, colours or CSS strings such as '45deg'.

spring

spring({ frame, fps, config }) gives a value that moves from 0 to 1 like a spring. config takes damping, stiffness and mass.

Easing

Easing has linear, ease, quad, cubic, sin, elastic, back, bounce and bezier. Wrap a curve in Easing.in, Easing.out or Easing.inOut.

Sequence, Series, Loop and Freeze

These place scenes in time. Inside a Sequence, useCurrentFrame() starts at 0.

src/Timeline.tsx
import { Freeze, Loop, Sequence, Series } from '@kinetographdev/core';
import { Intro, Spinner, Title } from './scenes';

export const Timeline = () => (
  <>
    <Sequence from={30} durationInFrames={60}>
      <Title />
    </Sequence>
    <Series>
      <Series.Sequence durationInFrames={45}><Intro /></Series.Sequence>
      <Series.Sequence durationInFrames={45}><Spinner /></Series.Sequence>
    </Series>
    <Loop durationInFrames={20}>
      <Spinner />
    </Loop>
    <Freeze frame={10}>
      <Title />
    </Freeze>
  </>
);
A timeline of 120 frames. A Sequence from frame 30 for 60 frames sits on it, and a nested Sequence with from 20 and 30 frames sits inside the first. Frame 50 of the composition is frame 20 inside the first Sequence and frame 0 inside the nested one, because each Sequence counts from its own start.
  • Sequence shows its children from frame from for durationInFrames.
  • Series plays its Series.Sequence children one after another. For transitions between them, see Transitions.
  • Loop repeats its children every durationInFrames.
  • Freeze holds its children at one frame. Audio inside it is silent.

Randomness

random('seed') returns the same number between 0 and 1 for the same seed, bit for bit the same as Remotion's. Use it for anything that must be the same every time.

Determinism

A frame depends only on the project and its number, so the same frame is the same picture in every render. Date.now(), Math.random(), timers and requestAnimationFrame follow the frame clock. Do not draw on top of what an earlier frame drew.

Suggested prompt

/kinetograph-markupMake the title spring in over the first second, then fade out in the last 15 frames, and check frames 0, 15 and 60.

Suggested prompt

What works

  • Drawn natively: all of the above, with values recorded from Remotion for interpolate, spring and random.
  • Approximated: useCurrentScale() and usePixelDensity() always return 1, and getRemotionEnvironment() always says it is rendering.
  • Not supported: a library that reads the wall clock is not frame-pure. See Libraries.
  • See What works.

On this page