Communitygithub.com

yazzang-homelab/motion-studio

使用 lib/motion.js 中的閉合形式彈簧,讓動態更具物理感:提供預設集、springFromFeel、用於多目標數值的 track()、循環 loopTrack、指示器與文字切換。適用於「感覺線性」、「添加彈跳」、「將緩動轉換為彈簧」等情境。

motion-studio 是什麼?

這個 AI 助手技能專注於實現 iOS/macOS 風格的物理彈簧動畫,用於開發工具如 Claude Code、Cursor 或 Codex 中,支援 npm 專案且不限定特定平台。其核心 API 圍繞 `lib/motion.js` 中的閉合形式彈簧函式,這些函式時間上是確定性的,無須模擬過往影格即可計算精確狀態。開發者可以使用 `sp()`、`spring()` 與 `track()` 等函式,將基於時間的彈響應用於動畫,視覺上能產生加速、輕微超調與自然緩衝的效果,避免了傳統線性內插或簡單緩動曲線的僵硬感。此技能也包含 `loopTrack()` 以實現無縫循環動畫、`indicator()` 實現可伸縮的標籤指示器,以及 `swapAlpha()` 實現文字容器變形時的透明度切換。設計師可以透過 `springFromFeel()` 使用 Apple 慣例的「持續時間-彈跳」參數,而技術用戶則可直接操作剛度(k)、阻尼(d)與質量(m)參數。此外,技能還提供預設集(如 `snappy`、`default`、`heavy`、`playful`),每組預設集都對應特定的阻尼比、超調量與穩定時間,以便在不同 UI 元素(按鈕、卡片、大型字體或吉祥物)上快速套用。系統還提供重構提示,能自動將既有線性內插或簡易緩動轉換為這些彈簧對應,並透過 lint 工具與逐格分析確保動畫品質。

相容平台✓Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/yazzang-homelab/motion-studio/tree/HEAD/skills/springs

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

彈簧(課程步驟 08)

簡單的運動緩動是在固定曲線上從 A 到 B。而帶有質量的運動會加速、稍微超調後再穩定下來。lib/motion.js 中的彈簧是閉合形式的階躍響應,因此它們始終是時間的純函數:第 812 影格可以直接渲染,無須模擬第 0 到第 811 影格,且 seek(t) 保持確定性。

從影片專案的 lib/motion.js 中匯入(路徑相對於檔案:從 film/film.js 為 ../lib/motion.js,從 film/scenes/*.js 為 ../../lib/motion.js)。完整的預設數值位於 ${CLAUDE_SKILL_DIR}/references/presets.md(references/presets.md)。

1. API

函式回傳值說明
sp(t, preset = 'default')0 到 1日常調用;t 是釋放以來的時間(lt - 0.2),釋放前為 0
spring(t, k, d, m = 1) / springVel(...) / springPV(...)x / v / [x, v]原始 k/d 形式;精確處理欠阻尼、臨界阻尼與過阻尼
SPRINGS{ snappy, default, heavy, playful }{k, d} 配對,見下方表格
resolveSpring(p){k, d}接受預設名稱、{k, d} 或 {duration, bounce},用於任何需要彈簧的地方
springFromFeel({ duration, bounce }) / feelFromSpring({k, d}){k, d} / {duration, bounce}設計師友善的參數(Apple 慣例)
track(t, keys, spring = 'default') / trackVel(...)數值 / 速度keys = [[時間, 數值], ...] 已排序;每次變化使用一個彈簧,結果疊加;可選的第三個元素可為該次變化覆蓋彈簧([2.4, 420, 'heavy'])
loopTrack(t, keys, dur, spring = 'default', cycles = null)數值無縫循環。關鍵幀時間在一個週期內,即 0..dur,且不會被包裝(超出會拋錯)。最後一個數值必須等於第一個。恰好位於 dur 的關鍵幀是接縫變化
indicator(t, stops, { width = 120, lead = 'snappy', trail = {k: 140, d: 22} }){ left, right }可伸縮的標籤指示器:邊緣使用不同的彈簧
swapAlpha(t, tIn, tOut, { inDelay = 0.08, inDur = 0.12, outLead = 0.1, outDur = 0.1 })0 到 1變形框內部的文字:在變形開始後淡入,在下一個變形前淡出
stagger(i, step = 0.03)秒項目 i 的延遲
stepTime(t, rate = 12)階梯式 t僅用於繪圖的「二步動畫」,從不用於攝影機或全域淡出。傳入 c.frameLt(或 c.frameT)即輸出影格的時間,可獲得步驟間的硬切換;c.t / lt 是子影格時間,會在步驟變化的影格上混合兩個步驟
loopT(t, dur)包裝到 [0, dur) 的 t時間包裝;單獨使用不足以處理彈簧(請使用 loopTrack)
settleTime(spring, eps = 0.01) / overshoot(spring)秒 / 比例規劃停留點與切點
easeOutCubic, easeInOutCubic0 到 1僅用於非物理的淡出(透明度);絕不用於會移動的物體

2. 預設集

預設k / d阻尼比超調量穩定時間 (1%)用途
snappy320 / 300.8390.79%0.24 秒按鈕、切換開關、領先邊緣、游標
default170 / 260.99700.51 秒卡片、容器、攝影機
heavy90 / 201.05400.78 秒大字體、3D 物體、標誌組合
playful220 / 140.47218.6%0.59 秒吉祥物、貼紙

內部規則:UI 上使用微量超調(snappy),字體上不使用超調(主標題的縮放與位置使用 default 或 heavy),playful 僅在超調本身是趣味點時使用。完整數值、感覺轉換與公式:references/presets.md。

3. 配方

在場景內部 draw(g, lt, c) 中:lt 是場景開始以來的時間,c.t 是影片時間,c.L 是佈局,c.brand 是品牌標記,c.grid 是節拍網格,c.film.dur 是影片長度(c.dur 是場景長度)。啟用動態模糊時,c.t 和 lt 是目前正在繪製的子影格時間(動態模糊會自行處理);c.frameT / c.frameLt 是輸出影格的時間,c.frame 是其索引,對於每個子影格都相同。程式碼片段假設 const { t, L } = c; 以及從 lib/motion.js、lib/draw.js 和 lib/rng.js 匯入。

一次性入場(在場景開始後 0.15 秒釋放):

const s = sp(lt - 0.15, 'snappy');
withTransform(g, { x: L.cx, y: lerp(L.cy + 80 * L.u, L.cy, s), s: lerp(0.92, 1, s) }, () => { /* 繪製 */ });

這個寫法一開始就可見:當彈簧為 0 時,位置與縮放都處於起始數值,因此第 0 影格不會是空的。如果 s 透過透明度或裁剪來驅動畫面上唯一的東西,第 0 影格就會是空的。對於一個從第 0 影格就出現在畫面上的場景(鉤子),可以在場景之前就釋放彈簧以在中間動作中打開:sp(lt + 0.3, 'snappy'),或使用 kinetic(g, 'MAKE IT MOVE.', x, y, lt + 0.3, { ... }),或 kinetic(..., { delay: -0.3 })。當 lt = 0 時,文字已經在其上升過程中經歷了 0.3 秒,而非尚未繪製(kinetic 會跳過所有彈簧仍為 0 的字形)。審查工具會將空白的第 0 影格標記為 P0 級問題(frame 0 is nearly empty)。

一個具有多個目標的數值(永遠不要重新啟動彈簧;每次變化新增一個):

// 游標 x 以邏輯像素為單位:靜止於 200,在 1.0 秒和 2.4 秒移動,在 3.6 秒返回
const cx = track(t, [[0, 200 * L.u], [1.0, 640 * L.u], [2.4, 420 * L.u], [3.6, 200 * L.u]], 'snappy');

第一個關鍵幀的時間被忽略:其數值是從一開始的靜止數值。之後的每次變化都會在自己的時間啟動自己的彈簧,即使在前一個目標尚未穩定時新目標就到達,總和仍然保持位置與速度的連續性。

單一形狀的變形(容器永不中斷;每個屬性都是相同關鍵幀時間上的 track):

const K = [0, 1, 2, 3].map((n) => c.grid.bar(n));       // 狀態變化發生在強拍上,從網格取得
const w = track(t, [[K[0], 320], [K[1], 120], [K[2], 760], [K[3], 320]].map(([k, v]) => [k, v * L.u]));
const h = track(t, [[K[0], 96], [K[1], 120], [K[2], 480], [K[3], 96]].map(([k, v]) => [k, v * L.u]));
const r = track(t, [[K[0], 48], [K[1], 60], [K[2], 32], [K[3], 48]].map(([k, v]) => [k, v * L.u]));
fillRoundRect(g, L.cx - w / 2, L.cy - h / 2, w, h, Math.max(0, r), c.brand.colors.fg);
withAlpha(g, swapAlpha(t, K[1], K[2]), () => ring(g, L.cx, L.cy, 36 * L.u, sp(t - K[1] - 0.1), { color: c.brand.colors.accent }));

顏色:用彈簧產生一個 0 到 1 的進度,然後用 lib/draw.js 中的 mixColor(a, b, p) 混合(它會限制 p 的範圍);或者,對於有多個目標的顏色,追蹤每個通道並限制在 0 到 255 之間。可能超調到低於零的半徑與尺寸需要使用 Math.max(0, ...)。

在停止點之間伸展的標籤指示器:

const { left, right } = indicator(t, [[0, x0], [1.5, x1], [3.0, x2]], { width: 140 * L.u });
fillRoundRect(g, left, y, right - left, 6 * L.u, 3 * L.u, c.brand.colors.accent);

無縫循環(數值與其速度在接縫處匹配):

// 6 秒循環:a 靜止,b 在 1.5 秒,c2 在 3 秒,回到 a 在 4.5 秒
const x = loopTrack(t, [[0, a], [1.5, b], [3, c2], [4.5, a]], c.film.dur, 'default');
// 相同的循環,但將返回設為接縫變化:最後一個關鍵幀正好位於 dur
const y = loopTrack(t, [[0, a], [1.5, b], [3, c2], [c.film.dur, a]], c.film.dur, 'default');

loopTrack 的規則(已根據 lib/motion.js 檢查):

規則詳細說明
關鍵幀時間保持在 0..dur 內它們是相對於週期的,永遠不會被包裝;超出範圍的時間會拋出 loopTrack: key <i> time <t> is outside 0..<dur>(來自網格運算的微小超出 dur 是可以容忍的)
第一個關鍵幀是靜止數值其時間被忽略(但仍必須位於 0..dur 內);該數值是第一次變化開始的基準
最後一個數值等於第一個否則會拋出 the last value (...) must equal the first (...)
位於 dur 的關鍵幀是接縫變化彈簧在下一個週期的 t = 0 時啟動:第 0 影格(= 第 dur 影格)顯示接縫前的數值,然後緩動到第一個數值。這等同於寫 [[0, pre], [0, post], ...]。將接縫變化寫一次,在 0 或 dur 處皆可
恰好在 dur 之前的變化可能在第 0 影格仍在移動總和是完全週期性的,因此無論時機如何,位置和速度在接縫處都匹配。若要在靜止影格上開啟,請確保最後一次變化距離 dur 至少 settleTime(preset) 的時間(default 為 0.51 秒)
循環次數疊加的先前週期數取決於穩定時間與最新的關鍵幀,因此較晚的關鍵幀是安全的;cycles 會覆蓋此設定

單純使用 loopT 加上 track 會在接縫處跳動,因為在末尾附近釋放的彈簧在 t = 0 時仍在移動。loopTrack 也會疊加先前週期中的彈簧(足夠多的週期以使其穩定),並且在使用關鍵幀 [[0, 0], [2, 100], [4, 40], [6, 0]] 與 dur 為 6 時,會在 t = 1 / 3 / 5 時給出數值 0.001 / 99.997 / 40.002。在執行 npm run critique 後檢查 out/review/<fmt>/loop.png:|last - first| 應看起來像一個正常的步驟,而 |end - first|(未包裝的結束狀態)應為黑色。

交錯彈出(每個元素有自己的隨機種子,絕不共用一個串流):

for (let i = 0; i < n; i++) {
  const r = rngFor('tile', i);
  const s = sp(lt - stagger(i, 0.035) - range(r, 0, 0.06), 'playful');
  // 繪製按 s 縮放的 tile i
}

動態文字:kinetic(g, str, x, y, lt, { size, family, weight, color, spring: 'snappy', stagger: 0.035, rise: 0.6, by: 'char' | 'word', mask, delay, alpha, align, baseline, style, tracking })。family 預設為 brand.fonts.display,weight 預設為該字體系列已註冊的最接近字重,因此除非設計需要其他字體,否則請省略這兩項。mask: true 會將文字行裁剪到其行框內,這樣字形會從邊緣後方升起,而不是淡入;delay 會平移整個文字行(負數表示在中間動作中開啟)。對於主標題文字,當上升幅度足夠大以至於 0.8% 的超調可見時,請傳入 spring: 'default' 或 'heavy'。多行文字:wrapText(g, text, maxW, font(size, family)) 會回傳各行(絕不會在韓文字節內部切割);使用 y + i * 1.2 * size 或更大的間距來繪製它們,並為每一行提供自己的 delay。

二步動畫(手繪外觀):const td = stepTime(c.frameLt, 12) 用於繪圖本身的動畫(使用輸出影格的時間,因此即使啟用動態模糊,每個步驟都是硬切換);讓攝影機移動、淡出和 UI 保持在連續的 lt 上,否則平移每秒會步進 12 次,看起來像是延遲。

4. 重構整個影片

使用專案中的提示範本:閱讀 prompts/refactor-springs.txt 並遵循它(或將其作為任務貼上)。它會將所有移動物體的線性內插與標準緩動替換為預設集、track()、loopTrack()、indicator() 和 swapAlpha(),保持時間不變,並報告每次變更。然後:

  1. npm run lint(必須無錯誤)。
  2. npm run stills 和 node tools/critique.mjs --strip-at <t> 在動畫最密集的時刻:strip.png 會顯示 12 個連續影格,這能揭露連環圖所隱藏的跳動、重啟和滑動。
  3. 在下一次審查輪次中記錄變更(/motion-studio:critique-loop)。

5. 需避免的錯誤

錯誤現象修復方式
每次目標都重新啟動彈簧(從舊數值 sp(t - tNew))速度瞬間變為 0,出現可見的拐點使用包含所有目標的 track()
對帶有各自起始數值的彈簧進行手動疊加求和兩個變化重疊時產生跳動每個數值使用一個 track();每個變化的預設集寫在關鍵幀的第三個元素中
對彈簧數值單獨使用 loopT接縫處跳動使用 loopTrack(),關鍵幀在 0..dur 內且最後數值等於第一個
字體使用超調文字晃動,看起來廉價字體使用 default / heavy
UI 飾框使用 playful介面像玩具UI 使用 snappy
僅對透明度使用彈簧,位置保持線性淡出效果不錯,但滑動很廉價對位置使用彈簧;透明度可以跟隨 easeOutCubic
所有元素使用相同的預設集與延遲機械化,缺乏層次感讓「snappy」引領,「default」跟隨,其餘使用 stagger()

下一步:/motion-studio:sound-design 將動態鎖定到節拍,然後 /motion-studio:critique-loop。

Individual skills in this repo

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

yazzang-homelab/motion-studio

Make Claude watch its own frames: critique.mjs evidence, harsh 7-axis scores, timestamped P0/P1/P2 problems in docs/review_log.md, fix the 3 worst, re-check, pass the gate. Use for 'critique it', 'review the frames', 'is it good'.

yazzang-homelab/motion-studio

Plan long-form or overnight films: director's brief (PLAN FIRST or GO, budget, definition of done), ANIMATION_GUIDE + STORYBOARD, chapter subagents, gates, chunked render. Use for 'overnight film', 'music video', '2-minute film'.

yazzang-homelab/motion-studio

Make a launch video, app or product reel, explainer or motion ad from code, end to end: brand assets from a URL, beat-grid shot list, synced sound, critique loop, all formats. Default for new video requests; not footage edits.

yazzang-homelab/motion-studio

Brand-asset stage of a product film (motion-reel runs the whole film): capture real screenshots, logo, colors and fonts from a URL, never redraw UI; brand story beats; voice + mascot. Use to grab or fix a brand's assets.

yazzang-homelab/motion-studio

Turn a reference (a frame, a video or an image library) into docs/style_guide.md and a beat-grid shot list: measure cuts, palette and pace, take grammar not content, wait for OK. Use when the user supplies or names a look.

yazzang-homelab/motion-studio

Build, debug or speed up the seek(t) render engine: render contract, canvas vs page capture, workers/subframes/chunks, determinism fixes, Remotion or HyperFrames handoff. Use for 'render is slow', 'frames differ', 'use Remotion'.

yazzang-homelab/motion-studio

Ship every format from one timeline, then package it: layout() reframing (never crop), render all formats, per-format checks, deliver.mjs, a brand skill, a service offer. Use for 'export 9:16 and 16:9', 'deliver', 'make a skill'.

yazzang-homelab/motion-studio

The viral one-line 'showreel for a résumé' prompt: why it works (anatomy), the credited quote, and seeded variants that avoid look-alike reels; runs it as an engine test. Use for that prompt, its variations, or a showreel.

yazzang-homelab/motion-studio

Score a film to its beat grid: measure a track (beats.mjs) or synthesize one (score.mjs), cue SFX from the film, add voice, mix to -14 LUFS / -1 dBTP at exact length. Use for 'add music', 'sync to the beat', 'SFX', 'loudness'.

yazzang-homelab/motion-studio

Scaffold a motion-studio film project (seek(t) renderer, springs, beat grid, synthesized sound, critique tools), install it, set up the browser, run doctor. Use for 'set up the motion studio', 'new film project', 'init studio'.

yazzang-homelab/motion-studio

Write a six-part XML state spec for a one-shape UI morph film (inputs, direction, structure, build, gotchas, start): states on downbeats, cursor-driven changes, seamless loop, approval gate. Use for 'UI morph', 'state list'.

相關技能