Skip to content

🎥 Make videos programmatically with React

Update motion-canvas.md

Jonny Burgere1186cbd3545
diff --git a/packages/docs/docs/compare/motion-canvas.md b/packages/docs/docs/compare/motion-canvas.md
index 4bade36ccd..2d49ae1428 100644
--- a/packages/docs/docs/compare/motion-canvas.md
+++ b/packages/docs/docs/compare/motion-canvas.md
@@ -15,83 +15,84 @@ Remotion uses a whole DOM tree for the video, while Motion Canvas uses a single
Remotion may render more types of content, but needs a headless browser to create a video.
Motion Canvas can only render canvas-based content, but may do so in the browser.
-## Declarative vs. Imperative API
+## API comparison
-Remotion uses React, a declarative library for expressing UI.
-Motion Canvas uses an its own imperative API.
+Remotion lets you to render React markup based on the current time. React is a popular library for building UIs.
-Compare the following examples to see the difference in the programming style:
+Motion Canvas uses an imperative API. Rather than rendering markup based on a timestamp, elements are added procedurally to the timeline.
-```tsx twoslash title="Remotion API - Declarative"
-import { Circle } from "@remotion/shapes";
+Remotions programming style can be described as "declarative" and "keyframe-based", while the terms "imperative" and "procedural" describe Motion Canvas well.
-export const MyComp: React.FC = () => {
- return <Circle radius={100} fill="red" />;
-};
-```
-
-```tsx title="Motion Canvas API - Imperative"
-export default makeScene2D(function* (view) {
- const circle = createRef<Circle>();
- view.add(<Circle ref={circle} width={100} height={100} />);
-
- circle().fill("red");
-});
-```
+Here is an identical animation (Red circle turning into an orange one, then jumping to the right using a spring animation) in Remotion and Motion Canvas:
-## Keyframes vs. Procedural
-
-Remotion requires you to render an image based on the current time.
-Motion Canvas requires you to define a list of animation steps.
-
-```tsx twoslash title="Remotion API"
-import { Circle } from "@remotion/shapes";
+```tsx twoslash title="Remotion Implementation"
import {
- Easing,
+ AbsoluteFill,
interpolate,
interpolateColors,
+ spring,
useCurrentFrame,
+ useVideoConfig,
} from "remotion";
export const MyComp: React.FC = () => {
const frame = useCurrentFrame();
- const progress = interpolate(frame, [0, 60], [0, 1], {
- easing: Easing.inOut(Easing.cubic),
+ const { fps } = useVideoConfig();
+
+ const colorChange = interpolate(frame, [0, 60], [0, 1], {
extrapolateRight: "clamp",
});
+ const spr = spring({
+ fps,
+ frame: frame - 60,
+ });
+ const translateX = interpolate(spr, [0, 1], [0, 300]);
+
return (
- <Circle
- radius={100}
- fill={interpolateColors(progress, [0, 60], ["#e6a700", "#e13238"])}
- />
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ }}
+ >
+ <div
+ style={{
+ width: 200,
+ height: 200,
+ borderRadius: 100,
+ backgrondColor: interpolateColors(
+ colorChange,
+ [0, 1],
+ ["#e6a700", "#e13238"]
+ ),
+ transform: `translateX(${translateX}px)`,
+ }}
+ />
+ </AbsoluteFill>
);
};
```
-```tsx title="Motion Canvas API"
-import { Color } from "@motion-canvas/core/lib/types";
+```tsx title="Motion Canvas Implementation"
+import { makeScene2D } from "@motion-canvas/2d";
+import { Circle } from "@motion-canvas/2d/lib/components";
+import { SmoothSpring, spring } from "@motion-canvas/core/lib/tweening";
+import { createRef } from "@motion-canvas/core/lib/utils";
export default makeScene2D(function* (view) {
const circle = createRef<Circle>();
- view.add(<Circle ref={circle} width={100} height={100} />);
-
- yield *
- tween(2, (value) => {
- circle().fill(
- Color.lerp(
- new Color("#e6a700"),
- new Color("#e13238"),
- easeInOutCubic(value)
- )
- );
- });
-}
+
+ view.add(<Circle ref={circle} size={200} fill={"#e6a700"} />);
+
+ yield* circle().fill("#e13238", 2);
+ yield* spring(SmoothSpring, 0, 300, (value) => circle().position.x(value));
+});
```
## Broad vs. specialized
-Remotion tries to make as few assumptions over the content of the video as possible and supports a wide variety of use-cases.
+Remotion tries to make as few assumptions over the content of the video as possible and supports a wide variety of use cases.
Motion Canvas is designed for informative vector animations and ships built-in APIs to optimize for this use case.
## Special qualities of each library