Skip to content

A toolbox of film styles made in code for Claude Code: 66 ready to use, and your own. Each style is a style prompt plus a demo film made entirely in code by Claude Opus 5.5, with no video model. By Lemomo. · 一套用代码做片的风格工具箱:66 种现成风格,也能做出你自己的

1.8 KB
Raw Blame
// Jointed cut-out skeleton: 2D affine matrix [a,b,c,d,e,f] (same order as canvas setTransform)
import { drawPiece, paperShadow, noShadow, transmitOf } from './paper.js';
export const mul = (A, B) => [A[0] * B[0] + A[2] * B[1], A[1] * B[0] + A[3] * B[1], A[0] * B[2] + A[2] * B[3], A[1] * B[2] + A[3] * B[3], A[0] * B[4] + A[2] * B[5] + A[4], A[1] * B[4] + A[3] * B[5] + A[5]];
export const T = (x, y) => [1, 0, 0, 1, x, y];
export const R = a => [Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0];
export const S = (sx, sy = sx) => [sx, 0, 0, sy, 0, 0];
export const ap = (M, p) => [M[0] * p[0] + M[2] * p[1] + M[4], M[1] * p[0] + M[3] * p[1] + M[5]];
export const scaleOf = M => Math.sqrt(Math.abs(M[0] * M[3] - M[1] * M[2]));
export const I = [1, 0, 0, 1, 0, 0];

// draw one piece: M = piece local→screen; opt.shadow (paper-shadow strength, 0 = no shadow)
export function put(g, p, M, opt = {}) {
  g.save(); g.setTransform(M[0], M[1], M[2], M[3], M[4], M[5]);
  if (opt.alpha != null) g.globalAlpha = opt.alpha;
  if (opt.shadow !== 0) paperShadow(g, scaleOf(M) * (opt.shadowScale || 1), opt.shadow ?? 1, opt.shadowCol); else noShadow(g);
  if (opt.filter) g.filter = opt.filter;
  g.drawImage(opt.img || p.c, p.x0, p.y0, p.w, p.h);
  g.restore();
}
// skeleton: parts = [{name, parent, at:[x,y] (joint position in parent coordinates), piece, ang:key, z}]
// returns the matrix table of all parts (used for rivet markers and prop attachment points)
export function solveRig(parts, root, pose) {
  const Ms = {};
  for (const p of parts) {
    const base = p.parent ? Ms[p.parent] : root;
    const a = (pose[p.ang] || 0) + (p.a0 || 0);
    let M = mul(base, T(p.at[0], p.at[1]));
    M = mul(M, R(a));
    if (p.flipKey && pose[p.flipKey]) M = mul(M, S(-1, 1));
    Ms[p.name] = M;
  }
  return Ms;
}