- Home
- Skills
- Frontend & Web Apps
- html whiteboard demo
More screenshots
Works with the AI Agents you already use
html whiteboard demo
Provide the source HTML. The Agent will analyze the real interaction and the code, and generate a whiteboard explanation page suitable for demonstrations and screen recordings, as well as an SRT subtitle file with the same time axis.
Free
html whiteboard demo
Example session with this skill installed
使用 $html-whiteboard-demo,将这个 HTML 制作为白板代码讲解 Demo,
并生成同步 SRT 字幕:/你的路径/demo.html
- Read your context and instructions
- Compiled the html whiteboard demo
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>下雪堆积 · 白板讲解</title>
<style>
* { box-sizing: border-box; }
:root { color-scheme: dark; font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif; background: #0e1d28; color: #e4ece5; --demo-hud-safe: 72px; --demo-caption-rail: 132px; --demo-safe-gap: 26px; }
body { margin: 0; overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid #dbb47e; outline-offset: 5px; }
button { border: 1px solid #a8bcb754; background: #c4d8c80b; padding: 10px 19px; border-radius: 7px; font-size: 13px; }
button:hover { background: #d0e1d021; }
button:disabled { opacity: .4; cursor: wait; }
.stage { position: absolute; left: 50%; top: 50%; width: 1920px; height: 1080px; transform-origin: center; overflow: hidden; background: #182e3e; }
.stage.paper { background: #f3ead8; color: #485646; }
.hud { position: absolute; inset: 0 0 auto; height: var(--demo-hud-safe); display: flex; align-items: center; justify-content: space-between; padding: 0 80px; font-size: 20px; letter-spacing: 3px; color: #adbfba; }
.paper .hud { color: #a79a7d; }
.chapter { font-size: 18px; letter-spacing: 3px; }
.content { position: absolute; inset: var(--demo-hud-safe) 0 var(--demo-caption-rail); overflow: hidden; }
.scene { position: absolute; inset: 0; opacity: 0; visibility: hidden; }
.scene.visible { visibility: visible; }
#effect-viewport { transform-origin: 74% 62%; width: 1920px; height: 876px; }
#effect-canvas { display: block; width: 1920px; height: 876px; }
.effect-note { position: absolute; top: 32px; left: 80px; font-size: 22px; letter-spacing: 2px; color: #d0dfd394; }
.effect-question { position: absolute; left: 140px; top: 135px; font-family: "Songti SC", serif; font-size: 62px; font-weight: 400; line-height: 1.5; letter-spacing: 5px; color: #e4eade; text-shadow: 0 2px 22px #182e3e; }
#principle { background: radial-gradient(#9d94741a 1px, transparent 1px), #f3ead8; background-size: 26px 26px; }
.board-title { position: absolute; left: 100px; top: 39px; margin: 0; font-family: "Songti SC", serif; font-size: 49px; font-weight: 500; letter-spacing: 3px; }
#whiteboard { width: 1920px; height: 876px; display: block; }
.draw-group { opacity: 0; }
.draw-group .ink { stroke: #65735e; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.draw-group text { font-family: "PingFang SC", sans-serif; fill: #71664e; font-size: 28px; }
.draw-group .small-label { font-size: 22px; fill: #a18c65; }
.draw-group .node-title { font-size: 31px; font-weight: 500; }
#pen { fill: #bc8054; stroke: #fbf3df; stroke-width: 4; opacity: 0; }
#code-intro { background: #f3ead8; display: flex; flex-direction: column; align-items: center; justify-content: center; padding-bottom: 20px; }
.title-kicker { font-size: 24px; letter-spacing: 7px; color: #a78f69; }
#intro-title { font-family: "Songti SC", serif; font-weight: 500; font-size: 83px; letter-spacing: 6px; margin: 28px 0 30px; color: #536951; }
#intro-rule { width: 400px; height: 2px; background: #b8aa84; transform-origin: left; }
#intro-subtitle { font-size: 30px; color: #9e9072; margin-top: 27px; letter-spacing: 5px; }
#code-scene { background: #f3ead8; }
#code-heading { position: absolute; top: 38px; left: 95px; margin: 0; font-family: "Songti SC", serif; font-size: 49px; font-weight: 500; letter-spacing: 2px; }
.code-panel { position: absolute; top: 170px; left: 80px; width: 1170px; height: 538px; background: #203745; border: 1px solid #364d54; border-radius: 14px; overflow: hidden; box-shadow: 0 14px 35px #3e49351a; }
.code-meta { height: 73px; padding: 24px 35px; border-bottom: 1px solid #aec9bc1f; color: #a5beb7; font-size: 21px; letter-spacing: 1px; }
#code-lines { margin: 39px 0 0; }
.code-line { position: relative; min-height: 66px; display: flex; gap: 24px; align-items: center; padding: 7px 25px 7px 18px; color: #829c9f; border-left: 4px solid transparent; font: 30px/1.65 "Menlo", "Consolas", monospace; white-space: pre; }
.code-line.active { background: #d8c28f15; border-color: #d4b57a; color: #f0e8cc; }
.line-no { font: 19px/1 "Menlo", monospace; min-width: 53px; text-align: right; color: #7791927a; user-select: none; }
.token-keyword { color: #b4cba4; }
.token-function { color: #dbbc83; }
.code-line:not(.active) .token-keyword, .code-line:not(.active) .token-function { color: inherit; }
#code-omitted { position: absolute; left: 34px; right: 30px; bottom: 24px; margin: 0; color: #7b9696; font-size: 20px; letter-spacing: 1px; white-space: pre-line; line-height: 1.65; }
#code-focus { position: absolute; left: 103px; top: 756px; font-size: 30px; color: #967947; padding-left: 21px; border-left: 3px solid #b79765; }
.code-result { position: absolute; right: 80px; top: 160px; width: 510px; height: 650px; background: #e9dfc9; border: 1px solid #c7ba9b; border-radius: 14px; }
.result-label { position: absolute; left: 28px; top: 22px; font-size: 22px; letter-spacing: 2px; color: #9a8764; }
#code-visual { width: 510px; height: 650px; display: block; }
.caption-rail { position: absolute; left: 120px; right: 120px; bottom: var(--demo-safe-gap); min-height: 78px; display: flex; align-items: center; justify-content: center; text-align: center; pointer-events: none; }
#caption { margin: 0; font-size: 38px; font-weight: 450; line-height: 1.45; letter-spacing: 1.2px; max-width: 1640px; white-space: pre-line; color: #e7eee4; }
.paper #caption { color: #4c5947; }
#caption:empty { display: none; }
.preparation, .end-screen { position: fixed; z-index: 20; inset: 0; display: flex; justify-content: center; align-items: center; background: #0d2230eb; backdrop-filter: blur(15px); }
.preparation[hidden], .end-screen[hidden] { display: none; }
.prep-card { width: min(600px, calc(100% - 36px)); border: 1px solid #a6bbb548; border-radius: 16px; padding: 34px; background: #19323fd9; box-shadow: 0 20px 80px #091e2c55; }
.prep-card small { font-size: 10px; letter-spacing: 3px; color: #a8bcb2; }
.prep-card h1, .end-card h2 { margin: 18px 0 12px; font-family: "Songti SC", serif; font-size: 33px; font-weight: 500; letter-spacing: 2px; }
.prep-card p { color: #9ab2b2; font-size: 12px; line-height: 2; margin: 10px 0; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 19px 0; }
.facts span { font-size: 10px; letter-spacing: 1px; border: 1px solid #a6bbb52e; border-radius: 20px; padding: 7px 11px; color: #a6bdb7; }
.settings { display: flex; gap: 16px; align-items: center; margin: 21px 0; font-size: 12px; color: #bbcec1; }
input { accent-color: #c6cba8; }
.prep-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.primary { background: #bac6ac; color: #253d40; border-color: #bac6ac; }
.primary:hover { background: #d1d8bb; }
#ready-note { min-height: 24px; font-size: 10px; color: #879f9f; }
.preview-controls { position: fixed; z-index: 12; bottom: 10px; left: 50%; transform: translateX(-50%); width: min(770px, calc(100% - 32px)); display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid #a6bbb533; border-radius: 10px; background: #15303ddf; }
.preview-controls[hidden] { display: none; }
.preview-controls button { font-size: 10px; padding: 7px 11px; white-space: nowrap; }
progress { width: 100%; min-width: 30px; height: 4px; accent-color: #c4cca8; }
#timecode { font: 10px "Menlo", monospace; white-space: nowrap; color: #b2c5bc; }
.countdown { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; pointer-events: none; color: #f0ead0; font: 110px "Songti SC", serif; background: #10263599; }
.countdown[hidden] { display: none; }
.end-screen { background: #102c3be8; }
.end-card { text-align: center; padding: 35px; }
.end-card p { color: #a5bcb6; font-size: 12px; margin-bottom: 25px; }
body.record-mode .preview-controls, body.record-mode .hud, body.record-mode .end-screen { display: none !important; }
body.record-mode, body.record-mode * { cursor: none !important; }
body.record-mode.preparing, body.record-mode.preparing * { cursor: auto !important; }
@media(max-width:600px) { .prep-card { padding: 25px; } .prep-card h1 { font-size: 28px; } .preview-controls { gap: 6px; } .preview-controls button { padding: 7px; } }
</style>
</head>
<body class="preparing">
<main class="stage" id="stage" aria-label="下雪堆积的白板讲解画幅">
<header class="hud"><span>落雪之后,雪去了哪里?</span><span id="chapter" class="chapter"></span></header>
<div class="content">
<section class="scene" id="effect">
<div id="effect-viewport" data-demo-critical><canvas id="effect-canvas" aria-label="受统一时间线控制的原始下雪堆积效果"></canvas></div>
<span class="effect-note" id="effect-note">积雪过程加速展示</span>
<div class="effect-question" id="effect-question"></div>
</section>
<section class="scene" id="principle">
<h2 class="board-title" data-demo-critical>把一片雪,变成一格厚度</h2>
<svg id="whiteboard" viewBox="0 0 1920 876" role="img" aria-label="雪花下落、接触表面、厚度小格与新雪面的逐步原理图">
<g id="board-flake" class="draw-group"><path class="ink" d="M350 155V245M311 177L389 223M311 223L389 177" fill="none" style="stroke:#789994"/><path class="ink" d="M335 164L350 179L365 164M335 236L350 221L365 236" fill="none" style="stroke:#789994"/><path class="ink" d="M312 192L329 188L329 173M388 208L371 212L371 227" fill="none" style="stroke:#789994"/><text x="350" y="285" class="" text-anchor="middle">空中的雪花</text></g>
<g id="board-fall" class="draw-group"><path class="ink" d="M359 290Q380 307 399 327L429 356M417 351L429 356L427 343" fill="none"/><rect class="ink" x="1230" y="150" width="510" height="118" rx="12" fill="#efe4cc"/><text x="1260" y="195" class="node-title" text-anchor="start">每一帧,往下走一点</text><text x="1260" y="234" class="small-label" text-anchor="start">更新粒子的位置</text></g>
<g id="board-roof" class="draw-group"><path class="ink" d="M210 514L420 350L638 514" fill="none" style="stroke:#a88b62"/><text x="240" y="550" class="small-label" text-anchor="start">接住它的表面</text></g>
<g id="board-hit" class="draw-group"><circle class="ink" cx="444" cy="368" r="25" fill="#ddbc8b"/><path class="ink" d="M461 383L513 420M503 418L513 420L509 409" fill="none" style="stroke:#bd8c52"/><text x="590" y="434" class="" text-anchor="middle">命中落点</text><rect class="ink" x="1230" y="375" width="510" height="118" rx="12" fill="#efe4cc"/><text x="1260" y="420" class="node-title" text-anchor="start">碰到表面,记录落点</text><text x="1260" y="459" class="small-label" text-anchor="start">从空中粒子,转成雪层厚度</text></g>
<g id="board-grid" class="draw-group"><rect class="ink" x="180" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="267" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="354" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="441" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="528" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="615" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="702" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="789" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="876" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><rect class="ink" x="963" y="600" width="80" height="135" rx="2" fill="#f7efdc"/><text x="610" y="795" class="" text-anchor="middle">把接雪面切成小格,每格记一个厚度</text></g>
<g id="board-link" class="draw-group"><path class="ink" d="M509 449Q580 483 568 576M558 562L568 576L578 562" fill="none" style="stroke:#bd8c52"/></g>
<g id="board-bars" class="draw-group"><rect class="ink" x="184" y="718" width="72" height="13" rx="2" fill="#b3c5ae"/><rect class="ink" x="271" y="711" width="72" height="20" rx="2" fill="#b3c5ae"/><rect class="ink" x="358" y="697" width="72" height="34" rx="2" fill="#b3c5ae"/><rect class="ink" x="445" y="668" width="72" height="63" rx="2" fill="#b3c5ae"/><rect class="ink" x="532" y="632" width="72" height="99" rx="2" fill="#b3c5ae"/><rect class="ink" x="619" y="657" width="72" height="74" rx="2" fill="#b3c5ae"/><rect class="ink" x="706" y="687" width="72" height="44" rx="2" fill="#b3c5ae"/><rect class="ink" x="793" y="705" width="72" height="26" rx="2" fill="#b3c5ae"/><rect class="ink" x="880" y="711" width="72" height="20" rx="2" fill="#b3c5ae"/><rect class="ink" x="967" y="716" width="72" height="15" rx="2" fill="#b3c5ae"/><text x="578" y="567" class="small-label" text-anchor="middle">厚度增加</text></g>
<g id="board-spread" class="draw-group"><path class="ink" d="M573 557Q539 524 500 555M511 543L500 555L516 555M585 555Q623 522 668 555M652 554L668 555L657 543" fill="none" style="stroke:#b78c57"/></g>
<g id="board-smooth" class="draw-group"><path class="ink" d="M180 718Q242 716 271 711Q320 702 357 691Q404 673 449 656Q491 633 532 632Q578 634 621 660Q666 682 708 698Q800 718 1044 719L1044 735L180 735Z" fill="#cad6bc" style="stroke:#789274"/><text x="623" y="845" class="small-label" text-anchor="middle">邻近厚度摊开,形成平滑边缘</text></g>
<g id="board-output" class="draw-group"><path class="ink" d="M1143 651L1208 651M1194 640L1208 651L1194 662" fill="none"/><rect class="ink" x="1230" y="620" width="510" height="118" rx="12" fill="#efe4cc"/><text x="1260" y="665" class="node-title" text-anchor="start">沿着厚度,画出新的雪面</text><text x="1260" y="704" class="small-label" text-anchor="start">新的落雪,又会落在这层雪上</text></g>
<circle id="pen" cx="0" cy="0" r="9"/>
</svg>
</section>
<section class="scene" id="code-intro">
<span class="title-kicker">从看见,到看懂</span>
<h2 id="intro-title" data-demo-critical></h2>
<div id="intro-rule"></div>
<p id="intro-subtitle"></p>
</section>
<section class="scene" id="code-scene">
<h2 id="code-heading" data-demo-critical></h2>
<div class="code-panel" data-demo-critical>
<div class="code-meta" id="code-meta"></div>
<div id="code-lines"></div>
<p id="code-omitted"></p>
</div>
<div id="code-focus" data-demo-critical></div>
<div class="code-result" data-demo-critical><span class="result-label">对应的画面变化</span><canvas id="code-visual" width="1020" height="1300"></canvas></div>
</section>
</div>
<div class="caption-rail" id="caption-rail"><p id="caption" aria-live="off"></p></div>
</main>
<section class="preparation" id="preparation">
<div class="prep-card">
<small>下雪堆积 · 开发入门讲解</small>
<h1>雪落下来,如何留下?</h1>
<p>先看积雪,再用白板和两段真实源码解释落点与厚度。</p>
<div class="facts"><span>正文 70 秒</span><span>横屏 16∶9</span><span>画幅 1920 × 1080</span><span>录制准备 3 秒</span></div>
<div class="settings"><label><input type="checkbox" id="captions-on" checked> 显示页面字幕</label><button id="fullscreen">进入全屏</button></div>
<p>预览保留控制。录屏模式会隐藏控制和鼠标指针。<br>播放时空格暂停或继续,退出录屏按 Esc。</p>
<p>请手动启动系统录屏。正文前的等待和倒计时需剪掉。<br>本页没有配音,字幕文件从正文第一帧开始计时。</p>
<div class="prep-buttons"><button class="primary" id="start-preview" disabled>开始预览</button><button id="start-record" disabled>准备录制</button></div>
<p id="ready-note">正在准备绘图和字体…</p>
</div>
</section>
<div class="preview-controls" id="preview-controls" hidden>
<button id="toggle-play">暂停</button><button id="replay">重播</button>
<progress id="progress" max="70000" value="0" aria-label="播放进度"></progress>
<span id="timecode">00:00 / 01:10</span><button id="return-prep">录制设置</button>
</div>
<div class="countdown" id="countdown" hidden aria-live="polite">3</div>
<section class="end-screen" id="end-screen" hidden>
<div class="end-card"><h2>讲解放完了。</h2><p>重看时,原效果、绘线和字幕会一起从头开始。</p><button class="primary" id="end-replay">再看一遍</button><button id="end-settings">准备录制</button></div>
</section>
<script type="application/json" id="demo-storyboard">{"durationMs": 70000, "audience": "beginner", "aspectRatio": "16:9", "logicalWidth": 1920, "logicalHeight": 1080, "countdownMs": 3000, "tailHoldMs": 2000, "source": {"filename": "下雪堆积.html", "sha256": "124e296f1153563854a9810266af9de9fb341c87d745fa8bf59ee9e536f05004", "dependencies": [], "events": ["requestAnimationFrame → updateSnow(dt) → drawScene()"], "adaptation": "复制源码到隔离函数,固定逻辑尺寸、固定随机种子,移除源页面独立时钟,由正文时间统一驱动;开场积雪加速展示。"}, "captions": [{"id": "caption-1", "startMs": 0, "endMs": 3700, "text": "雪落到屋顶和地面,会越积越厚。"}, {"id": "caption-2", "startMs": 3700, "endMs": 7200, "text": "落下的雪,并没有简单地消失。"}, {"id": "caption-3", "startMs": 7200, "endMs": 10000, "text": "程序把这些雪,记在了哪里?"}, {"id": "caption-4", "startMs": 10400, "endMs": 14500, "text": "在空中时,每一帧都让雪花往下走一点。"}, {"id": "caption-5", "startMs": 14500, "endMs": 18200, "text": "碰到屋顶或地面,就把它记进雪层。"}, {"id": "caption-6", "startMs": 18200, "endMs": 22400, "text": "把接雪面切成小格,每格记一个厚度。"}, {"id": "caption-7", "startMs": 22400, "endMs": 26700, "text": "新雪落在哪儿,附近几格就增加一点。"}, {"id": "caption-8", "startMs": 26700, "endMs": 30500, "text": "相邻雪格再互相摊开,边缘就更平滑。"}, {"id": "caption-9", "startMs": 30500, "endMs": 34000, "text": "最后沿着这些厚度,画出新的雪面。"}, {"id": "caption-10", "startMs": 37400, "endMs": 41100, "text": "先看动画更新里,雪花碰到表面的这一刻。"}, {"id": "caption-11", "startMs": 41100, "endMs": 45800, "text": "命中后,把这片雪分给落点附近的小格。"}, {"id": "caption-12", "startMs": 45800, "endMs": 50500, "text": "再移走空中的雪花,避免重复累加。"}, {"id": "caption-13", "startMs": 50900, "endMs": 55000, "text": "接着看绘制循环,每格都算一个雪面位置。"}, {"id": "caption-14", "startMs": 55000, "endMs": 59000, "text": "横向位置用 x 表示,i 是当前这格。"}, {"id": "caption-15", "startMs": 59000, "endMs": 63000, "text": "画布的 y 越小,位置就越靠上。"}, {"id": "caption-16", "startMs": 63000, "endMs": 66500, "text": "原地面减去厚度,雪面就被抬高。"}, {"id": "caption-17", "startMs": 66500, "endMs": 69600, "text": "落点记厚度,厚度再决定新的雪面。"}], "scenes": [{"id": "effect", "phase": "effect", "startMs": 0, "endMs": 10000, "title": "雪落下来,为什么会留下?"}, {"id": "principle", "phase": "principle", "startMs": 10000, "endMs": 34000, "title": "把一片雪,变成一格厚度"}, {"id": "code-intro", "phase": "code", "kind": "title", "startMs": 34000, "endMs": 37000, "title": "雪,是怎么被记住的?", "subtitle": "从落点,到新的雪面"}, {"id": "code-hit", "phase": "code", "kind": "snippet", "startMs": 37000, "endMs": 50500, "title": "碰到表面,就换一种方式留下", "snippetId": "landing"}, {"id": "code-height", "phase": "code", "kind": "snippet", "startMs": 50500, "endMs": 66500, "title": "厚度增加,雪面为什么会升高?", "snippetId": "height"}, {"id": "outro", "phase": "outro", "startMs": 66500, "endMs": 70000, "title": "让落下的雪,留在画面里"}], "actions": [{"id": "draw-flake", "sceneId": "principle", "targetId": "board-flake", "startMs": 10500, "endMs": 12100, "captionId": "caption-4", "sequence": 1, "narrativeRole": "空中粒子", "codeRef": "updateSnow", "kind": "draw"}, {"id": "draw-fall", "sceneId": "principle", "targetId": "board-fall", "startMs": 12100, "endMs": 14100, "captionId": "caption-4", "sequence": 2, "narrativeRole": "逐帧移动", "codeRef": "updateSnow", "kind": "draw"}, {"id": "draw-roof", "sceneId": "principle", "targetId": "board-roof", "startMs": 14600, "endMs": 16000, "captionId": "caption-5", "sequence": 3, "narrativeRole": "接雪表面", "codeRef": "firstLanding", "kind": "draw"}, {"id": "draw-hit", "sceneId": "principle", "targetId": "board-hit", "startMs": 16000, "endMs": 17800, "captionId": "caption-5", "sequence": 4, "narrativeRole": "落点", "codeRef": "firstLanding", "kind": "draw"}, {"id": "draw-grid", "sceneId": "principle", "targetId": "board-grid", "startMs": 18400, "endMs": 20500, "captionId": "caption-6", "sequence": 5, "narrativeRole": "厚度小格", "codeRef": "makeSurface", "kind": "draw"}, {"id": "draw-link", "sceneId": "principle", "targetId": "board-link", "startMs": 20500, "endMs": 22000, "captionId": "caption-6", "sequence": 6, "narrativeRole": "落点映射", "codeRef": "deposit", "kind": "draw"}, {"id": "draw-bars", "sceneId": "principle", "targetId": "board-bars", "startMs": 22600, "endMs": 24600, "captionId": "caption-7", "sequence": 7, "narrativeRole": "增加附近格子", "codeRef": "deposit", "kind": "draw"}, {"id": "draw-spread", "sceneId": "principle", "targetId": "board-spread", "startMs": 24600, "endMs": 26400, "captionId": "caption-7", "sequence": 8, "narrativeRole": "分摊雪量", "codeRef": "deposit", "kind": "draw"}, {"id": "draw-smooth", "sceneId": "principle", "targetId": "board-smooth", "startMs": 26900, "endMs": 29300, "captionId": "caption-8", "sequence": 9, "narrativeRole": "摊平厚度", "codeRef": "settleSurfaces", "kind": "draw"}, {"id": "draw-output", "sceneId": "principle", "targetId": "board-output", "startMs": 30800, "endMs": 32400, "captionId": "caption-9", "sequence": 10, "narrativeRole": "绘制雪面", "codeRef": "drawAccumulation", "kind": "draw"}], "code": {"landing": {"function": "updateSnow(dt)", "startLine": 428, "lines": ["const landing = firstLanding(flake, previousX, previousY);", "if (landing) {", " deposit(landing.surface, landing.x, flake.mass);", " flakes.splice(i, 1);"]}, "height": {"function": "drawAccumulation(surface)", "startLine": 445, "lines": ["for (let i = 0; i \u003c count; i++) {", " const x = surface.start + i * surface.spacing;", " const y = surface.baseAt(x) - surface.snow[i];"]}}, "highlights": [{"sceneId": "code-hit", "startMs": 37400, "endMs": 41100, "lines": [0], "label": "landing 保存命中的表面与落点"}, {"sceneId": "code-hit", "startMs": 41100, "endMs": 45800, "lines": [2], "label": "把雪的份额加入落点附近"}, {"sceneId": "code-hit", "startMs": 45800, "endMs": 50500, "lines": [3], "label": "移走粒子,让它只计入一次"}, {"sceneId": "code-height", "startMs": 50900, "endMs": 55000, "lines": [0], "label": "逐格计算雪面位置"}, {"sceneId": "code-height", "startMs": 55000, "endMs": 59000, "lines": [1], "label": "格子编号 → 横向位置"}, {"sceneId": "code-height", "startMs": 59000, "endMs": 66500, "lines": [2], "label": "地面高度 − 积雪厚度"}], "shots": [{"id": "roof-detail", "sceneId": "effect", "startMs": 0, "endMs": 4500, "purpose": "看清屋顶雪沿与落雪", "targetId": "effect-viewport", "camera": {"scaleFrom": 1.08, "scaleTo": 1.08, "moveMs": 0}}, {"id": "whole-scene", "sceneId": "effect", "startMs": 4500, "endMs": 10000, "purpose": "看清屋顶与地面的关联", "targetId": "effect-viewport", "camera": {"scaleFrom": 1.08, "scaleTo": 1, "moveMs": 600}}], "transitions": [{"sceneId": "effect", "type": "fade", "enterMs": 0, "exitMs": 300}, {"sceneId": "principle", "type": "fade", "enterMs": 400, "exitMs": 300}, {"sceneId": "code-intro", "type": "fade", "enterMs": 400, "exitMs": 300}, {"sceneId": "code-hit", "type": "fade", "enterMs": 400, "exitMs": 300}, {"sceneId": "code-height", "type": "fade", "enterMs": 400, "exitMs": 300}, {"sceneId": "outro", "type": "fade", "enterMs": 400, "exitMs": 0}]}</script>
<script>
function createSnowEffect(targetCanvas) {
let seed = 20261108;
let simulationFrame = 0;
function random() {
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
return seed / 4294967296;
}
'use strict';
const canvas = targetCanvas;
const context = canvas.getContext('2d');
const backdrop = document.createElement('canvas');
const backgroundContext = backdrop.getContext('2d');
const snowfallAmount = .58;
const windSpeed = 9;
const binSize = 3;
const maximumFlakes = 1800;
let width = 0;
let height = 0;
let sceneScale = 1;
let layout = null;
let surfaces = [];
let flakes = [];
let elapsed = 0;
let emission = 0;
function clamp(value, minimum, maximum) {
return Math.max(minimum, Math.min(maximum, value));
}
function mix(a, b, amount) {
return a + (b - a) * amount;
}
function makeSurface(id, start, end, baseAt, kind, maxDepth) {
const count = Math.max(3, Math.ceil((end - start) / binSize) + 1);
return {
id, start, end, baseAt, kind, maxDepth,
spacing: (end - start) / (count - 1),
snow: new Float32Array(count),
overflow: 0,
sheddingTime: 0
};
}
function snowAt(surface, x) {
const index = clamp((x - surface.start) / surface.spacing, 0, surface.snow.length - 1);
const left = Math.floor(index);
return mix(surface.snow[left], surface.snow[Math.min(left + 1, surface.snow.length - 1)], index - left);
}
function topAt(surface, x) {
if (x < surface.start || x > surface.end) return Infinity;
return surface.baseAt(x) - snowAt(surface, x);
}
function buildScene() {
const floor = height * .79;
const cabin = { x: width * .71, y: floor + 4, scale: sceneScale };
const trees = [
{ x: width * .17, y: floor + 7, scale: sceneScale * 1.05 },
{ x: width * .31, y: floor + 2, scale: sceneScale * .65 }
];
layout = { floor, cabin, trees };
const ground = makeSurface('ground', -30, width + 30,
x => floor + Math.sin(x / Math.max(1, width) * Math.PI * 2.4) * 7 + Math.cos(x * .009) * 2,
'ground', Math.max(80, height * .27));
surfaces = [ground];
const houseX = cabin.x;
const houseY = cabin.y;
const scale = cabin.scale;
surfaces.push(makeSurface('roof', houseX - 124 * scale, houseX + 124 * scale,
x => houseY - 225 * scale + Math.abs(x - houseX) * .79,
'roof', 32 * scale));
surfaces.push(makeSurface('chimney', houseX + 62 * scale, houseX + 87 * scale,
() => houseY - 240 * scale, 'cap', 23 * scale));
trees.forEach((tree, treeIndex) => {
const tiers = [
{ peak: 335, bottom: 226, halfWidth: 55 },
{ peak: 266, bottom: 137, halfWidth: 79 },
{ peak: 195, bottom: 37, halfWidth: 108 }
];
tiers.forEach((tier, tierIndex) => {
const halfWidth = tier.halfWidth * tree.scale;
const rise = (tier.peak - tier.bottom) * tree.scale;
surfaces.push(makeSurface(`pine-${treeIndex}-${tierIndex}`,
tree.x - halfWidth, tree.x + halfWidth,
x => tree.y - tier.peak * tree.scale + Math.abs(x - tree.x) / halfWidth * rise,
'branch', 20 * tree.scale));
});
});
}
function roundRect(target, x, y, w, h, radius, color) {
target.beginPath();
target.roundRect(x, y, w, h, radius);
target.fillStyle = color;
target.fill();
}
function drawPine(target, tree) {
target.save();
target.translate(tree.x, tree.y);
target.scale(tree.scale, tree.scale);
roundRect(target, -7, -100, 14, 110, 3, '#25383d');
const tiers = [
{ peak: -195, bottom: -37, halfWidth: 108, color: '#253f45' },
{ peak: -266, bottom: -137, halfWidth: 79, color: '#29464b' },
{ peak: -335, bottom: -226, halfWidth: 55, color: '#2d4c50' }
];
for (const tier of tiers) {
target.beginPath();
target.moveTo(0, tier.peak);
target.lineTo(-tier.halfWidth, tier.bottom);
target.quadraticCurveTo(0, tier.bottom + 15, tier.halfWidth, tier.bottom);
target.closePath();
target.fillStyle = tier.color;
target.fill();
target.beginPath();
target.moveTo(0, tier.peak + 20);
target.lineTo(0, tier.bottom - 7);
target.strokeStyle = '#7b9c8f0d';
target.lineWidth = 2;
target.stroke();
}
target.restore();
}
function drawCabin(target) {
const cabin = layout.cabin;
target.save();
target.translate(cabin.x, cabin.y);
target.scale(cabin.scale, cabin.scale);
const glow = target.createRadialGradient(4, -50, 4, 4, -50, 210);
glow.addColorStop(0, '#e7ba7426');
glow.addColorStop(1, '#e7ba7400');
target.fillStyle = glow;
target.fillRect(-230, -260, 460, 300);
roundRect(target, -103, -130, 206, 140, 3, '#35474b');
for (let y = -120; y <= 0; y += 14) {
target.strokeStyle = '#172c334f';
target.lineWidth = 2;
target.beginPath();
target.moveTo(-102, y);
target.lineTo(102, y);
target.stroke();
}
roundRect(target, 63, -238, 23, 92, 2, '#34434b');
target.fillStyle = '#253a45';
target.beginPath();
target.moveTo(-124, -127);
target.lineTo(0, -225);
target.lineTo(124, -127);
target.closePath();
target.fill();
target.strokeStyle = '#58707755';
target.lineWidth = 2;
target.stroke();
target.strokeStyle = '#132b3866';
target.lineWidth = 3;
for (let y = -199; y < -130; y += 14) {
const extent = (y + 225) / .79;
target.beginPath();
target.moveTo(-extent, y);
target.lineTo(extent, y);
target.stroke();
}
roundRect(target, -75, -91, 57, 55, 3, '#172e38');
const windowLight = target.createLinearGradient(-70, -88, -24, -38);
windowLight.addColorStop(0, '#f6d6a0');
windowLight.addColorStop(1, '#cfa56a');
roundRect(target, -71, -87, 49, 47, 1, windowLight);
target.strokeStyle = '#665d48';
target.lineWidth = 3;
target.beginPath();
target.moveTo(-46, -87);
target.lineTo(-46, -40);
target.moveTo(-71, -64);
target.lineTo(-22, -64);
target.stroke();
roundRect(target, 23, -100, 48, 110, 3, '#243d44');
roundRect(target, 31, -91, 32, 42, 2, '#bb9b6a');
target.fillStyle = '#e6c68d';
target.beginPath();
target.arc(59, -28, 2, 0, Math.PI * 2);
target.fill();
roundRect(target, 17, 3, 60, 8, 2, '#52666a');
target.strokeStyle = '#a8b0a349';
target.lineWidth = 2;
target.beginPath();
target.moveTo(87, -121);
target.lineTo(87, -81);
target.stroke();
roundRect(target, 82, -82, 11, 16, 3, '#e7c58c');
const lamp = target.createRadialGradient(87, -74, 2, 87, -74, 60);
lamp.addColorStop(0, '#f0ce8a30');
lamp.addColorStop(1, '#f0ce8a00');
target.fillStyle = lamp;
target.fillRect(25, -135, 125, 125);
target.restore();
}
function paintBackdrop() {
const target = backgroundContext;
const sky = target.createLinearGradient(0, 0, 0, height);
sky.addColorStop(0, '#172d40');
sky.addColorStop(.63, '#345261');
sky.addColorStop(1, '#54717a');
target.fillStyle = sky;
target.fillRect(0, 0, width, height);
const mist = target.createRadialGradient(width * .69, height * .44, 20, width * .69, height * .44, width * .65);
mist.addColorStop(0, '#7d9c9622');
mist.addColorStop(1, '#7d9c9600');
target.fillStyle = mist;
target.fillRect(0, 0, width, height);
const moonX = width * .8;
const moonY = height * .19;
const moonRadius = Math.min(29, width * .045);
const moonGlow = target.createRadialGradient(moonX, moonY, 2, moonX, moonY, moonRadius * 4.5);
moonGlow.addColorStop(0, '#dce3ca20');
moonGlow.addColorStop(1, '#dce3ca00');
target.fillStyle = moonGlow;
target.fillRect(moonX - moonRadius * 5, moonY - moonRadius * 5, moonRadius * 10, moonRadius * 10);
target.fillStyle = '#d6dcc5b0';
target.beginPath();
target.arc(moonX, moonY, moonRadius, 0, Math.PI * 2);
target.fill();
for (let layer = 0; layer < 3; layer++) {
target.beginPath();
target.moveTo(0, height);
for (let x = 0; x <= width + 20; x += 20) {
const y = height * (.63 + layer * .055) + Math.sin(x * .003 + layer * 1.4) * 27 + Math.cos(x * .008 + layer) * 9;
target.lineTo(x, y);
}
target.lineTo(width, height);
target.closePath();
target.fillStyle = ['#304a55', '#2b454e', '#29434b'][layer];
target.fill();
}
for (let i = 0; i < 24; i++) {
const x = width * i / 23;
const treeHeight = 35 + (Math.sin(i * 31) + 1) * 27;
const y = layout.floor - 17;
target.beginPath();
target.moveTo(x, y - treeHeight);
target.lineTo(x - treeHeight * .25, y + 12);
target.lineTo(x + treeHeight * .25, y + 12);
target.closePath();
target.fillStyle = '#243d46';
target.fill();
}
const ground = surfaces[0];
target.beginPath();
target.moveTo(-30, height + 10);
for (let x = -30; x <= width + 30; x += 5) target.lineTo(x, ground.baseAt(x));
target.lineTo(width + 30, height + 10);
target.closePath();
target.fillStyle = '#38515b';
target.fill();
layout.trees.forEach(tree => drawPine(target, tree));
drawCabin(target);
}
function resize() {
const oldWidth = width;
const oldHeight = height;
const oldScale = sceneScale;
const oldSurfaces = new Map(surfaces.map(surface => [surface.id, surface]));
const bounds = { width: 1920, height: 876 };
if (!bounds.width || !bounds.height) return;
width = bounds.width;
height = bounds.height;
sceneScale = clamp(width / 1050, .55, 1.35);
const density = Math.min(devicePixelRatio || 1, 2);
canvas.width = backdrop.width = Math.round(width * density);
canvas.height = backdrop.height = Math.round(height * density);
context.setTransform(density, 0, 0, density, 0, 0);
backgroundContext.setTransform(density, 0, 0, density, 0, 0);
buildScene();
for (const surface of surfaces) {
const old = oldSurfaces.get(surface.id);
if (!old) continue;
const depthScale = surface.kind === 'ground' ? height / oldHeight : sceneScale / oldScale;
for (let i = 0; i < surface.snow.length; i++) {
const oldX = mix(old.start, old.end, i / (surface.snow.length - 1));
surface.snow[i] = Math.min(surface.maxDepth, snowAt(old, oldX) * depthScale);
}
}
if (oldWidth && oldHeight) {
flakes.forEach(flake => { flake.x *= width / oldWidth; flake.y *= height / oldHeight; });
}
paintBackdrop();
}
function createFlake(spread = false) {
const radius = .8 + random() ** 1.7 * 2.8;
const direction = windSpeed;
const edge = Math.min(180, Math.abs(direction) * 2);
return {
x: -edge + random() * (width + edge * 2),
y: spread ? random() * height * .79 : -10 - random() * 35,
radius,
speed: 37 + radius * 21 + random() * 22,
phase: random() * Math.PI * 2,
alpha: .32 + radius * .14,
mass: radius * radius * 5,
carried: false
};
}
function deposit(surface, x, area) {
const center = (x - surface.start) / surface.spacing;
const radius = surface.kind === 'ground' ? 4 : 3;
const first = Math.max(0, Math.floor(center - radius));
const last = Math.min(surface.snow.length - 1, Math.ceil(center + radius));
let weightSum = 0;
for (let i = first; i <= last; i++) weightSum += Math.exp(-((i - center) ** 2) / 5);
if (!weightSum) return;
for (let i = first; i <= last; i++) {
const weight = Math.exp(-((i - center) ** 2) / 5);
surface.snow[i] += area * weight / weightSum / surface.spacing;
}
}
// 每段移动按小步检查雪面,雪花落到积雪顶面后就转入高度场。
function firstLanding(flake, previousX, previousY) {
const distance = Math.hypot(flake.x - previousX, flake.y - previousY);
const steps = Math.max(1, Math.ceil(distance / 3));
for (let step = 1; step <= steps; step++) {
const amount = step / steps;
const x = mix(previousX, flake.x, amount);
const bottom = mix(previousY, flake.y, amount) + flake.radius;
let hit = null;
let highest = Infinity;
for (const surface of surfaces) {
const top = topAt(surface, x);
if (top <= bottom && top < highest && previousY - flake.radius <= surface.baseAt(x) + 2) {
hit = surface;
highest = top;
}
}
if (hit) return { surface: hit, x };
}
return null;
}
function settleSurfaces(dt) {
for (const surface of surfaces) {
const snow = surface.snow;
const smoothing = Math.min(.16, dt * 3.5);
for (let i = 0; i < snow.length - 1; i++) {
const transfer = (snow[i] - snow[i + 1]) * smoothing;
snow[i] -= transfer;
snow[i + 1] += transfer;
}
// 地面上的陡雪堆会向两侧摊开,限制局部坡度并保留雪量。
if (surface.kind === 'ground') {
const maximumDifference = surface.spacing * .65;
for (let pass = 0; pass < 3; pass++) {
for (let step = 0; step < snow.length - 1; step++) {
const i = pass % 2 === 0 ? step : snow.length - 2 - step;
const difference = snow[i] - snow[i + 1];
const excess = Math.abs(difference) - maximumDifference;
if (excess <= 0) continue;
const transfer = Math.sign(difference) * excess * .45;
snow[i] -= transfer;
snow[i + 1] += transfer;
}
}
}
for (let i = 0; i < snow.length; i++) {
if (snow[i] <= surface.maxDepth) continue;
const extra = snow[i] - surface.maxDepth;
snow[i] = surface.maxDepth;
if (surface.kind !== 'ground') surface.overflow += extra * surface.spacing;
}
surface.sheddingTime += dt;
if (surface.overflow > 6 && surface.sheddingTime > .15 && flakes.length < maximumFlakes) {
const side = windSpeed < 0 ? -1 : 1;
const edge = side < 0 ? surface.start : surface.end;
const mass = Math.min(40, surface.overflow);
flakes.push({
x: edge + side * 5,
y: surface.baseAt(edge) - snowAt(surface, edge) - 5,
radius: 2.2, speed: 70, phase: random() * 6,
alpha: .85, mass, carried: true
});
surface.overflow -= mass;
surface.sheddingTime = 0;
}
}
}
function updateSnow(dt) {
elapsed += dt;
const amount = snowfallAmount;
const rate = (12 + amount * amount * 220) * clamp(width / 1000, .55, 1.5);
if (amount > 0) emission += dt * rate;
while (emission >= 1 && flakes.length < maximumFlakes) {
flakes.push(createFlake());
emission--;
}
if (flakes.length >= maximumFlakes) emission = Math.min(emission, 1);
const breeze = windSpeed * 1.7;
for (let i = flakes.length - 1; i >= 0; i--) {
const flake = flakes[i];
const previousX = flake.x;
const previousY = flake.y;
flake.x += (breeze * (.6 + flake.radius * .15) + Math.sin(elapsed * .8 + flake.phase) * 12) * dt;
flake.y += flake.speed * dt;
const landing = firstLanding(flake, previousX, previousY);
if (landing) {
deposit(landing.surface, landing.x, flake.mass);
flakes.splice(i, 1);
} else if (flake.y > height + 30 || flake.x < -220 || flake.x > width + 220) {
flakes.splice(i, 1);
}
}
settleSurfaces(dt);
}
function drawAccumulation(surface) {
if (!surface.snow.some(depth => depth > .03)) return;
const target = context;
target.beginPath();
target.moveTo(surface.start, surface.baseAt(surface.start));
const count = surface.snow.length;
for (let i = 0; i < count; i++) {
const x = surface.start + i * surface.spacing;
const y = surface.baseAt(x) - surface.snow[i];
if (i < count - 1) {
const nextX = x + surface.spacing;
const nextY = surface.baseAt(nextX) - surface.snow[i + 1];
target.quadraticCurveTo(x, y, (x + nextX) / 2, (y + nextY) / 2);
} else target.lineTo(x, y);
}
for (let i = count - 1; i >= 0; i--) {
const x = surface.start + i * surface.spacing;
target.lineTo(x, surface.baseAt(x));
}
target.closePath();
const base = surface.baseAt((surface.start + surface.end) / 2);
const gradient = target.createLinearGradient(0, base - surface.maxDepth, 0, base + 20);
gradient.addColorStop(0, '#f3f7ef');
gradient.addColorStop(.65, '#d9e7e9');
gradient.addColorStop(1, '#a9c3cd');
target.fillStyle = gradient;
target.fill();
}
function drawGroundCover() {
const ground = surfaces[0];
const average = ground.snow.reduce((sum, depth) => sum + depth, 0) / ground.snow.length;
if (average <= 0) return;
context.save();
context.globalAlpha = clamp(average / 1.5, 0, 1);
const gradient = context.createLinearGradient(0, layout.floor, 0, height);
gradient.addColorStop(0, '#bdd2dc');
gradient.addColorStop(1, '#91adbd');
context.fillStyle = gradient;
context.beginPath();
context.moveTo(-30, height + 10);
for (let x = -30; x <= width + 30; x += 5) context.lineTo(x, ground.baseAt(x));
context.lineTo(width + 30, height + 10);
context.closePath();
context.fill();
context.restore();
}
function drawScene() {
context.clearRect(0, 0, width, height);
context.drawImage(backdrop, 0, 0, width, height);
drawGroundCover();
for (const surface of surfaces) drawAccumulation(surface);
const cabin = layout.cabin;
context.save();
context.translate(cabin.x + 75 * cabin.scale, cabin.y - 246 * cabin.scale);
context.strokeStyle = '#c4d0c11c';
context.lineWidth = 5 * cabin.scale;
context.lineCap = 'round';
for (let i = 0; i < 3; i++) {
const progress = (elapsed * .065 + i / 3) % 1;
const dx = windSpeed * progress * .5;
const dy = -progress * 70 * cabin.scale;
context.globalAlpha = Math.sin(progress * Math.PI) * .6;
context.beginPath();
context.moveTo(dx, dy);
context.bezierCurveTo(dx - 10, dy - 12, dx + 15, dy - 15, dx + 5, dy - 30);
context.stroke();
}
context.restore();
for (const flake of flakes) {
context.fillStyle = `rgba(237,245,240,${flake.alpha})`;
context.beginPath();
context.arc(flake.x, flake.y, flake.radius, 0, Math.PI * 2);
context.fill();
}
}
function resetSourceEffect() {
seed = 20261108;
simulationFrame = 0;
width = 0;
height = 0;
sceneScale = 1;
surfaces = [];
flakes = [];
elapsed = 0;
emission = 0;
resize();
flakes = Array.from({ length: Math.round(clamp(width * .22, 100, 270)) }, () => createFlake(true));
}
function renderSourceAt(seconds) {
const frame = Math.floor(seconds * 60);
if (frame < simulationFrame) resetSourceEffect();
while (simulationFrame < frame) {
updateSnow(1 / 60);
simulationFrame++;
}
drawScene();
}
function snapshot() {
const snowArea = surfaces.reduce((total, surface) => total + surface.snow.reduce((sum, v) => sum + v, 0) * surface.spacing, 0);
return { frame: simulationFrame, flakes: flakes.length, snowArea: Math.round(snowArea * 100) / 100 };
}
resetSourceEffect();
return { renderAt: renderSourceAt, reset: resetSourceEffect, snapshot };
}
</script>
<script>
'use strict';
const storyboard = JSON.parse(document.querySelector('#demo-storyboard').textContent);
const stage = document.querySelector('#stage');
const snow = createSnowEffect(document.querySelector('#effect-canvas'));
const captionElement = document.querySelector('#caption');
const pen = document.querySelector('#pen');
const whiteboard = document.querySelector('#whiteboard');
const visual = document.querySelector('#code-visual');
const visualContext = visual.getContext('2d');
visualContext.scale(2, 2);
const geometry = new Map();
let state = 'idle';
let mode = 'preview';
let playheadMs = 0;
let anchorTime = 0;
let countdownRemaining = storyboard.countdownMs;
let countdownAnchor = 0;
let resumeCountdown = false;
let frameRequest = 0;
let activeCode = '';
let ready = false;
let currentScene = storyboard.scenes[0];
let currentCaption = null;
function clamp(value, minimum = 0, maximum = 1) { return Math.max(minimum, Math.min(maximum, value)); }
function smooth(value) { const p = clamp(value); return p * p * (3 - 2 * p); }
function fraction(time, start, end) { return clamp((time - start) / Math.max(1, end - start)); }
function text(context, value, x, y, size = 24, color = '#6d755d', align = 'center') {
context.font = `${size}px "PingFang SC", sans-serif`;
context.textAlign = align;
context.textBaseline = 'middle';
context.fillStyle = color;
context.fillText(value, x, y);
}
function rounded(context, x, y, width, height, radius, fill, stroke = null) {
context.beginPath(); context.roundRect(x, y, width, height, radius);
if (fill) { context.fillStyle = fill; context.fill(); }
if (stroke) { context.strokeStyle = stroke; context.lineWidth = 2; context.stroke(); }
}
function line(context, x, y, x2, y2, color = '#8d9a7c', width = 2) {
context.beginPath(); context.moveTo(x, y); context.lineTo(x2, y2);
context.strokeStyle = color; context.lineWidth = width; context.lineCap = 'round'; context.stroke();
}
function drawFlake(context, x, y, radius, alpha = 1) {
context.save(); context.globalAlpha = alpha;
for (let i = 0; i < 3; i++) {
const angle = i * Math.PI / 3;
line(context, x - Math.cos(angle) * radius, y - Math.sin(angle) * radius,
x + Math.cos(angle) * radius, y + Math.sin(angle) * radius, '#7c9b9b', 3);
}
context.restore();
}
function fitStage() {
const scale = Math.min(innerWidth / storyboard.logicalWidth, innerHeight / storyboard.logicalHeight);
stage.style.transform = `translate(-50%, -50%) scale(${scale})`;
}
addEventListener('resize', fitStage);
fitStage();
for (const action of storyboard.actions) {
const group = document.getElementById(action.targetId);
const paths = [...group.querySelectorAll('.ink')].map(path => ({ path, length: path.getTotalLength() }));
geometry.set(action.targetId, { group, paths, length: paths.reduce((sum, item) => sum + item.length, 0) });
}
function drawWhiteboard(time) {
let penPoint = null;
for (const action of storyboard.actions) {
const item = geometry.get(action.targetId);
const progress = fraction(time, action.startMs, action.endMs);
item.group.style.opacity = progress > 0 ? '1' : '0';
const inkProgress = clamp(progress / .68);
const fillProgress = clamp((progress - .68) / .32);
let available = item.length * inkProgress;
for (const { path, length } of item.paths) {
const drawn = clamp(available, 0, length);
path.style.strokeDasharray = `${length} ${length}`;
path.style.strokeDashoffset = String(length - drawn);
path.style.fillOpacity = String(fillProgress);
if (available > 0 && available < length && time >= action.startMs && time < action.endMs) {
const localPoint = path.getPointAtLength(drawn);
const screenPoint = new DOMPoint(localPoint.x, localPoint.y).matrixTransform(path.getScreenCTM());
penPoint = screenPoint.matrixTransform(whiteboard.getScreenCTM().inverse());
}
available -= length;
}
item.group.querySelectorAll('text').forEach(element => { element.style.opacity = String(fillProgress); });
}
pen.style.opacity = penPoint ? '1' : '0';
if (penPoint) { pen.setAttribute('cx', penPoint.x); pen.setAttribute('cy', penPoint.y); }
}
function addCodeTokens(element, source) {
const tokens = source.split(/(\b(?:const|if|for|let)\b|\b(?:firstLanding|deposit|splice|baseAt)\b)/g);
for (const token of tokens) {
const span = document.createElement('span');
span.textContent = token;
if (/^(const|if|for|let)$/.test(token)) span.className = 'token-keyword';
if (/^(firstLanding|deposit|splice|baseAt)$/.test(token)) span.className = 'token-function';
element.append(span);
}
}
function showCode(scene) {
if (activeCode === scene.snippetId) return;
activeCode = scene.snippetId;
const code = storyboard.code[scene.snippetId];
document.querySelector('#code-heading').textContent = scene.title;
document.querySelector('#code-meta').textContent = `所在函数 · ${code.function}`;
document.querySelector('#code-omitted').textContent = scene.snippetId === 'landing'
? 'flake 是当前雪花,previousX / previousY 是上一帧坐标。\ndt 是一帧经过的秒数。节选省略了后续边界处理。'
: 'i 是格子编号,count 是格数,spacing 是格宽。\nsurface.snow[i] 记录厚度。节选省略了后续轮廓连接。';
const container = document.querySelector('#code-lines');
container.replaceChildren();
code.lines.forEach((source, index) => {
const row = document.createElement('div'); row.className = 'code-line';
const number = document.createElement('span'); number.className = 'line-no';
number.textContent = code.startLine + index;
const line = document.createElement('span');
addCodeTokens(line, source);
row.append(number, line); container.append(row);
});
}
function drawCodeVisual(scene, time, highlight) {
const target = visualContext;
target.clearRect(0, 0, 510, 650);
const columnWidths = 52;
const depths = [16, 22, 44, 68, 46, 25, 18];
const baseline = 438;
const start = 72;
if (scene.id === 'code-hit') {
const falling = smooth(fraction(time, 37400, 40400));
const deposited = smooth(fraction(time, 41100, 44500));
for (let i = 0; i < 7; i++) {
rounded(target, start + i * columnWidths, baseline - depths[i] * deposited, columnWidths - 4, depths[i] * deposited + 1, 2, '#acc4bd');
line(target, start + i * columnWidths, baseline + 2, start + i * columnWidths, baseline + 19, '#b8b29a', 1);
}
line(target, 57, baseline + 1, 455, baseline + 1, '#7d8b70', 3);
const opacity = time < 45800 ? 1 : 1 - fraction(time, 45800, 48500);
drawFlake(target, 255, 170 + falling * 250, 19, opacity);
if (time >= 40000) {
target.strokeStyle = '#bb8b58'; target.lineWidth = 3;
target.beginPath(); target.arc(255, baseline - 5, 18, 0, Math.PI * 2); target.stroke();
text(target, '落点', 255, baseline + 54, 25, '#a77c48');
}
text(target, time < 41100 ? '先找到碰到的表面' : time < 45800 ? '粒子的份额 → 附近小格' : '空中少一片,雪层留一份', 255, 562, 24);
if (time >= 48000) {
line(target, 236, 250, 250, 264, '#7b9b70', 4);
line(target, 250, 264, 279, 225, '#7b9b70', 4);
}
} else {
const raise = time < 59000 ? .55 : .55 + .45 * smooth(fraction(time, 59000, 64300));
for (let i = 0; i < 7; i++) {
const depth = depths[i] * raise * 1.4;
rounded(target, start + i * columnWidths, baseline - depth, columnWidths - 4, depth, 2, i === 3 ? '#c69a67' : '#b4c6ae');
line(target, start + i * columnWidths, baseline + 1, start + i * columnWidths, baseline + 18, '#b8b29a', 1);
}
line(target, 55, baseline, 465, baseline, '#7d8b70', 2);
text(target, '原地面', 404, baseline + 43, 22, '#a09578');
const top = baseline - depths[3] * raise * 1.4;
line(target, 228, top, 330, top, '#8a9c78', 3);
text(target, '雪面', 373, top, 25, '#75876b');
line(target, 245, baseline - 5, 245, top + 6, '#b38450', 2);
line(target, 245, top + 6, 237, top + 18, '#b38450', 2);
line(target, 245, top + 6, 253, top + 18, '#b38450', 2);
if (time < 59000) {
text(target, '当前格 i', 255, 225, 25);
text(target, '横向位置 x', 255, 273, 25, '#aa8a59');
} else {
line(target, 88, 168, 88, 310, '#9b9c7e', 2);
line(target, 88, 310, 80, 298, '#9b9c7e', 2);
line(target, 88, 310, 96, 298, '#9b9c7e', 2);
text(target, 'y 向下增大', 220, 205, 26);
text(target, '厚度增加 → 雪面向上', 255, 560, 25, '#aa8a59');
}
text(target, '原地面 − 厚度 = 雪面', 255, 607, 22, '#8c8e70');
}
}
function renderAt(time) {
currentScene = storyboard.scenes.find(scene => scene.startMs <= time && time < scene.endMs) || storyboard.scenes.at(-1);
currentCaption = storyboard.captions.find(caption => caption.startMs <= time && time < caption.endMs) || null;
const isPaper = ['principle', 'code'].includes(currentScene.phase);
stage.classList.toggle('paper', isPaper);
const sceneElements = document.querySelectorAll('.scene');
sceneElements.forEach(element => { element.classList.remove('visible'); element.style.opacity = '0'; });
const targetId = currentScene.phase === 'effect' || currentScene.phase === 'outro' ? 'effect'
: currentScene.id === 'code-intro' ? 'code-intro' : currentScene.phase === 'code' ? 'code-scene' : 'principle';
const target = document.getElementById(targetId);
target.classList.add('visible');
const transition = storyboard.transitions.find(item => item.sceneId === currentScene.id);
const entering = transition.enterMs ? smooth(fraction(time, currentScene.startMs, currentScene.startMs + transition.enterMs)) : 1;
const exiting = transition.exitMs ? 1 - smooth(fraction(time, currentScene.endMs - transition.exitMs, currentScene.endMs)) : 1;
target.style.opacity = String(Math.min(entering, exiting));
document.querySelector('#chapter').textContent = currentScene.phase === 'effect' ? '看见效果' : currentScene.phase === 'principle' ? '白板原理' : currentScene.phase === 'outro' ? '' : '实现揭秘';
if (targetId === 'effect') {
const sourceSeconds = 18 + Math.min(time, 10000) / 1000 * 1.5 + Math.max(0, time - 66500) / 1000 * .8;
snow.renderAt(sourceSeconds);
const shot = storyboard.shots.find(item => item.startMs <= time && time < item.endMs);
const camera = shot?.camera;
const scale = camera ? camera.scaleFrom + (camera.scaleTo - camera.scaleFrom) * smooth(fraction(time, shot.startMs, shot.startMs + camera.moveMs)) : 1;
document.querySelector('#effect-viewport').style.transform = `scale(${scale})`;
document.querySelector('#effect-note').textContent = currentScene.id === 'effect' ? '积雪过程加速展示' : '';
document.querySelector('#effect-question').textContent = currentScene.id === 'effect' && time >= 7200 ? '落下的雪,\n被记在了哪里?' : '';
document.querySelector('#effect-question').style.whiteSpace = 'pre-line';
}
drawWhiteboard(time);
if (currentScene.id === 'code-intro') {
document.querySelector('#intro-title').textContent = currentScene.title;
document.querySelector('#intro-subtitle').textContent = currentScene.subtitle;
document.querySelector('#intro-rule').style.transform = `scaleX(${smooth(fraction(time, 34100, 35000))})`;
}
if (currentScene.kind === 'snippet') {
showCode(currentScene);
const highlight = storyboard.highlights.find(item => item.sceneId === currentScene.id && item.startMs <= time && time < item.endMs);
document.querySelectorAll('.code-line').forEach((line, index) => line.classList.toggle('active', Boolean(highlight?.lines.includes(index))));
document.querySelector('#code-focus').textContent = highlight?.label || '';
drawCodeVisual(currentScene, time, highlight);
}
captionElement.textContent = document.querySelector('#captions-on').checked ? currentCaption?.text || '' : '';
document.querySelector('#progress').value = time;
const seconds = Math.floor(time / 1000);
document.querySelector('#timecode').textContent = `${String(Math.floor(seconds / 60)).padStart(2, '0')}:${String(seconds % 60).padStart(2, '0')} / 01:10`;
}
function updateInterface() {
document.querySelector('#preparation').hidden = state !== 'idle';
document.querySelector('#preview-controls').hidden = state === 'idle' || mode === 'record' || state === 'countdown' || resumeCountdown;
document.querySelector('#end-screen').hidden = !(state === 'ended' && mode === 'preview');
document.querySelector('#countdown').hidden = state !== 'countdown' && !resumeCountdown;
document.querySelector('#toggle-play').textContent = state === 'paused' ? '继续' : '暂停';
document.body.classList.toggle('record-mode', mode === 'record');
document.body.classList.toggle('preparing', state === 'idle');
}
function resetDemo() {
cancelAnimationFrame(frameRequest);
frameRequest = 0;
state = 'idle';
playheadMs = 0;
resumeCountdown = false;
countdownRemaining = storyboard.countdownMs;
activeCode = '';
snow.reset();
captionElement.textContent = '';
document.querySelector('#code-lines').replaceChildren();
document.querySelector('#code-focus').textContent = '';
document.querySelector('#countdown').textContent = '3';
renderAt(0);
updateInterface();
}
function requestFrame() { if (!frameRequest) frameRequest = requestAnimationFrame(tick); }
function tick(now) {
frameRequest = 0;
if (state === 'countdown') {
const remaining = Math.max(0, countdownRemaining - (now - countdownAnchor));
document.querySelector('#countdown').textContent = String(Math.max(1, Math.ceil(remaining / 1000)));
if (remaining === 0) {
state = 'playing'; playheadMs = 0; anchorTime = now;
updateInterface(); renderAt(0);
}
} else if (state === 'playing') {
playheadMs = clamp(now - anchorTime, 0, storyboard.durationMs);
renderAt(playheadMs);
if (playheadMs === storyboard.durationMs) {
state = 'ended'; updateInterface();
captionElement.textContent = ''; pen.style.opacity = '0';
}
}
if (state === 'playing' || state === 'countdown') requestFrame();
}
function startDemo(playbackMode = 'preview') {
if (!ready) return;
resetDemo();
mode = playbackMode;
if (mode === 'record') {
state = 'countdown'; countdownAnchor = performance.now();
} else {
state = 'playing'; anchorTime = performance.now();
}
updateInterface(); requestFrame();
}
function pauseDemo() {
if (state !== 'playing' && state !== 'countdown') return;
const now = performance.now();
if (state === 'countdown') {
countdownRemaining = Math.max(0, countdownRemaining - (now - countdownAnchor));
document.querySelector('#countdown').textContent = String(Math.max(1, Math.ceil(countdownRemaining / 1000)));
resumeCountdown = true;
} else {
playheadMs = clamp(now - anchorTime, 0, storyboard.durationMs);
renderAt(playheadMs);
}
state = 'paused'; cancelAnimationFrame(frameRequest); frameRequest = 0;
updateInterface();
}
function resumeDemo() {
if (state !== 'paused') return;
if (resumeCountdown) {
state = 'countdown'; resumeCountdown = false; countdownAnchor = performance.now();
} else {
state = 'playing'; anchorTime = performance.now() - playheadMs;
}
updateInterface(); requestFrame();
}
function replayDemo() { startDemo(mode); }
function returnToPreparation() { mode = 'preview'; resetDemo(); }
document.querySelector('#start-preview').addEventListener('click', () => startDemo('preview'));
document.querySelector('#start-record').addEventListener('click', () => startDemo('record'));
document.querySelector('#toggle-play').addEventListener('click', () => state === 'paused' ? resumeDemo() : pauseDemo());
document.querySelector('#replay').addEventListener('click', replayDemo);
document.querySelector('#end-replay').addEventListener('click', replayDemo);
document.querySelector('#return-prep').addEventListener('click', returnToPreparation);
document.querySelector('#end-settings').addEventListener('click', returnToPreparation);
document.querySelector('#captions-on').addEventListener('change', () => renderAt(playheadMs));
document.querySelector('#fullscreen').addEventListener('click', async () => {
try { await document.documentElement.requestFullscreen(); }
catch { document.querySelector('#ready-note').textContent = '全屏未开启,仍可在固定画幅内播放。'; }
});
document.addEventListener('keydown', event => {
if (event.target.matches('input, textarea, select, [contenteditable="true"]')) return;
if (event.code === 'Space') {
event.preventDefault();
if (state === 'paused') resumeDemo(); else pauseDemo();
}
if (event.key === 'Escape' && state !== 'idle') returnToPreparation();
});
document.addEventListener('visibilitychange', () => { if (document.hidden) pauseDemo(); });
Object.defineProperty(window, 'demoState', { get() {
return Object.freeze({ state, mode, playheadMs, sceneId: currentScene.id, captionId: currentCaption?.id || null,
captionText: captionElement.textContent, progress: playheadMs / storyboard.durationMs,
source: Object.freeze(snow.snapshot()), countdownRemaining, penOpacity: pen.style.opacity });
}});
async function prepare() {
const fontWait = document.fonts?.ready || Promise.resolve();
let timer;
const timeout = new Promise(resolve => { timer = setTimeout(resolve, 3500); });
await Promise.allSettled([Promise.race([fontWait, timeout])]);
clearTimeout(timer);
resetDemo(); ready = true;
document.querySelector('#start-preview').disabled = false;
document.querySelector('#start-record').disabled = false;
document.querySelector('#ready-note').textContent = '已就绪。录屏结束后可多保留约 2 秒尾帧。';
}
prepare();
</script>
</body>
</html>
Connects securely to your tools. The creator never sees your data.
About this skill
快速使用
在能够读取本地文件并执行脚本的 Agent 会话中,指定本仓库的技能入口和待处理 HTML。将下面的路径替换为实际路径:
请读取 /你的路径/jyeontu-skill/html-whiteboard-demo/SKILL.md,
按照该技能,将 /你的路径/demo.html 制作为白板代码讲解演示,
并生成同步 SRT 字幕。
如果当前环境已经安装并识别该技能,可以直接调用:
使用 $html-whiteboard-demo,将这个 HTML 制作为白板代码讲解 Demo,
并生成同步 SRT 字幕:/你的路径/demo.html
源文件使用本地图片、字体或脚本时,应一并提供这些资源。无需提前准备字幕、分镜或配图;Agent 会根据源码生成。若目录里有多个 HTML,建议明确指定源文件。
默认交付
- 与源文件同目录的 {原名}-白板演示.html 和 {原名}-白板演示.srt。
- 中文、16:9、1920×1080,约 60 秒,通常为 45~80 秒;具体时长按内容可读性调整。
- 四阶段内容:效果展示与介绍 → 白板原理总结 → 关键代码解释 → 感谢与关注。
- 支持开始、暂停、继续和重播;讲解结束后显示独立结束页。 字幕、白板绘制、代码高亮和模拟光标共用毫秒时间轴。
输出文件已存在且未授权覆盖时,整组文件使用相同版本后缀。源 HTML 保持原样。
生成的 HTML 内嵌分镜和字幕数据,无需另行加载 SRT 或 JSON。SRT 可用于后续剪辑,时间零点对应点击开始后的内容播放起点;录屏包含片头等待时,需要剪除等待或整体偏移字幕。
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 8 days ago
- Free with an Agensi account
Requires
Permissions
Allowed Hosts