🎥 Make videos programmatically with React
Elements: Add Cylinder Text
Jonny Burger82e681d36da7
diff --git a/packages/docs/components/demos/CylinderTextDemo.tsx b/packages/docs/components/demos/CylinderTextDemo.tsxindex 16a07ff023..a30e173619 100644--- a/packages/docs/components/demos/CylinderTextDemo.tsx+++ b/packages/docs/components/demos/CylinderTextDemo.tsx@@ -1,35 +1,17 @@-import {cylinder} from '@remotion/effects/cylinder';import React from 'react';-import {- AbsoluteFill,- CanvasImage,- useCurrentFrame,- useVideoConfig,-} from 'remotion';--// A transparent strip lets the back of the wheel show through the lettering.-const textSource = `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="1280" height="720" viewBox="0 0 1280 720"><text x="0" y="394" fill="#b6f34b" font-family="Arial, sans-serif" font-size="100" font-weight="900" textLength="1280" lengthAdjust="spacingAndGlyphs">REMOTION • CREATE • </text></svg>`)}`;+import {AbsoluteFill} from 'remotion';+import {CylinderText} from '../../elements/text/cylinder-text/cylinder-text';export const CylinderTextDemo: React.FC = () => {- const frame = useCurrentFrame();- const {durationInFrames} = useVideoConfig();return (- <AbsoluteFill style={{backgroundColor: '#10151c'}}>- <CanvasImage- src={textSource}- width={1280}- height={720}- fit="cover"- effects={[- cylinder({- radius: 340,- rotation: (frame / durationInFrames) * 360,- rotationX: 52,- rotationZ: -18,- shading: 0.65,- }),- ]}- />+ <AbsoluteFill+ style={{+ alignItems: 'center',+ justifyContent: 'center',+ backgroundColor: '#eef1f4',+ }}+ >+ <CylinderText /></AbsoluteFill>);};diff --git a/packages/docs/elements/text/cylinder-text/cylinder-text.tsx b/packages/docs/elements/text/cylinder-text/cylinder-text.tsxnew file mode 100644index 0000000000..bf0d21789b--- /dev/null+++ b/packages/docs/elements/text/cylinder-text/cylinder-text.tsx@@ -0,0 +1,90 @@+import {cylinder} from '@remotion/effects/cylinder';+import React from 'react';+import {+ CanvasImage,+ Interactive,+ useCurrentFrame,+ useVideoConfig,+ type InteractiveTransformProps,+ type InteractivitySchema,+} from 'remotion';++type CylinderTextProps = InteractiveTransformProps & {+ readonly text?: string;+ readonly color?: string;+ readonly speed?: number;+ readonly tilt?: number;+};++const cylinderTextSchema = {+ text: {+ type: 'string',+ default: 'MAKE IT MOVE • MAKE IT MOVE • ',+ description: 'Text',+ },+ color: {type: 'color', default: '#182033', description: 'Text color'},+ speed: {+ type: 'number',+ min: -1,+ max: 1,+ step: 0.01,+ default: 1 / 6,+ description: 'Revolutions per second',+ hiddenFromList: false,+ },+ tilt: {+ type: 'rotation-degrees',+ min: 0,+ max: 85,+ default: 52,+ description: 'Tilt',+ },+} as const satisfies InteractivitySchema;++const CylinderTextInner: React.FC<CylinderTextProps> = ({+ text = 'MAKE IT MOVE • MAKE IT MOVE • ',+ color = '#182033',+ speed = 1 / 6,+ tilt = 52,+ style,+}) => {+ const frame = useCurrentFrame();+ const {fps} = useVideoConfig();+ const [escapedText, escapedColor] = [text, color].map((value) =>+ value+ .replaceAll('&', '&')+ .replaceAll('"', '"')+ .replaceAll('<', '<')+ .replaceAll('>', '>'),+ );+ const src = `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="800" height="680" viewBox="0 0 800 680"><text x="0" y="340" dominant-baseline="central" fill="${escapedColor}" font-family="Arial, Helvetica, sans-serif" font-size="90" font-weight="700" textLength="800" lengthAdjust="spacingAndGlyphs" xml:space="preserve">${escapedText}</text></svg>`)}`;++ return (+ <div style={{width: 800, height: 680, ...style}}>+ <CanvasImage+ src={src}+ width={800}+ height={680}+ fit="cover"+ showInTimeline={false}+ style={{width: '100%', height: '100%'}}+ effects={[+ cylinder({+ radius: 320,+ rotation: (frame / fps) * speed * 360,+ rotationX: tilt,+ rotationZ: -18,+ shading: 0.35,+ }),+ ]}+ />+ </div>+ );+};++export const CylinderText = Interactive.create({+ Component: CylinderTextInner,+ componentName: '<CylinderText>',+ layout: 'none',+ schema: cylinderTextSchema,+});diff --git a/packages/docs/elements/text/cylinder-text/index.mdx b/packages/docs/elements/text/cylinder-text/index.mdxnew file mode 100644index 0000000000..1163030c51--- /dev/null+++ b/packages/docs/elements/text/cylinder-text/index.mdx@@ -0,0 +1,14 @@+---+title: Cylinder Text+description: Editable text spinning around a tilted cylinder using WebGPU.+image: https://remotion.media/elements/text-cylinder-text-preview-dedee66f-31f5-49bb-ad07-d02622c05c4c.png+---++import {getElementDefinition} from '@site/src/components/Elements/element-utils';+import {ElementPage} from '@site/src/components/Elements/ElementPage';++# Cylinder Text++<ElementPage definition={getElementDefinition('text/cylinder-text')} sourceFile="./cylinder-text.tsx" />++Requires WebGPU. Change the text, color, rotation speed, and tilt in the Inspector. Negative speed reverses the rotation.diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.tsindex a8d3964100..6ea0b0c2df 100644--- a/packages/docs/src/components/Elements/element-definitions.ts+++ b/packages/docs/src/components/Elements/element-definitions.ts@@ -52,6 +52,7 @@ import {speedLinesInitialProps} from '../../../elements/storytelling/speed-linesimport {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 {CylinderText} from '../../../elements/text/cylinder-text/cylinder-text';import {NewsArticleHighlight} from '../../../elements/text/news-article-highlight/news-article-highlight';import {SpinningTextWheel} from '../../../elements/text/spinning-text-wheel/spinning-text-wheel';import {StrikeThroughText} from '../../../elements/text/strike-through/strike-through';@@ -1158,6 +1159,34 @@ const elementImplementations = [installationMode: 'component-owned-sequence',width: 1920,},+ {+ slug: 'text/cylinder-text',+ assets: [],+ installationProps: null,+ component: CylinderText,+ contributors: [],+ description:+ 'Editable text spinning around a tilted cylinder using WebGPU.',+ dependencies: [{name: '@remotion/effects', version: null}],+ durationInFrames: 180,+ elementHeight: 680,+ elementWidth: 800,+ fps: 30,+ height: 1080,+ posterFrame: 30,+ preview: {+ previewLayout: 'composition',+ posterUrl:+ 'https://remotion.media/elements/text-cylinder-text-preview-dedee66f-31f5-49bb-ad07-d02622c05c4c.png',+ backgroundTheme: 'light',+ videoUrl:+ 'https://remotion.media/elements/text-cylinder-text-preview-dedee66f-31f5-49bb-ad07-d02622c05c4c.mp4',+ },+ safeArea: 120,+ initialProps: null,+ installationMode: 'component-owned-sequence',+ width: 1920,+ },{slug: 'text/spinning-text-wheel',assets: [],diff --git a/packages/docs/src/components/Elements/element-registry.ts b/packages/docs/src/components/Elements/element-registry.tsindex 64183b7c6f..71377321a6 100644--- a/packages/docs/src/components/Elements/element-registry.ts+++ b/packages/docs/src/components/Elements/element-registry.ts@@ -159,6 +159,10 @@ export const elementRegistry = {category: 'text',displayName: 'Crossed Off',},+ 'text/cylinder-text': {+ category: 'text',+ displayName: 'Cylinder Text',+ },'text/spinning-text-wheel': {category: 'text',displayName: 'Spinning Text Wheel',