Motion Canvas — TypeScript 애니메이션 엔진 (설명 영상 제작용)
제너레이터를 사용하여 애니메이션을 프로그래밍하고 실시간 편집기로 제어할 수 있는 TypeScript 라이브러리입니다. 설명 영상, 코드 워크스루, 교육 콘텐츠 제작에 적합합니다.
개요
- 저장소: github.com/motion-canvas/motion-canvas (18K+ 스타)
- 언어: TypeScript
- 라이선스: MIT
- 설치:
npm create @motion-canvas@latest - 문서: motioncanvas.io/docs
핵심 개념
프로젝트 설정
npm create @motion-canvas@latest my-animation
cd my-animation
npm install
npm start # localhost:9000에서 편집기 실행
씬(Scene)
모든 애니메이션은 씬으로 구성되며, 각 씬은 제너레이터 함수입니다:
import { makeScene2D } from "@motion-canvas/2d";
import { createRef } from "@motion-canvas/core";
import { Circle } from "@motion-canvas/2d/lib/components";
export default makeScene2D(function* (view) {
const circle = createRef<Circle>();
view.add(<Circle ref={circle} size={100} fill="#e13238" />);
// 원 애니메이션
yield* circle().scale(2, 0.6);
yield* circle().opacity(0, 0.3);
});
제너레이터를 이용한 애니메이션
yield* 키워드가 각 프레임을 순차적으로 제어합니다:
// 순차 애니메이션 (하나씩 실행)
yield* rect().position.x(300, 1); // 1초 동안 오른쪽으로 이동
yield* rect().fill("#00ff00", 0.5); // 0.5초 동안 색상 변경
// 병렬 애니메이션 (동시에 실행)
yield* all(
rect().position.x(300, 1),
rect().rotation(360, 1),
);
// 지연과 체인 연결
yield* chain(
rect().opacity(1, 0.3),
waitFor(0.5),
rect().scale(2, 0.6),
);
// 일정 시간 대기
yield* waitFor(2); // 2초 대기
노드 (시각 요소)
import { Rect, Circle, Line, Txt, Img, Video, Layout } from "@motion-canvas/2d/lib/components";
// 사각형
<Rect width={200} height={100} fill="#333" radius={10} />
// 텍스트
<Txt text="Hello" fontSize={48} fill="white" fontFamily="monospace" />
// 원
<Circle size={80} fill="#e13238" />
// 이미지
<Img src={myImage} width={400} />
// 레이아웃 (flexbox)
<Layout direction="column" gap={20} alignItems="center">
<Txt text="Title" />
<Rect width={200} height={50} />
</Layout>
신호 (반응형 값)
import { createSignal } from "@motion-canvas/core";
const progress = createSignal(0);
// 컴포넌트에서 사용
<Rect width={() => progress() * 400} height={20} fill="blue" />
// 신호 애니메이션
yield* progress(1, 2); // 0에서 1까지 2초 동안 애니메이션
이징(Easing)
import { easeInOutCubic, easeOutBounce, linear } from "@motion-canvas/core";
yield* rect().position.x(300, 1, easeInOutCubic);
yield* circle().scale(2, 0.8, easeOutBounce);
코드 하이라이팅
import { Code, lines, word } from "@motion-canvas/2d/lib/components";
const code = createRef<Code>();
view.add(
<Code
ref={code}
fontSize={24}
code={`function hello() {\n console.log("world");\n}`}
/>
);
// 특정 줄 하이라이트
yield* code().selection(lines(1, 2), 0.3);
// 코드 변경 애니메이션
yield* code().code(
`function hello() {\n return "world";\n}`,
0.6,
);
명령어
# 편집기 실행 (실시간 미리보기)
npm start
# 영상 렌더링
npx motion-canvas render
# 특정 씬 렌더링
npx motion-canvas render --scene=myScene
모범 사례
- 애니메이션 대상은 ref 사용: 애니메이션할 노드마다
createRef<Circle>()사용 - 제너레이터 기반 흐름: 순차적으로 생각하세요 —
yield*가 타임라인입니다 all()로 병렬 처리: 동시에 실행할 애니메이션은 그룹화- 반응형 데이터는 신호 사용: 여러 노드가 의존하는 값에 적합
- flexbox는 Layout 컴포넌트 사용: 자식 요소를 자동으로 배치
- 씬을 짧게 유지: 긴 애니메이션은 여러 씬으로 분할
- 편집기 활용: 실시간 미리보기와 스크러빙이 매우 유용합니다
Motion Canvas vs Remotion 사용 시기
| Motion Canvas | Remotion | |
|---|---|---|
| 적합한 대상 | 교육, 설명 영상 | 제품, 마케팅 영상 |
| 애니메이션 스타일 | 명령형 (제너레이터) | 선언형 (React) |
| 편집기 | 내장 실시간 편집기 | Remotion Studio |
| 코드 애니메이션 | 일급 지원 | 수동 구현 |
| 생태계 | 성장 중 | 대규모 (npm 패키지) |
| 음성 동기화 | 내장 오디오 동기화 | 수동 동기화 |
출처
- 저장소: github.com/motion-canvas/motion-canvas
- 문서: motioncanvas.io/docs
- 예제: motioncanvas.io/docs/examples