🎥 Make videos programmatically with React
Add Speed Lines storytelling element
Jonny Burger95fe15b695f3
diff --git a/packages/docs/elements/storytelling/speed-lines/index.mdx b/packages/docs/elements/storytelling/speed-lines/index.mdxnew file mode 100644index 0000000000..3d2cbb34dd--- /dev/null+++ b/packages/docs/elements/storytelling/speed-lines/index.mdx@@ -0,0 +1,12 @@+---+title: Speed Lines+description: Animated radial speed lines with a quick entrance and exit.+image: /elements/storytelling-speed-lines-preview.png+---++import {ElementPage} from '@site/src/components/Elements/ElementPage';+import {getElementDefinition} from '@site/src/components/Elements/element-utils';++# Speed Lines++<ElementPage definition={getElementDefinition('storytelling/speed-lines')} sourceFile="./speed-lines.tsx" />diff --git a/packages/docs/elements/storytelling/speed-lines/initial-props.ts b/packages/docs/elements/storytelling/speed-lines/initial-props.tsnew file mode 100644index 0000000000..e071ee8189--- /dev/null+++ b/packages/docs/elements/storytelling/speed-lines/initial-props.ts@@ -0,0 +1,6 @@+import type {ComponentProps} from 'react';+import type {SpeedLines} from './speed-lines';++export const speedLinesInitialProps = {+ color: '#ffffff',+} satisfies ComponentProps<typeof SpeedLines>;diff --git a/packages/docs/elements/storytelling/speed-lines/speed-lines.tsx b/packages/docs/elements/storytelling/speed-lines/speed-lines.tsxnew file mode 100644index 0000000000..9933a1bf3a--- /dev/null+++ b/packages/docs/elements/storytelling/speed-lines/speed-lines.tsx@@ -0,0 +1,72 @@+import React from 'react';+import {+ AbsoluteFill,+ Interactive,+ interpolate,+ random,+ useCurrentFrame,+ useVideoConfig,+ type InteractivitySchema,+} from 'remotion';++type SpeedLinesProps = {+ readonly color?: string;+ readonly style?: React.CSSProperties;+};++const SpeedLinesInner: React.FC<SpeedLinesProps> = ({+ color = '#ffffff',+ style,+}) => {+ const frame = useCurrentFrame();+ const {width, height, durationInFrames} = useVideoConfig();+ const seed = Math.floor(frame / 2);+ const cx = width / 2;+ const cy = height / 2;+ const far = Math.hypot(width, height);+ const lines = new Array(56).fill(true).map((_, i) => {+ const angle = (i / 56) * Math.PI * 2 + random(`angle-${i}-${seed}`) * 0.08;+ const spread = 0.006 + random(`spread-${i}-${seed}`) * 0.014;+ const inner = 0.36 + random(`inner-${i}-${seed}`) * 0.22;+ const x1 = cx + Math.cos(angle - spread) * far;+ const y1 = cy + Math.sin(angle - spread) * far;+ const x2 = cx + Math.cos(angle + spread) * far;+ const y2 = cy + Math.sin(angle + spread) * far;+ const xi = cx + Math.cos(angle) * inner * (width / 2);+ const yi = cy + Math.sin(angle) * inner * (height / 2);+ return `M ${xi} ${yi} L ${x1} ${y1} L ${x2} ${y2} Z`;+ });++ return (+ <AbsoluteFill style={style}>+ <AbsoluteFill+ name="Speed lines fade"+ style={{+ opacity: interpolate(+ frame,+ [0, 3, durationInFrames - 5, durationInFrames - 1],+ [0, 0.85, 0.85, 0],+ {extrapolateLeft: 'clamp', extrapolateRight: 'clamp'},+ ),+ }}+ >+ <svg width={width} height={height} viewBox={`0 0 ${width} ${height}`}>+ {lines.map((d, i) => (+ <path key={i} d={d} fill={color} />+ ))}+ </svg>+ </AbsoluteFill>+ </AbsoluteFill>+ );+};++const speedLinesSchema = {+ color: {type: 'color', default: '#ffffff', description: 'Color'},+} as const satisfies InteractivitySchema;++export const SpeedLines = Interactive.withSchema({+ Component: SpeedLinesInner,+ componentName: '<SpeedLines>',+ schema: speedLinesSchema,+ wrapInSequence: true,+});diff --git a/packages/docs/src/components/Elements/ElementPage.tsx b/packages/docs/src/components/Elements/ElementPage.tsxindex 79da0420a1..14079b7ba1 100644--- a/packages/docs/src/components/Elements/ElementPage.tsx+++ b/packages/docs/src/components/Elements/ElementPage.tsx@@ -193,6 +193,7 @@ export const ElementPage: React.FC<ElementPageProps> = ({<section aria-label="Preview" className={styles.previewColumn}><div className={styles.previewAndSource}><ElementPreview+ backgroundColor={definition.preview.backgroundColor ?? null}component={PreviewComponent}durationInFrames={durationInFrames}elementHeight={definition.elementHeight}diff --git a/packages/docs/src/components/Elements/ElementPreview.tsx b/packages/docs/src/components/Elements/ElementPreview.tsxindex 073706c579..5e9bcf5da9 100644--- a/packages/docs/src/components/Elements/ElementPreview.tsx+++ b/packages/docs/src/components/Elements/ElementPreview.tsx@@ -6,6 +6,7 @@ import {useHtmlInCanvasDocsDemoBranch} from '../../../components/demos/useHtmlInimport type {ElementPreviewLayout} from './element-definitions';type ElementPreviewProps = {+ readonly backgroundColor: string | null;readonly component: ComponentType<Record<string, never>>;readonly durationInFrames: number;readonly elementHeight: number | null;@@ -49,6 +50,7 @@ const HtmlInCanvasElementPreview: React.FC<{};export const ElementPreview: React.FC<ElementPreviewProps> = ({+ backgroundColor,component,durationInFrames,elementHeight,@@ -78,7 +80,10 @@ export const ElementPreview: React.FC<ElementPreviewProps> = ({backgroundSize: '32px 32px',}: {backgroundColor: lightPreviewBackground};- let previewBackgroundStyle = transparencyBackgroundStyle;+ let previewBackgroundStyle =+ checkerboard && backgroundColor !== null+ ? {backgroundColor}+ : transparencyBackgroundStyle;let verticalBackgroundStyle: React.CSSProperties | null = null;if (previewLayout === 'vertical') {@@ -112,7 +117,9 @@ export const ElementPreview: React.FC<ElementPreviewProps> = ({const transparencyLabel = checkerboard? 'Use light preview background'- : 'Show transparency as checkerboard';+ : backgroundColor === null+ ? 'Show transparency as checkerboard'+ : 'Use dark preview background';return (<divdiff --git a/packages/docs/src/components/Elements/ElementPreviewComposition.tsx b/packages/docs/src/components/Elements/ElementPreviewComposition.tsxindex 08da4824c1..6da570c995 100644--- a/packages/docs/src/components/Elements/ElementPreviewComposition.tsx+++ b/packages/docs/src/components/Elements/ElementPreviewComposition.tsx@@ -93,11 +93,14 @@ export const ElementPreviewComposition: React.FC<{export const ElementAssetComposition: React.FC<{readonly slug: string;}> = ({slug}) => {- const definition = getElementDefinition(slug);+ const definition: ElementDefinition = getElementDefinition(slug);return (<AbsoluteFill- style={{backgroundColor: ELEMENT_PREVIEW_BACKGROUND}}+ style={{+ backgroundColor:+ definition.preview.backgroundColor ?? ELEMENT_PREVIEW_BACKGROUND,+ }}showInTimeline={false}><ElementPreviewComposition definition={definition} />diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.tsindex a56e2328dc..f3b0a4c3ce 100644--- a/packages/docs/src/components/Elements/element-definitions.ts+++ b/packages/docs/src/components/Elements/element-definitions.ts@@ -51,6 +51,8 @@ import {NameLowerThird} from '../../../elements/overlays/name-lower-third/name-limport {SocialSafeZones} from '../../../elements/overlays/social-safe-zones/social-safe-zones';import {OnScreenMessages} from '../../../elements/storytelling/on-screen-messages/on-screen-messages';import {PolaroidPictures} from '../../../elements/storytelling/polaroid-pictures/polaroid-pictures';+import {speedLinesInitialProps} from '../../../elements/storytelling/speed-lines/initial-props';+import {SpeedLines} from '../../../elements/storytelling/speed-lines/speed-lines';import {CircleMarker} from '../../../elements/text/circle-marker/circle-marker';import {CrossedOffText} from '../../../elements/text/crossed-off/crossed-off';import {NewsArticleHighlight} from '../../../elements/text/news-article-highlight/news-article-highlight';@@ -70,6 +72,7 @@ import {export type ElementPreviewLayout = 'composition' | 'vertical';export type ElementPreviewMetadata = {+ readonly backgroundColor?: string;readonly previewLayout: ElementPreviewLayout;readonly posterUrl:| `/elements/${string}-preview.png`@@ -982,6 +985,31 @@ const elementImplementations = [installationMode: 'wrapped',width: 1920,},+ {+ slug: 'storytelling/speed-lines',+ assets: [],+ installationProps: null,+ component: SpeedLines,+ contributors: [],+ description: 'A burst of animated radial speed lines around a subject.',+ dependencies: [],+ durationInFrames: 45,+ elementHeight: null,+ elementWidth: null,+ fps: 30,+ height: 1080,+ posterFrame: 15,+ preview: {+ backgroundColor: '#20262f',+ previewLayout: 'composition',+ posterUrl: '/elements/storytelling-speed-lines-preview.png',+ videoUrl: '/elements/storytelling-speed-lines-preview.mp4',+ },+ safeArea: 0,+ initialProps: speedLinesInitialProps as ElementInitialProps,+ installationMode: 'component-owned-sequence',+ width: 1920,+ },{slug: 'storytelling/on-screen-messages',assets: [],diff --git a/packages/docs/src/components/Elements/element-registry.ts b/packages/docs/src/components/Elements/element-registry.tsindex 71a5db27db..64183b7c6f 100644--- a/packages/docs/src/components/Elements/element-registry.ts+++ b/packages/docs/src/components/Elements/element-registry.ts@@ -143,6 +143,10 @@ export const elementRegistry = {category: 'storytelling',displayName: 'Polaroid Pictures',},+ 'storytelling/speed-lines': {+ category: 'storytelling',+ displayName: 'Speed Lines',+ },'text/news-article-highlight': {category: 'storytelling',displayName: 'News Article Highlight',diff --git a/packages/docs/static/elements/storytelling-speed-lines-preview.mp4 b/packages/docs/static/elements/storytelling-speed-lines-preview.mp4new file mode 100644index 0000000000..8d12daf749Binary files /dev/null and b/packages/docs/static/elements/storytelling-speed-lines-preview.mp4 differdiff --git a/packages/docs/static/elements/storytelling-speed-lines-preview.png b/packages/docs/static/elements/storytelling-speed-lines-preview.pngnew file mode 100644index 0000000000..33446bc1d6Binary files /dev/null and b/packages/docs/static/elements/storytelling-speed-lines-preview.png differ