Skip to content

🎥 Make videos programmatically with React

inline animated shapes example

Jonny Burger8c6a28493d34
diff --git a/bun.lock b/bun.lock
index 297347dcbf..dc1c5b9b70 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1264,6 +1264,20 @@
"react-dom": ">=16.8.0",
},
},
+ "packages/skills": {
+ "name": "skills",
+ "version": "4.0.407",
+ "devDependencies": {
+ "@remotion/bundler": "workspace:*",
+ "@remotion/cli": "workspace:*",
+ "@remotion/eslint-config-internal": "workspace:*",
+ "@remotion/shapes": "workspace:*",
+ "eslint": "catalog:",
+ "react": "catalog:",
+ "react-dom": "catalog:",
+ "remotion": "workspace:*",
+ },
+ },
"packages/streaming": {
"name": "@remotion/streaming",
"version": "4.0.407",
@@ -6643,6 +6657,8 @@
"sitemap": ["[email protected]", "", { "dependencies": { "@types/node": "17.0.17", "@types/sax": "1.2.3", "arg": "5.0.2", "sax": "1.2.4" }, "bin": { "sitemap": "dist/cli.js" } }, "sha512-mK3aFtjz4VdJN0igpIJrinf3EO8U8mxOPsTBzSsy06UtjZQJ3YY3o3Xa7zSc5nMqcMrRwlChHZ18Kxg0caiPBg=="],
+ "skills": ["skills@workspace:packages/skills"],
+
"skin-tone": ["[email protected]", "", { "dependencies": { "unicode-emoji-modifier-base": "1.0.0" } }, "sha512-kUMbT1oBJCpgrnKoSr0o6wPtvRWT9W9UKvGLwfJYO2WuahZRHOpEyL1ckyMGgMWh0UdpmaoFqKKD29WTomNEGA=="],
"slash": ["[email protected]", "", {}, "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q=="],
diff --git a/packages/skills/package.json b/packages/skills/package.json
index 46d444819e..29eb2d29f6 100644
--- a/packages/skills/package.json
+++ b/packages/skills/package.json
@@ -4,5 +4,15 @@
},
"name": "skills",
"private": true,
- "version": "4.0.407"
+ "version": "4.0.407",
+ "devDependencies": {
+ "@remotion/eslint-config-internal": "workspace:*",
+ "eslint": "catalog:",
+ "@remotion/bundler": "workspace:*",
+ "remotion": "workspace:*",
+ "react": "catalog:",
+ "react-dom": "catalog:",
+ "@remotion/shapes": "workspace:*",
+ "@remotion/cli": "workspace:*"
+ }
}
diff --git a/packages/skills/skills/example-animated-shapes/assets/example.tsx b/packages/skills/skills/example-animated-shapes/assets/example.tsx
index 25825ea95d..0f8cf7a7f3 100644
--- a/packages/skills/skills/example-animated-shapes/assets/example.tsx
+++ b/packages/skills/skills/example-animated-shapes/assets/example.tsx
@@ -1,81 +1,99 @@
-import { AbsoluteFill, useCurrentFrame, useVideoConfig, spring, interpolate } from "remotion";
-import { Circle, Triangle, Rect, Star } from "@remotion/shapes";
+import {Circle, Rect, Star, Triangle} from '@remotion/shapes';
+import {
+ AbsoluteFill,
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+export const COMPOSITION_HEIGHT = 400;
+export const COMPOSITION_WIDTH = 1080;
export const MyAnimation = () => {
- const frame = useCurrentFrame();
- const { fps } = useVideoConfig();
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
- const shapes = [
- { type: "circle", color: "#6366f1", delay: 0 },
- { type: "triangle", color: "#10b981", delay: 15 },
- { type: "rect", color: "#f59e0b", delay: 30 },
- { type: "star", color: "#ec4899", delay: 45 },
- ];
+ const shapes = [
+ {type: 'circle', color: '#6366f1', delay: 0},
+ {type: 'triangle', color: '#10b981', delay: 15},
+ {type: 'rect', color: '#f59e0b', delay: 30},
+ {type: 'star', color: '#ec4899', delay: 45},
+ ];
- return (
- <AbsoluteFill
- style={{
- backgroundColor: "#0f0f0f",
- justifyContent: "center",
- alignItems: "center",
- }}
- >
- <div
- style={{
- display: "flex",
- gap: 80,
- alignItems: "center",
- }}
- >
- {shapes.map((shape, i) => {
- const entrance = spring({
- frame: frame - shape.delay,
- fps,
- config: { damping: 12, stiffness: 200 },
- });
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: '#0f0f0f',
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ display: 'flex',
+ gap: 80,
+ alignItems: 'center',
+ }}
+ >
+ {shapes.map((shape, i) => {
+ const entrance = spring({
+ frame: frame - shape.delay,
+ fps,
+ config: {damping: 12, stiffness: 200},
+ });
- const rotation = interpolate(
- frame,
- [0, 180],
- [0, 360],
- { extrapolateRight: "clamp" }
- );
+ const rotation = interpolate(frame, [0, 180], [0, 360], {
+ extrapolateRight: 'clamp',
+ });
- const bounce = Math.sin((frame - shape.delay) * 0.1) * 10;
+ const bounce = Math.sin((frame - shape.delay) * 0.1) * 10;
- const scale = entrance;
- const opacity = entrance;
+ const scale = entrance;
+ const opacity = entrance;
- const shapeProps = {
- fill: shape.color,
- stroke: "#fff",
- strokeWidth: 2,
- };
+ const shapeProps = {
+ fill: shape.color,
+ stroke: '#fff',
+ strokeWidth: 2,
+ };
- return (
- <div
- key={i}
- style={{
- opacity,
- transform: `scale(${scale}) translateY(${bounce}px) rotate(${shape.type === "star" ? rotation : 0}deg)`,
- }}
- >
- {shape.type === "circle" && (
- <Circle radius={60} {...shapeProps} />
- )}
- {shape.type === "triangle" && (
- <Triangle length={120} direction="up" {...shapeProps} />
- )}
- {shape.type === "rect" && (
- <Rect width={100} height={100} cornerRadius={12} {...shapeProps} />
- )}
- {shape.type === "star" && (
- <Star points={5} innerRadius={40} outerRadius={70} {...shapeProps} />
- )}
- </div>
- );
- })}
- </div>
- </AbsoluteFill>
- );
+ return (
+ <div
+ key={i}
+ style={{
+ opacity,
+ scale,
+ translate: '0 ' + bounce + 'px',
+ rotate: (shape.type === 'star' ? rotation : 0) + 'deg',
+ }}
+ >
+ {shape.type === 'circle' && (
+ <Circle radius={60} {...shapeProps} />
+ )}
+ {shape.type === 'triangle' && (
+ <Triangle length={120} direction="up" {...shapeProps} />
+ )}
+ {shape.type === 'rect' && (
+ <Rect
+ width={100}
+ height={100}
+ cornerRadius={12}
+ {...shapeProps}
+ />
+ )}
+ {shape.type === 'star' && (
+ <Star
+ points={5}
+ innerRadius={40}
+ outerRadius={70}
+ {...shapeProps}
+ />
+ )}
+ </div>
+ );
+ })}
+ </div>
+ </AbsoluteFill>
+ );
};
diff --git a/packages/skills/src/Root.tsx b/packages/skills/src/Root.tsx
new file mode 100644
index 0000000000..3992d4508e
--- /dev/null
+++ b/packages/skills/src/Root.tsx
@@ -0,0 +1,21 @@
+import {Composition} from 'remotion';
+import {
+ COMPOSITION_HEIGHT,
+ COMPOSITION_WIDTH,
+ MyAnimation,
+} from '../skills/example-animated-shapes/assets/example';
+
+export const RemotionRoot = () => {
+ return (
+ <>
+ <Composition
+ id="AnimatedShapes"
+ component={MyAnimation}
+ durationInFrames={100}
+ fps={30}
+ width={COMPOSITION_WIDTH}
+ height={COMPOSITION_HEIGHT}
+ />
+ </>
+ );
+};
diff --git a/packages/skills/src/index.ts b/packages/skills/src/index.ts
new file mode 100644
index 0000000000..d831f7b0f1
--- /dev/null
+++ b/packages/skills/src/index.ts
@@ -0,0 +1,4 @@
+import {registerRoot} from 'remotion';
+import {RemotionRoot} from './Root';
+
+registerRoot(RemotionRoot);