Skip to content

Visualize Your Ideas With Code

docs: presentation mode (#489)

Jacob96774d376a8a
diff --git a/packages/docs/docs/getting-started/configuration.mdx b/packages/docs/docs/getting-started/configuration.mdx
index accbcd5c..dcf61e49 100644
--- a/packages/docs/docs/getting-started/configuration.mdx
+++ b/packages/docs/docs/getting-started/configuration.mdx
@@ -1,5 +1,5 @@
---
-sidebar_position: 11
+sidebar_position: 16
slug: /configuration
---
diff --git a/packages/docs/docs/getting-started/presentation.mdx b/packages/docs/docs/getting-started/presentation.mdx
new file mode 100644
index 00000000..05a68ddc
--- /dev/null
+++ b/packages/docs/docs/getting-started/presentation.mdx
@@ -0,0 +1,60 @@
+---
+sidebar_position: 15
+slug: /presentation
+---
+
+import {VideoSettings} from '@site/src/Icon/VideoSettings';
+
+# Presentation
+
+Aside from exporting your animations, you can use Motion Canvas to present them
+in real time. Simply define some slides in your animation and then navigate
+between them using the Presentation Mode.
+
+## `beginSlide` function
+
+The [`beginSlide`](/api/core/utils#beginSlide) function is used to mark the
+beginning of a new slide. When this function is yielded, the playback will pause
+and wait for you to press `SPACE`:
+
+```ts
+import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
+import {Txt} from '@motion-canvas/2d/lib/components';
+import {beginSlide, createRef} from '@motion-canvas/core/lib/utils';
+import {waitFor} from '@motion-canvas/core/lib/flow';
+
+export default makeScene2D(function* (view) {
+ const title = createRef<Txt>();
+ view.add(<Txt ref={title} />);
+
+ title().text('FIRST SLIDE');
+ yield* beginSlide('first slide');
+ yield* waitFor(1); // try doing some actual animations here
+
+ title().text('SECOND SLIDE');
+ yield* beginSlide('second slide');
+ yield* waitFor(1);
+
+ title().text('LAST SLIDE');
+ yield* beginSlide('last slide');
+ yield* waitFor(1);
+});
+```
+
+## Presentation Mode
+
+To present your animation, navigate to the Video Settings <VideoSettings
+ className="icon-inline"
+ alt="Video Settings"
+ title="Video Settings"
+/> tab. Click on the dropdown next to the `RENDER` button and choose `PRESENT`.
+From now on, pressing the button will enter the Presentation Mode (You can
+switch back to rendering at any time using the same dropdown). Try entering the
+Presentation Mode in <a href="/editor/presentation/" target="_blank">our online
+editor</a>.
+
+In this mode, you can quickly switch between all your slides using the panel on
+the left. You can also use the playback controls at the bottom to navigate from
+one slide to another. Hover over the buttons to see what they do and what
+keyboard shortcuts are assigned to them. When switching to full screen, the
+controls disappear, but you can still use your keyboard to navigate.
diff --git a/packages/docs/docs/getting-started/quickstart.mdx b/packages/docs/docs/getting-started/quickstart.mdx
index aaf14b51..fa32dc34 100644
--- a/packages/docs/docs/getting-started/quickstart.mdx
+++ b/packages/docs/docs/getting-started/quickstart.mdx
@@ -31,7 +31,7 @@ node -v
Run the following command in order to scaffold a new Motion Canvas project:
```bash
-npm init @motion-canvas
+npm init @motion-canvas@latest
```
Answer the prompts to name your project and select which language you would like
diff --git a/packages/docs/docs/getting-started/rendering.mdx b/packages/docs/docs/getting-started/rendering.mdx
index 0b7f9aa5..d4af15f0 100644
--- a/packages/docs/docs/getting-started/rendering.mdx
+++ b/packages/docs/docs/getting-started/rendering.mdx
@@ -1,5 +1,5 @@
---
-sidebar_position: 12
+sidebar_position: 14
slug: /rendering
---
@@ -8,30 +8,44 @@ import {PhotoCamera} from '@site/src/Icon/PhotoCamera';
# Rendering
-To render an animation, open the Rendering tab using the <VideoSettings
+The Video Settings tab serves as the main control panel for all things related
+to the display of your animation. You can open it by pressing the <VideoSettings
className="icon-inline"
alt="Video Settings"
title="Video Settings"
-/> icon. Here, you can configure the output settings of your animation as well
-as initialize the rendering process.
+/> icon. Here, you can configure various settings related to your animation,
+initialize the rendering process, and enter the presentation mode.
## Configuration
+### Background
+
+The background of your animation. This is the base color used to clear the
+canvas before drawing your scenes. Most color formats such as `#242424` or
+`rgba(255, 255, 255, 0.5)` are accepted. Leaving this option empty will make the
+background transparent.
+
+:::tip
+
+The project background cannot be animated. You can use the `fill` property of
+the view, instead:
+
+```ts
+export default makeScene2D(function* (view) {
+ view.fill('#242424'); // set the background of this scene
+ yield* view.fill('lightseagreen', 2); // animate it
+});
+```
+
+:::
+
### Range
-The Range is the span of frames that will be rendered. If set to a smaller range
+The range is the span of frames that will be rendered. If set to a smaller range
than the entire length of the video, it will only render a portion of the frames
in your animation. This can be useful for quickly rendering small changes in
your animation.
-### Frame rate
-
-The frame rate at which the preview plays and the number of frames that will
-render per one second of runtime. The most common values are 24, 30, and 60,
-though any whole integer value is allowed. Motion Canvas animations are
-resilient to changes in frame rate, so most animations will not be affected by
-changing it.
-
### Resolution
The resolution in pixels of each frame in the video. You may use this value to
@@ -39,13 +53,34 @@ render in a higher resolution or to change the aspect ratio. Note, however, that
animations will not scale with changes in resolution, so plan ahead for any
adjustments to resolution.
+### Audio offset
+
+This option is only available if you've [set up audio](/docs/media#audio) for
+the current project. It allows you to offset the start of the audio in relation
+to your animation. The value is stored in seconds. You can also adjust the
+offset by holding `SHIFT` over the audio track and dragging it left or right.
+
+### Frame rate
+
+The frame rate at which the animation plays and the number of frames that will
+render per one second of runtime. The most common values are 24, 30, and 60,
+though any whole integer value is allowed. Motion Canvas animations are
+resilient to changes in frame rate, so most animations will not be affected by
+changing it.
+
### Scale
Scale will increase or decrease the resolution of the animation, but, unlike the
Resolution option, the coordinates and size of animation elements will be
-adjusted as well. You may use this option to render in multiple different
-resolution densities or to adjust your output resolution after completing an
-animation.
+adjusted as well.
+
+:::tip
+
+Both Scale and Frame rate can be configured separately for the preview and the
+rendering. This lets you increase the performance of the preview (by rendering
+in smaller resolution and/or lower framerate) while rendering in high quality.
+
+:::
### Color Space
diff --git a/packages/docs/docusaurus.config.js b/packages/docs/docusaurus.config.js
index d6365e9a..1ddb83d4 100644
--- a/packages/docs/docusaurus.config.js
+++ b/packages/docs/docusaurus.config.js
@@ -160,6 +160,10 @@ const config = {
name: 'logging',
url: 'Logging example',
},
+ {
+ name: 'presentation',
+ url: 'Presentation example',
+ },
],
},
],
diff --git a/packages/docs/src/Icon/VideoSettings/index.tsx b/packages/docs/src/Icon/VideoSettings/index.tsx
index cf7b23b5..d9cfa3b7 100644
--- a/packages/docs/src/Icon/VideoSettings/index.tsx
+++ b/packages/docs/src/Icon/VideoSettings/index.tsx
@@ -13,13 +13,7 @@ export function VideoSettings({
fill="currentColor"
{...props}
>
- <g>
- <g>
- <path d="M3,6h18v5h2V6c0-1.1-0.9-2-2-2H3C1.9,4,1,4.9,1,6v12c0,1.1,0.9,2,2,2h9v-2H3V6z" />
- <polygon points="15,12 9,8 9,16" />
- <path d="M22.71,18.43c0.03-0.29,0.04-0.58,0.01-0.86l1.07-0.85c0.1-0.08,0.12-0.21,0.06-0.32l-1.03-1.79 c-0.06-0.11-0.19-0.15-0.31-0.11L21.23,15c-0.23-0.17-0.48-0.31-0.75-0.42l-0.2-1.36C20.26,13.09,20.16,13,20.03,13h-2.07 c-0.12,0-0.23,0.09-0.25,0.21l-0.2,1.36c-0.26,0.11-0.51,0.26-0.74,0.42l-1.28-0.5c-0.12-0.05-0.25,0-0.31,0.11l-1.03,1.79 c-0.06,0.11-0.04,0.24,0.06,0.32l1.07,0.86c-0.03,0.29-0.04,0.58-0.01,0.86l-1.07,0.85c-0.1,0.08-0.12,0.21-0.06,0.32l1.03,1.79 c0.06,0.11,0.19,0.15,0.31,0.11l1.27-0.5c0.23,0.17,0.48,0.31,0.75,0.42l0.2,1.36c0.02,0.12,0.12,0.21,0.25,0.21h2.07 c0.12,0,0.23-0.09,0.25-0.21l0.2-1.36c0.26-0.11,0.51-0.26,0.74-0.42l1.28,0.5c0.12,0.05,0.25,0,0.31-0.11l1.03-1.79 c0.06-0.11,0.04-0.24-0.06-0.32L22.71,18.43z M19,19.5c-0.83,0-1.5-0.67-1.5-1.5s0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5 S19.83,19.5,19,19.5z" />
- </g>
- </g>
+ <path d="M15 8v8H5V8h10m1-2H4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4V7c0-.55-.45-1-1-1z" />
</svg>
);
}
diff --git a/packages/examples/src/presentation.meta b/packages/examples/src/presentation.meta
new file mode 100644
index 00000000..264a1896
--- /dev/null
+++ b/packages/examples/src/presentation.meta
@@ -0,0 +1,26 @@
+{
+ "version": 0,
+ "shared": {
+ "background": "rgb(20,20,20)",
+ "range": [
+ 0,
+ null
+ ],
+ "size": {
+ "x": 1920,
+ "y": 1080
+ },
+ "audioOffset": 0
+ },
+ "preview": {
+ "fps": 30,
+ "resolutionScale": 1
+ },
+ "rendering": {
+ "fps": 60,
+ "resolutionScale": 2,
+ "colorSpace": "srgb",
+ "fileType": "image/png",
+ "quality": 1
+ }
+}
\ No newline at end of file
diff --git a/packages/examples/src/presentation.ts b/packages/examples/src/presentation.ts
new file mode 100644
index 00000000..fea0d189
--- /dev/null
+++ b/packages/examples/src/presentation.ts
@@ -0,0 +1,7 @@
+import {makeProject} from '@motion-canvas/core';
+
+import scene from './scenes/presentation?scene';
+
+export default makeProject({
+ scenes: [scene],
+});
diff --git a/packages/examples/src/scenes/presentation.meta b/packages/examples/src/scenes/presentation.meta
new file mode 100644
index 00000000..e9af48e6
--- /dev/null
+++ b/packages/examples/src/scenes/presentation.meta
@@ -0,0 +1,5 @@
+{
+ "version": 0,
+ "timeEvents": [],
+ "seed": 513847161
+}
\ No newline at end of file
diff --git a/packages/examples/src/scenes/presentation.tsx b/packages/examples/src/scenes/presentation.tsx
new file mode 100644
index 00000000..cc28e85a
--- /dev/null
+++ b/packages/examples/src/scenes/presentation.tsx
@@ -0,0 +1,70 @@
+import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
+import {Rect, Txt} from '@motion-canvas/2d/lib/components';
+import {beginSlide, createRef} from '@motion-canvas/core/lib/utils';
+import {all, loop} from '@motion-canvas/core/lib/flow';
+import {easeInOutCubic} from '@motion-canvas/core/lib/tweening';
+import {Color} from '@motion-canvas/core/lib/types';
+import {createSignal} from '@motion-canvas/core/lib/signals';
+import {cancel} from '@motion-canvas/core/lib/threading';
+
+const YELLOW = '#FFC66D';
+const RED = '#FF6470';
+const GREEN = '#99C47A';
+const BLUE = '#68ABDF';
+
+export default makeScene2D(function* (view) {
+ view.fontFamily(`'JetBrains Mono', monospace`).fontWeight(700).fontSize(256);
+ const backdrop = createRef<Rect>();
+ const title = createRef<Txt>();
+ const rotation = createSignal(0);
+ const rotationScale = createSignal(0);
+
+ view.add(
+ <Rect
+ cache
+ ref={backdrop}
+ width={'50%'}
+ height={'50%'}
+ fill={RED}
+ radius={40}
+ smoothCorners
+ rotation={() => rotation() * rotationScale()}
+ >
+ <Txt
+ ref={title}
+ scale={0.5}
+ compositeOperation={'destination-out'}
+ rotation={() => -rotation() * rotationScale()}
+ >
+ START
+ </Txt>
+ </Rect>,
+ );
+
+ yield* beginSlide('start');
+ yield* all(
+ backdrop().fill(GREEN, 0.6, easeInOutCubic, Color.createLerp('lab')),
+ backdrop().size.x('60%', 0.6),
+ title().text('CONTENT', 0.6),
+ );
+
+ yield* beginSlide('content');
+ const loopTask = yield loop(Infinity, () => rotation(-5, 1).to(5, 1));
+ yield* all(
+ backdrop().fill(BLUE, 0.6, easeInOutCubic, Color.createLerp('lab')),
+ backdrop().size.x('70%', 0.6),
+ title().text('ANIMATION', 0.6),
+ rotationScale(1, 0.6),
+ );
+
+ yield* beginSlide('animation');
+ yield* all(
+ backdrop().fill(YELLOW, 0.6, easeInOutCubic, Color.createLerp('lab')),
+ backdrop().size.x('50%', 0.6),
+ title().text('FINISH', 0.6),
+ rotationScale(0, 0.6),
+ );
+ cancel(loopTask);
+
+ yield* beginSlide('finish');
+});
diff --git a/packages/examples/vite.config.ts b/packages/examples/vite.config.ts
index b7eb4c43..2b593c69 100644
--- a/packages/examples/vite.config.ts
+++ b/packages/examples/vite.config.ts
@@ -25,6 +25,7 @@ export default defineConfig({
'./src/transitions.ts',
'./src/tweening-spring.ts',
'./src/tweening-save-restore.ts',
+ './src/presentation.ts',
],
}),
],