Skip to content

🎥 Make videos programmatically with React

clockwipe

Patric Salvisberg6792500b8c0c
diff --git a/packages/docs/components/TableOfContents/transitions/presentations.tsx b/packages/docs/components/TableOfContents/transitions/presentations.tsx
index b70bcb3f15..e2ded3f92d 100644
--- a/packages/docs/components/TableOfContents/transitions/presentations.tsx
+++ b/packages/docs/components/TableOfContents/transitions/presentations.tsx
@@ -1,3 +1,4 @@
+import { clockwipe } from "@remotion/transitions/clockwipe";
import { fade } from "@remotion/transitions/fade";
import { flip } from "@remotion/transitions/flip";
import { slide } from "@remotion/transitions/slide";
@@ -13,6 +14,9 @@ const row: React.CSSProperties = {
justifyContent: "space-between",
};
+const compositionWidth = 540;
+const compositionHeight = 280;
+
export const Presentations: React.FC = () => {
return (
<Grid>
@@ -68,6 +72,23 @@ export const Presentations: React.FC = () => {
</div>
</div>
</TOCItem>
+ <TOCItem link="/docs/transitions/presentations/clockwipe">
+ <div style={row}>
+ <PresentationPreview
+ durationRestThreshold={0.001}
+ effect={clockwipe({
+ width: compositionWidth,
+ height: compositionHeight,
+ })}
+ />
+ <div style={{ flex: 1, marginLeft: 10 }}>
+ <strong>
+ <code>{"flip()"}</code>
+ </strong>
+ <div>Rotate the previous scene</div>
+ </div>
+ </div>
+ </TOCItem>
<TOCItem link="/docs/transitions/audio-transitions">
<div style={row}>
<div style={{ flex: 1 }}>
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 29f5653f87..24ecdfe63d 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -7,6 +7,7 @@ import styles from "./styles.module.css";
import type { DemoType } from "./types";
import {
circleDemo,
+ clockwipePresentationDemo,
customPresentationDemo,
customTimingDemo,
ellipseDemo,
@@ -57,6 +58,7 @@ const demos: DemoType[] = [
flipPresentationDemo,
customPresentationDemo,
customTimingDemo,
+ clockwipePresentationDemo,
];
export const Demo: React.FC<{
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 30af4f1c03..47e7f3370a 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -1,4 +1,5 @@
import {
+ ClockWipeDemo,
CustomTimingDemo,
CustomTransitionDemo,
FadeDemo,
@@ -614,6 +615,17 @@ export const wipePresentationDemo: DemoType = {
],
};
+export const clockwipePresentationDemo: DemoType = {
+ comp: ClockWipeDemo,
+ compHeight: 280,
+ compWidth: 540,
+ durationInFrames: 60,
+ fps: 30,
+ id: "clockwipe",
+ autoPlay: true,
+ options: [],
+};
+
export const customPresentationDemo: DemoType = {
comp: CustomTransitionDemo,
compHeight: 280,
diff --git a/packages/docs/components/transitions/previews.tsx b/packages/docs/components/transitions/previews.tsx
index d49c1c5836..cdc263c7fc 100644
--- a/packages/docs/components/transitions/previews.tsx
+++ b/packages/docs/components/transitions/previews.tsx
@@ -5,6 +5,7 @@ import type {
TransitionTiming,
} from "@remotion/transitions";
import { springTiming, TransitionSeries } from "@remotion/transitions";
+import { clockwipe } from "@remotion/transitions/clockwipe";
import { fade } from "@remotion/transitions/fade";
import type { FlipDirection } from "@remotion/transitions/flip";
import { flip } from "@remotion/transitions/flip";
@@ -131,6 +132,17 @@ export const WipeDemo: React.FC<{
);
};
+export const ClockWipeDemo: React.FC<{}> = () => {
+ const { width, height } = useVideoConfig();
+
+ return (
+ <SampleTransition
+ effect={clockwipe({ width, height })}
+ durationRestThreshold={0.001}
+ />
+ );
+};
+
export const CustomTransitionDemo: React.FC<{}> = () => {
const { width, height } = useVideoConfig();
diff --git a/packages/docs/docs/transitions/presentations/clockwipe.mdx b/packages/docs/docs/transitions/presentations/clockwipe.mdx
new file mode 100644
index 0000000000..e29a416a5e
--- /dev/null
+++ b/packages/docs/docs/transitions/presentations/clockwipe.mdx
@@ -0,0 +1,69 @@
+---
+image: /generated/articles-docs-transitions-presentations-clockwipe.png
+crumb: "@remotion/transitions - Presentations"
+title: "clockwipe()"
+---
+
+# clockwipe()<AvailableFrom v="4.0.73"/>
+
+A presentation where the exiting slide fades out in a clockwise fashion, revealing the next slide underneath it.
+
+<Demo type="clockwipe" />
+
+## Example
+
+```tsx twoslash title="ClockWipeTransition.tsx"
+import { AbsoluteFill } from "remotion";
+
+const Letter: React.FC<{
+ children: React.ReactNode;
+ color: string;
+}> = ({ children, color }) => {
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: color,
+ opacity: 0.9,
+ justifyContent: "center",
+ alignItems: "center",
+ fontSize: 200,
+ color: "white",
+ }}
+ >
+ {children}
+ </AbsoluteFill>
+ );
+};
+// ---cut---
+import { linearTiming, TransitionSeries } from "@remotion/transitions";
+import { clockwipe } from "@remotion/transitions/clockwipe";
+import { useVideoConfig } from "remotion";
+
+const BasicTransition = () => {
+ const { width, height } = useVideoConfig();
+
+ return (
+ <TransitionSeries>
+ <TransitionSeries.Sequence durationInFrames={40}>
+ <Letter color="#0b84f3">A</Letter>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={clockwipe({ width, height })}
+ timing={linearTiming({ durationInFrames: 30 })}
+ />
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <Letter color="pink">B</Letter>
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ );
+};
+```
+
+## API
+
+Accepts an object containg of `width` and `height`, which should be set to the width and height of the video.
+
+## See also
+
+- [Source code for this presentation](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/clockwipe.tsx)
+- [Presentations](/docs/transitions/presentations)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index c19cb99ef6..2f5f88a490 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -428,6 +428,7 @@ module.exports = {
"transitions/presentations/slide",
"transitions/presentations/wipe",
"transitions/presentations/flip",
+ "transitions/presentations/clockwipe",
"transitions/presentations/custom",
"transitions/audio-transitions",
],
diff --git a/packages/transitions/package.json b/packages/transitions/package.json
index 7c49a59326..cb0a47803e 100644
--- a/packages/transitions/package.json
+++ b/packages/transitions/package.json
@@ -22,7 +22,9 @@
"url": "https://github.com/remotion-dev/remotion/issues"
},
"dependencies": {
- "remotion": "workspace:*"
+ "remotion": "workspace:*",
+ "@remotion/shapes": "workspace:*",
+ "@remotion/paths": "workspace:*"
},
"devDependencies": {
"@jonny/eslint-config": "3.0.276",
@@ -82,6 +84,12 @@
"require": "./dist/cjs/presentations/flip.js",
"types": "./dist/presentations/flip.d.ts"
},
+ "./clockwipe": {
+ "module": "./dist/presentations/clockwipe.js",
+ "import": "./dist/presentations/clockwipe.js",
+ "require": "./dist/cjs/presentations/clockwipe.js",
+ "types": "./dist/presentations/clockwipe.d.ts"
+ },
"./package.json": "./package.json"
},
"typesVersions": {
@@ -97,6 +105,9 @@
],
"fade": [
"dist/presentations/fade.d.ts"
+ ],
+ "clockwipe": [
+ "dist/presentations/clockwipe.d.ts"
]
}
}
diff --git a/packages/transitions/rollup.config.js b/packages/transitions/rollup.config.js
index 661c129ed8..5d2903a547 100644
--- a/packages/transitions/rollup.config.js
+++ b/packages/transitions/rollup.config.js
@@ -1,7 +1,7 @@
// rollup.config.js
import typescript from '@rollup/plugin-typescript';
-const presentations = ['slide', 'flip', 'wipe', 'fade'];
+const presentations = ['slide', 'flip', 'wipe', 'fade', 'clockwipe'];
export default [
{
@@ -32,7 +32,14 @@ export default [
sourcemap: false,
},
],
- external: ['remotion', 'remotion/no-react', 'react', 'react/jsx-runtime'],
+ external: [
+ 'remotion',
+ 'remotion/no-react',
+ 'react',
+ 'react/jsx-runtime',
+ '@remotion/paths',
+ '@remotion/shapes',
+ ],
plugins: [
typescript({
tsconfig: 'tsconfig-cjs.json',
diff --git a/packages/transitions/src/presentations/clockwipe.tsx b/packages/transitions/src/presentations/clockwipe.tsx
new file mode 100644
index 0000000000..4f9f91872e
--- /dev/null
+++ b/packages/transitions/src/presentations/clockwipe.tsx
@@ -0,0 +1,64 @@
+import {translatePath} from '@remotion/paths';
+import {makePie} from '@remotion/shapes';
+import React, {useMemo, useState} from 'react';
+import {AbsoluteFill, random} from 'remotion';
+import type {
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+} from '../types.js';
+
+export type ClockWipeProps = {
+ width: number;
+ height: number;
+};
+
+const ClockWipePresentation: React.FC<
+ TransitionPresentationComponentProps<ClockWipeProps>
+> = ({children, presentationDirection, presentationProgress, passedProps}) => {
+ const finishedRadius =
+ Math.sqrt(passedProps.width ** 2 + passedProps.height ** 2) / 2;
+
+ const {path} = makePie({
+ radius: finishedRadius,
+ progress: presentationProgress,
+ });
+
+ const translatedPath = translatePath(
+ path,
+ -(finishedRadius * 2 - passedProps.width) / 2,
+ -(finishedRadius * 2 - passedProps.height) / 2,
+ );
+
+ const [clipId] = useState(() => String(random(null)));
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ width: '100%',
+ height: '100%',
+ clipPath:
+ presentationDirection === 'exiting' ? undefined : `url(#${clipId})`,
+ };
+ }, [clipId, presentationDirection]);
+
+ return (
+ <AbsoluteFill>
+ <AbsoluteFill style={style}>{children}</AbsoluteFill>
+ {presentationDirection === 'exiting' ? null : (
+ <AbsoluteFill>
+ <svg>
+ <defs>
+ <clipPath id={clipId}>
+ <path d={translatedPath} fill="black" />
+ </clipPath>
+ </defs>
+ </svg>
+ </AbsoluteFill>
+ )}
+ </AbsoluteFill>
+ );
+};
+
+export const clockwipe = (
+ props: ClockWipeProps,
+): TransitionPresentation<ClockWipeProps> => {
+ return {component: ClockWipePresentation, props: props ?? {}};
+};