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.
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.
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.
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>
</>
);Sequenceshows its children from framefromfordurationInFrames.Seriesplays itsSeries.Sequencechildren one after another. For transitions between them, see Transitions.Looprepeats its children everydurationInFrames.Freezeholds 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.
What works
- Drawn natively: all of the above, with values recorded from Remotion for
interpolate,springandrandom. - Approximated:
useCurrentScale()andusePixelDensity()always return 1, andgetRemotionEnvironment()always says it is rendering. - Not supported: a library that reads the wall clock is not frame-pure. See Libraries.
- See What works.