Warning
⚠️ This library is still under construction. Breaking changes are possible until I release version 1.0.0. Update versions with caution and only after reading the commit log.⚠️
If you use this in your videos, I would appreciate credit via a link to this
repo, or a mention by name. I would also love to see them; feel free to show me
on the motion canvas discord (I'm @Hunter
on there).
If you want to support the development of this and other libraries, feel free to donate on Ko-fi.
Code for this GIF can be found here
- Clone this repo.
- Run
npm install <path to this repo>
in your motion canvas project
- Run
npm install @hhenrichsen/canvas-commons
The Scrollable
node is a custom component designed to allow for scrolling
within a container. Its size represents the viewports size, and it can be
scrolled to any position within its content.
activeOpacity
- the opacity of the scrollbars when they are activehandleFadeoutDuration
- how long it takes for the scrollbars to fade outhandleFadeoutHang
- how long the scrollbars stay visible after the last scroll eventhandleInset
- the amount to inset the scrollbar handleshandleProps
- the props to pass to the scrollbar handleshandleWidth
- the width of the scrollbar handlesinactiveOpacity
- the opacity of the scrollbars when they are inactivescrollOffset
- the initial offset to use for the scrollablescrollPadding
- the amount of extra space to add when scrolling to preset positionszoom
- the zoom level of the scrollable
import {Scrollable} from '@hhenrichsen/canvas-commons';
import {makeScene2D, Rect} from '@motion-canvas/2d';
import {createRef, waitFor} from '@motion-canvas/core';
export default makeScene2D(function* (view) {
const scrollable = createRef<Scrollable>();
const rect = createRef<Rect>();
view.add(
<Scrollable ref={scrollable}>
<Rect fill={'blue'} radius={5} ref={rect} size={40}></Rect>
</Scrollable>,
);
yield* scrollable().scrollTo([150, 150], 2);
yield* scrollable().scrollToLeft(1);
yield* scrollable().scrollToTop(1);
yield* scrollable().scrollTo(0, 1);
yield* waitFor(1);
yield rect().fill('seagreen', 1);
yield* rect().size(600, 2);
yield* waitFor(1);
yield* scrollable().scrollToBottom(1);
yield* scrollable().scrollToRight(1);
yield* scrollable().scrollBy(-100, 1);
yield* waitFor(5);
});
The Window
node is custom component designed to look like a window on either a
MacOS system or a Windows 98 system.
bodyColor
- the color of the bodyheaderColor
- the color of the headertitleProps
- the props to pass to the title's<Txt>
nodetitle
- the title of the windowwindowStyle
- the style of the window, eitherWindowStyle.Windows98
orWindowStyle.MacOS
import {Window, Scrollable, WindowStyle} from '@hhenrichsen/canvas-commons';
import {makeScene2D, Rect} from '@motion-canvas/2d';
import {createRef, waitFor} from '@motion-canvas/core';
export default makeScene2D(function* (view) {
const window = createRef<Window>();
const rect = createRef<Rect>();
view.add(
<>
<Window windowStyle={WindowStyle.Windows98} ref={window}>
<Rect fill={'blue'} radius={5} ref={rect} size={40}></Rect>
</Window>
</>,
);
yield* window.open(view, 1);
yield* waitFor(1);
});
The FileTree
node is a custom component designed to look like a file tree. It
supports highlighting and selection of files and folders.
assetColor
- the color of the asset iconfileColor
- the color of the file iconfolderColor
- the color of the folder iconindentAmount
- the amount to indent each level of the treelabelColor
- the color of the labelrowSize
- the size of each row in the treestructure
- the structure of the file tree
import {FileTree, FileType} from '@hhenrichsen/canvas-commons';
import {makeScene2D} from '@motion-canvas/2d';
import {createRef, waitFor} from '@motion-canvas/core';
export default makeScene2D(function* (view) {
const fileStructure = createRef<FileTree>();
view.add(
<>
<FileTree
rowSize={50}
ref={fileStructure}
structure={{
name: '/',
type: FileType.Folder,
children: [
{
name: 'src',
type: FileType.Folder,
children: [
{
name: 'data',
id: 'db',
type: FileType.Folder,
children: [
{
name: 'queries',
type: FileType.Folder,
children: [
{
name: 'userQueries.ts',
type: FileType.File,
},
{
name: 'postQueries.ts',
type: FileType.File,
},
],
},
{
name: 'connection.ts',
type: FileType.File,
},
],
},
{
name: 'model',
id: 'model',
type: FileType.Folder,
children: [
{
name: 'user.ts',
type: FileType.File,
},
{
name: 'post.ts',
type: FileType.File,
},
],
},
{
name: 'view',
id: 'view',
type: FileType.Folder,
children: [
{
name: 'home.component.ts',
type: FileType.File,
},
{
name: 'profile.component.ts',
type: FileType.File,
},
],
},
],
},
],
}}
></FileTree>
</>,
);
yield* fileStructure().emphasize('db', 1);
});
I also have a collection of functional components that I use to automate using some of these components:
ImgWindow
- a window that contains an imageBody
- aTxt
component that wraps textTitle
- aTxt
component that is bold and largeEm
- aTxt
component that is emphasizedBold
- aTxt
component that is boldErrorBox
- a Windows 98-style error messageWindows98Button
- a button with a bevel, like in Windows 98