Communitygithub.com

ever-just/agentskills

一个使用生成器编程动画并带有实时编辑器的 TypeScript 库,非常适合制作解说视频、代码演示和教学内容。

agentskills 是什么?

Motion Canvas 是一个基于 TypeScript 的开源动画引擎,专门用于创建解说型视频和代码演示。它利用 ES6 生成器(Generators)来编写动画逻辑,提供了一种命令式的、顺序化的动画编程方式,配合内置的实时编辑器,可以即时预览和调整动画效果。该库支持创建场景(Scene)、节点(Node)、信号(Signal)和缓动(Easing),并内置了代码高亮功能,非常适合制作技术教程、代码走查和解释性内容。与 Remotion 相比,Motion Canvas 更侧重于教育和解释类场景,拥有更流畅的实时编辑体验和内置的音频同步支持。它通过 `yield*` 关键字驱动动画,支持顺序、并行和链式动画编排,并有丰富的组件库和文档支持。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ever-just/agentskills/tree/HEAD/skills/motion-canvas

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

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 打开编辑器

场景

每个动画由多个场景组成。场景是一个生成器函数:

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); // 在 2 秒内从 0 动画到 1

缓动

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

最佳实践

  1. 使用 ref 作为动画目标: 对需要动画的节点使用 createRef<Circle>()
  2. 基于生成器的流程: 按顺序思考 —— yield* 就是你的时间线
  3. 使用 all() 实现并行: 将同时进行的动画分组
  4. 信号用于响应式数据: 多个节点依赖的数值使用信号
  5. 使用 Layout 组件实现 Flexbox: 自动定位子元素
  6. 保持场景简洁: 将长动画拆分为多个场景
  7. 使用编辑器: 实时预览和拖动时间轴非常有用

何时使用 Motion Canvas 与 Remotion

Motion CanvasRemotion
最佳用途教育、解说产品、营销
动画风格命令式 (生成器)声明式 (React)
编辑器内置实时编辑器Remotion Studio
代码动画一等支持手动实现
生态系统正在成长庞大 (npm 包)
语音同步内置音频同步手动同步

来源

  • 仓库: github.com/motion-canvas/motion-canvas
  • 文档: motioncanvas.io/docs
  • 示例: motioncanvas.io/docs/examples

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

ever-just/agentskills

> Declarative animations for React. Springs, gestures, layout animations, and page transitions. GPU-accelerated, production-ready.

ever-just/agentskills

> Create animated logos, icons, and micro-interactions as lightweight Lottie JSON files. No After Effects needed — build animations entirely in code.

ever-just/agentskills

> Add animated subtitles and captions to Remotion videos from .SRT files. TikTok-style word-by-word highlights, karaoke effects, and more.

ever-just/agentskills

> Create videos programmatically using React components. The most mature framework for code-driven video production.

ever-just/agentskills

> Copy-paste video components for Remotion. Intros, text effects, transitions, and full scene templates. Like shadcn/ui but for video.

ever-just/agentskills

Extract actionable intelligence from video content across YouTube, Vimeo, and company websites. Video reveals what text sources cannot: facility scale, team composition, product demonstrations, signage, event attendance, and operational reality.

ever-just/agentskills

Optimize and embed an existing video as a fast, crisp, autoplaying hero/background/loop on a website. Use when adding or replacing a video on a marketing site and it is too heavy, will not autoplay (especially on mobile/Safari), shows a codec error, or looks soft — to transcode it to web-safe H.264 with the right pixel format, faststart, retina-aware sizing, and a poster frame, then embed and verify it actually plays. This is optimization + embedding of footage you already have, not creating/animating a video (for that use remotion/moviepy/motion-canvas). Use when the user says "add this video to the site", "the hero video is too big / won't play / isn't crisp", "replace the homepage video", or "make this loop on the landing page".

ever-just/agentskills

Full conversion audit for any homepage or landing page. Use when someone asks to "review my homepage," "audit my landing page," "why isn't my page converting," "check my website," or wants feedback on their marketing page. Requires URL or screenshot before proceeding.

ever-just/agentskills

Automatically fetch YouTube video transcripts, generate structured summaries, and send full transcripts to messaging platforms. Detects YouTube URLs and provides metadata, key insights, and downloadable transcripts.

相关技能