Claude Codeで動画を作る方法【コード付き】HyperFramesの使い方と書き出しまでの手順

Claude Codeで動画を作るなら、HeyGenが無料で公開している「HyperFrames」を使うのが手早いです。Claudeが動画の中身をHTMLとJavaScriptで書き、HyperFramesがそのページを1コマずつ撮ってMP4にします。カメラも映像生成AIもAPIキーも要りません。

この記事では、私が2026年12月2日に実際に作った30秒のショート動画3本と、空っぽの環境から10秒の動画を書き出すまでの実測(最初の1回はChromeを取り込むので約1分半、その後は約27秒)、Claude Codeに1文頼んでMP4ができるまでの時間を、コードと頼み方の文つきで書いていきます。lint が何も言わないのに画面が崩れた失敗や、Claude Codeが「検査は指摘なし」と報告したのに実はエラーが残っていた話も、そのまま載せています。

Claude Codeで作った動画はこんな仕上がりになる

先に完成品を見てください。下の3本は、どれも撮影も映像生成AIも使わず、Claude Codeが書いたコードだけで作った縦型(1080×1920・30秒)の動画です。

1本目は、4万個の光る粒が爆発して、地球、日本列島、人の横顔、文字へと形を変え続ける動画です。粒はThree.jsという3Dの部品で描いていて、地図は公開されている地図データから点を撒いています。

1本目「粒子の変身」の書き出しから8コマを並べたもの(2026年12月2日・1080×1920・30秒)
1本目「粒子の変身」の書き出しから8コマを並べたもの(2026年12月2日・1080×1920・30秒)

2本目は「存在しない街」の空撮です。雲を突き抜けて夜の未来都市に降り、大通りの谷間を低く飛んで、最後は夜明けの地平線を見せます。ビルが約6,000棟ありますが、街も車の光も雨も、全部コードで組み立てたものです。

2本目「存在しない街」の書き出しから8コマを並べたもの(街も雲も夜明けもThree.jsのコード)
2本目「存在しない街」の書き出しから8コマを並べたもの(街も雲も夜明けもThree.jsのコード)

3本目は、チャット欄に1行の頼みを打つと、裏でコードが流れて図形が描かれ、3Dの惑星へワープし、最後に「ブラウザの窓1枚だった」と種明かしする動画です。曲の拍に合わせて場面が切り替わります。

3本目「一行の頼みが映像に」の書き出しから8コマを並べたもの
3本目「一行の頼みが映像に」の書き出しから8コマを並べたもの

ひとつ断っておくと、3本目の動画の中でチャット欄に打っている「30秒で、宇宙から始まる映像を作って」の1行は、頼む場面を見せるための演出です。実際にこの動画を作るときに頼んだのは、下で紹介する長い頼み方の文と、何回かの直しの指示でした。1文だけで動画ができるかは、このあと10秒の動画で本当に試しています。冒頭の「カメラ使ってません」のとおり撮影はしておらず、動画編集ソフトで人が切り貼りもしていません。

正直に言うと、3本とも1回の頼みで出来上がったわけではありません。Claude Codeが書き出したあとにコマを並べて確かめ、崩れや見切れを何度も直しています。それでも、私がやったのは日本語で頼むことと、できた動画を見て直してほしい所を伝えることだけでした。

Claude Codeで動画を作るのに必要な物と料金

必要なのはNode.js(22.19以上)とFFmpegとClaude Codeの3つで、HyperFrames自体は無料です。お金がかかるのはClaude Codeを使うためのClaudeの有料プランだけでした。

必要な物 料金 私の環境(2026年12月2日)
Node.js 22.19以上 無料 24.14.1
FFmpeg 無料 7.1
HyperFrames 無料(Apache-2.0) 0.10.7(作品によって0.8.33)
Claude Code Claudeの有料プラン(Pro以上)が必要 2.1.334
動画を撮る Chrome 無料(初回に自動で取ってくる) 158.0.8127.88

Node.jsの版は気をつけてください。HyperFramesの説明記事では「22以上」と書かれていることが多いのですが、npmに登録されている条件は「22.19.0以上」です(2026年12月2日に npm view hyperframes engines で確かめました)。

Claude Codeは、Claudeの無料プランでは使えません。Claudeの公式ヘルプでは、Proプラン(月払いで月20ドル)にClaude Codeが含まれると説明されています。料金表でもFreeの列のClaude Codeは「No」でした。HyperFramesで書き出す部分は手元のPCで動くので、動画1本ごとに料金がかかる仕組みではありません。Claudeの各プランの違いはClaudeの全機能とClaude Code・料金プランのまとめにも書いています。

使った物の入れ方は短く書いておきます。Node.jsは公式サイト(nodejs.org)のLTS版のインストーラー、FFmpegはWindowsなら winget install Gyan.FFmpeg、Claude Codeは公式の手順どおりに入れてログインします(Claude Codeを入れるところから不安な人はClaudeCodeとCodexの始め方の手順を先にどうぞ)。入ったかどうかは、ターミナルで次の3行を打てば分かります。

node --version
ffmpeg -version
claude --version

HyperFramesを入れる手順と初回にかかる時間

npx hyperframes init を1回打つと、雛形の作成とClaude Code用のスキル6つの導入まで自動で終わりました。別に npx skills add を打つ必要はありませんでした。

スキルを npx skills add heygen-com/hyperframes で別に入れる手順を書いた解説記事も多いのですが、init がスキルを入れてくれることを2026年11月の版(0.9.46)で確かめている記事もあります。私が試した0.10.7でも同じで、init の途中でClaude Codeを見つけて入れてくれました。確かめ方はこうです。

まっさらなPCを用意する代わりに、ホームフォルダとnpmの取り置き(キャッシュ)を空のフォルダに差し替えた状態を作り、そこで次のコマンドを打ちました。

npx --yes hyperframes@0.10.7 init demo --non-interactive --resolution portrait

終わるまで54.6秒。画面には「Agent detected — installing non-interactively」と出て、次の6つが ~/.claude/skills と ~/.agents/skills の両方に入りました。

  • hyperframes(動画を組み立てる本体のスキル)
  • hyperframes-cli(init・lint・render などのコマンドの扱い)
  • hyperframes-registry(公式の部品の取り込み)
  • media-use
  • reverse-any-video
  • style-sampling

最後に「Restart your AI agent (new session) so it loads the skills.」と出ます。Claude Codeを開いていた人は、一度閉じて開き直さないとスキルが読まれません。ここを飛ばすと「スキルが見当たらない」で止まります。入ったスキルは ~/.claude/skills の中の SKILL.md というファイルで、Claude Codeは作業のたびにこれを読みます。勝手に書き換えられると困るファイルなので、守り方はClaude Codeのカスタムスキル(SKILL.md)の書き換えを防ぐ方法で試しています。

作られたプロジェクトのフォルダには index.html・package.json・hyperframes.json・meta.json・CLAUDE.md・AGENTS.md の6つが入っていました。1つのプロジェクトが1本の動画で、本体は index.html の1枚です。CLAUDE.md と AGENTS.md は、Claude CodeなどのAIエージェントがこのフォルダで作業するときに読む説明書きです。

続けて雛形のまま書き出してみると、最初の1回だけ時間がかかりました。画面に「Still getting Chrome ready; the first use downloads it.」と出て、動画を撮るための Chrome(headless shell)を自動で取りに行くからです。

回 中身 かかった時間 取り込んだ物
init 雛形とスキル6つ 54.6秒 npmの取り置き 182MB
書き出し1回目 雛形(10秒) 86.5秒 Chrome 284MB
Chrome取り込み後の書き出し 下の最小の例(10秒) 27.1秒 なし

Chromeを取り込んだ後、下に載せた最小の例(記事に載せた最終のコード)を書き出すと、HyperFrames自身の表示で「rendered in 20.1s」、ターミナルに打ってから戻ってくるまでの実時間で27.1秒でした。途中の書き直しの版も同じくらいで、実時間は21〜27秒の間でした。最初の1回が遅いのは故障ではなく、Chromeを落としている時間なので、そのまま待てば大丈夫です。

Claude Codeに1行で頼んで動画を作る方法

init で作ったフォルダでClaude Codeに日本語で1文頼むだけで、10秒の動画のMP4までできました。私が実際に送ったのは次の1文です。

hyperframes のスキルを使って、縦 1080×1920・10 秒の動画を作り、out.mp4 に書き出して。中身は「Claude Codeで作った動画」という文字が光りながら出てくるだけでいい。

2026年12月2日、npx hyperframes init で作ったばかりの空のプロジェクトのフォルダでClaude Codeにこの1文を渡したところ、10分36秒後に out.mp4 ができていました。

このあたりは、使っているパソコンの環境によって変わってくるでしょう。

Claude Codeは途中で「書き出しを始めました」「書き出し直しています」と言っていて、書き出しは少なくとも2回。ログに残った最後の1回は「rendered in 33.6s」でした。残りの時間は、Claude Codeが中身を書き、直し、書き出した動画からコマを取り出して確かめていた時間です。

返ってきた報告は「縦 1080×1920、ちょうど 10.0 秒、30 コマ/秒、1.5MB、音なし」。ffprobeで測り直しても同じでした。「光の筋がほとんど見えません」と、うまくいかなかった演出まで書いてきます。

ところが、報告の「作る前の検査は指摘なし」は事実と違いました。書き出しのログには「Lint: 1 error(s), 1 warning(s)」とあり、エラーのまま書き出しを続けていたんです。あとで自分で npx hyperframes lint を回すと、エラーの中身はこうでした。

✗ multiple_root_compositions: Multiple root-level HTML files with data-composition-id: index.html, index.scaffold.bak.html. The runtime may discover both as entry points, causing duplicate audio playback.

Claude Codeが元の雛形を index.scaffold.bak.html という名前で同じフォルダに控えとして残したため、「動画の入口が2つある」と言われていたわけです。音の無い動画なので今回は実害がありませんでしたが、音楽を付けていたら二重に鳴るおそれがあると書かれています。エージェントの「問題なし」はそのまま信じず、最後に自分で lint(あとで出てくる check)を1回回すのがいちばん安上がりな確かめ方だと思いました。控えのファイルは、lint の直し方の表示(Remove or rename extra files)どおり、別のフォルダへ移すか消せばよいはずです(私は試していません)。

1文の頼みでClaude Codeが作った10秒の動画(0.5秒・1.5秒・3秒・5秒・9.5秒のコマ)
1文の頼みでClaude Codeが作った10秒の動画(0.5秒・1.5秒・3秒・5秒・9.5秒のコマ)

条件も書いておきます。このテストのフォルダは init の --skip-skills を付けて作ったので、使われたスキルは init が入れた物ではなく、私のPCに元から入っていた hyperframes のスキルです。それに、私のClaude Codeには自作の決まりごとや見張りの仕組みをたくさん入れています。ふつうの環境だと10分36秒より短くなるのか長くなるのかは、確かめていません。

作り込んだ3本に近い物を作りたいときは、下の頼み方の文が出発点になります。この3つの文は、3本を作り終えてから、やり取りの中身を1回で頼み直せる形にまとめた文です。この形のまま送って試してはいませんし、載せるにあたって音楽と効果音の行も外しました。貼れば同じ動画が出る、とは約束できません。

1本目(粒子の変身)の頼み方です。

hyperframes のスキルを読んでから、縦 1080x1920・30 秒・30fps の YouTube ショートを作って。
中身: 数万個の光る粒子(Three.js の Points・加算合成・被写界深度風のぼかし・ゆっくり回るカメラ)が、
暗闇の 1 点が爆発して渦 → 地球(球に大陸の点描)→ 日本列島 → 人の横顔 → 「全部 コードで 描いた」の文字、へと滑らかに変形し続ける。
地図は world-atlas、文字は Google Fonts の字形から点を撒き、形の座標は Node の道具で前もって焼いて js に入れておくこと(レンダー中にネットから読まない・Math.random を使わない)。
字幕は最小限で、締めに「カメラも 生成AIの映像モデルも 使っていません」「Claude が コードを書いて 作りました」。
画像や映像の生成モデル・API キーの要る物は使わない。書き出したら 2 秒おきのコンタクトシートを作って自分の目で見て、崩れ・見切れ・字化けを直してから渡して。

2本目(存在しない街)の頼み方です。

縦 1080x1920・30 秒・30fps の YouTube ショートを hyperframes で作ってください。
題は「存在しない街を空撮」。Three.js で手続き的に作った夜の未来都市(ビル群・窓の灯り・霧・ネオン看板・道を流れる車の光の筋・雨で濡れた路面の映り込み)を、ドローンの空撮のように飛びます。
・0〜1.5 秒: 月夜の雲海を見せてから急降下し、雲を突き抜けて街が現れる
・大通りの谷間を低空で縫い、空中の渡り廊下の下をくぐる。カメラは時刻つきのスプライン経路・わずかな揺れ・横の加速でバンク
・最後は中央の超高層の壁面を駆け上がって屋上を越え、地平線まで続く街と夜明けの空を見せる
・仕上げ: ブルーム・色調補正・ビネット・フィルムの粒・モーションブラーでシネマ風に
・字幕(日本語・少なく): 冒頭「この街は 存在しません」、締め「カメラも 映像生成AIも 使っていない」「Claude が コードで 街ごと 作りました」
・守る事: 絵は時刻 t だけで決める(Math.random と Date を使わない)。API キーの要る物・画像や映像の生成モデルは使わない
・確かめ: ffprobe で尺と解像度と音声、2 秒おきのコンタクトシートを見て、真っ黒・崩れ・字の見切れが無いか確かめてから渡す

3本目(一行の頼みが映像に)の頼み方です。

hyperframes のスキルで、縦 1080x1920・30 秒・30fps の YouTube ショートを作って。
題は「日本語の頼みが映像になる種明かし」。画像や映像の生成モデルは使わず、全部 HTML/CSS/JS(GSAP と Three.js)のコードで描くこと。
0〜3 秒 フック。大きな太字の日本語「この動画、」「カメラ」「使って」「ません」を拍ごとに叩きつける(揺れとグリッチ付き)。
3〜8 秒 黒い画面にチャット欄。「30秒で、宇宙から始まる映像を作って」をタイプし、送信ボタンを押す。
8〜24 秒 押した瞬間にフラッシュ、裏の HTML/JS のコードが滝のように流れる → コード 1 行ごとに図形が描かれる → Three.js の 3D 惑星と光の輪へワープ → 「日本語の頼みが コードになって 映像に なった」の文字が爆発 → 宇宙がブラウザの窓(index.html)に縮んで「この映像の正体は…」。
24〜30 秒 種明かし「全部 Claude が コードで 書いた」「無料の道具で 誰の PC でも」。
文字は Noto Sans JP の太字、Shorts の下と右の UI に被らない範囲に収める。
書き出したら ffprobe で尺と寸法と音声を確かめ、2 秒おきのコンタクトシートを作って自分で見て、見切れや字化けを直してから渡して。

3つの文は、最初に縦横の大きさと秒数、最後に使ってはいけない物と確かめ方を書く構成です。2本目と3本目は、間に何秒目にどの場面(シーン)を出すかも秒数で区切りました(1本目は場面が1つなので区切りなし)。複数シーンの動画では、この秒数の区切りがそのまま場面の切り替えの目印になります。

3つとも最後に「書き出したらコマを並べて自分で見てから渡して」と入れています。上の1文テストでも、Claude Codeは書き出した動画からコマを取り出して見てから返してきました。ただ、lint のエラーは見落としていたので、最後に自分の目と check で確かめる手間は残ります。音楽の指定は、私の環境にある音楽つきのスキルを前提にしていたので、上の文からは外しました。2本目と3本目の効果音は、earshot という道具でコードから作った音です。

3本の動画の実際のコード(全文)

上の頼み方の文は「どう頼んだか」です。ここには、Claude Codeが書いて実際に3本を書き出したファイルを、手を入れずにそのまま載せます。YouTubeに上げたショート版で、最後の「こんな動画を作りたい方は…」の場面まで入っています。長いので、見出しを押すと開くようにしました。

曲・効果音・フォントのファイルは載せていません。曲はSascha Endeさんの曲(CC BY 4.0)で、使うには自分で入手してクレジットを書く必要があります。コードの中で assets/ や sound/ から読んでいる音のファイルが、それに当たります。

1本目(粒子の変身)のコード

画面の動きは index.html の1枚です。4万個の粒の行き先(渦・地球・日本列島・横顔・文字)の座標は shapes.js(約2.2MB)に入っていますが、数字が並んでいるだけなので載せず、それを作る道具 tools/bake_shapes.mjs を載せます。tools フォルダで npm install のあと node bake_shapes.mjs を打つと shapes.js ができます。書き出しは npx --yes hyperframes@0.8.33 render で作りました。

1本目 index.html(345行・クリックで開く)
<!doctype html>
<html lang="ja" data-resolution="portrait">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=1080, height=1920" />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Zen+Kaku+Gothic+New:wght@700;900&display=block"
      rel="stylesheet"
    />
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
    <script src="shapes.js"></script>
    <style>
      * { margin: 0; padding: 0; box-sizing: border-box; }
      html, body { width: 1080px; height: 1920px; overflow: hidden; background: #020108; }
      body { font-family: "Zen Kaku Gothic New", sans-serif; color: #f4f1ff; }
      #stage { position: absolute; inset: 0; width: 1080px; height: 1920px; display: block; }
      #vignette {
        position: absolute; inset: 0; pointer-events: none;
        background: radial-gradient(ellipse 75% 60% at 50% 50%, rgba(0,0,0,0) 55%, rgba(0,0,0,0.78) 100%);
      }
      #fadeout { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }
      .cap {
        position: absolute; left: 0; width: 1080px; padding: 0 60px;
        display: flex; flex-direction: column; align-items: center; gap: 18px;
        text-align: center; letter-spacing: 0.04em;
        text-shadow: 0 0 18px rgba(120,160,255,0.55), 0 0 4px rgba(0,0,0,0.9);
      }
      #hook { top: 250px; }
      #hook .small { font-size: 44px; font-weight: 700; color: #b9c6ff; }
      #hook .big { font-size: 84px; font-weight: 900; }
      #hook .big em { font-style: normal; color: #7ff3ff; font-variant-numeric: tabular-nums; }
      #capA, #capC { width: 978px; padding: 0 30px; }
      #capA { top: 640px; }
      #capC { top: 600px; gap: 34px; }
      #capC .c1 { font-size: 62px; font-weight: 700; color: #ffd27a; }
      #capC .c2 { font-size: 62px; font-weight: 900; color: #f4f1ff; }
      #capC .c3 { white-space: nowrap; font-size: 58px; font-weight: 900; color: #7ff3ff; }
      #capC::before {
        content: ""; position: absolute; left: 0; right: 0; top: -70px; bottom: -70px; z-index: -1;
        background: radial-gradient(ellipse 60% 50% at 50% 50%, rgba(2,1,8,0.35) 0%, rgba(2,1,8,0) 100%);
      }
      #capA .l1 { font-size: 56px; font-weight: 700; color: #d9dcff; }
      #capA .l2 { font-size: 92px; font-weight: 900; }
      #capB { top: 1120px; }
      #capB .l1 { font-size: 64px; font-weight: 700; color: #ffd27a; }
      #capB .l2 { font-size: 92px; font-weight: 900; }
      #credit {
        position: absolute; left: 0; width: 1080px; top: 1580px; width: 978px; text-align: center;
        font-size: 24px; font-weight: 700; color: #8f93b8; letter-spacing: 0.06em;
      }
    </style>
  </head>
  <body>
    <div id="root" data-composition-id="main" data-start="0" data-duration="30" data-width="1080" data-height="1920">
      <canvas id="stage" width="1080" height="1920"></canvas>
      <div id="vignette"></div>

      <div id="hook" class="cap clip" data-start="0.7" data-duration="3.6" data-track-index="2">
        <div class="small">この光、ぜんぶ</div>
        <div class="big"><em>40,000</em>個の粒</div>
      </div>

      <div id="capA" class="cap clip" data-start="22.3" data-duration="3.0" data-track-index="3">
        <div class="l1">カメラも 生成AIの映像モデルも</div>
        <div class="l2">使っていません</div>
      </div>

      <div id="capC" class="cap clip" data-start="25.1" data-duration="4.9" data-track-index="4">
        <div class="c1">こんな動画を作りたい方は</div>
        <div class="c2">ブログで詳しく解説してます</div>
        <div class="c3">コメント欄を見てください👇</div>
      </div>

      <div id="credit" class="clip" data-start="25.5" data-duration="4.5" data-track-index="5">Music: Sascha Ende, ende.app (CC BY 4.0)</div>

      <div id="fadeout"></div>

      <audio id="bgm" data-start="0" data-duration="30" data-track-index="1" src="assets/bgm.mp3" data-volume="0.9"></audio>
    </div>

    <script>
      // ===== 粒子の変身(Three.js・決まった時刻から毎回同じ絵を描く) =====
      const DURATION = 30;
      const W = 1080, H = 1920;
      const S = window.PARTICLE_SHAPES;
      const N = S.N;

      // 曲 vol-12 の拍(cues json の beats と strongCues から。変形の着地を強い拍に置く)
      const BEATS = [0.56,1.09,1.64,2.19,2.73,3.27,3.82,4.39,4.91,5.34,6.00,6.56,7.09,7.64,8.19,8.74,9.29,9.83,10.37,10.93,11.46,12.02,12.55,13.11,13.64,14.20,14.73,15.29,15.84,16.38,16.93,17.47,18.02,18.56,19.10,19.66,20.19,20.75,21.28,21.84,22.37,22.93,23.46,24.02,24.56,25.11,25.65,26.20,26.74,27.30,27.83,28.37,28.92,29.47];
      const STRONG = [8.74,9.29,10.93,12.55,13.11,13.64,15.84,17.47,18.56,19.66,22.37,22.93,23.46,24.56,25.65,26.74,27.30];
      const BURST_AT = 0.56;
      // 変形: [始め, 着地] 着地は強い拍
      const MORPHS = [
        [3.30, 4.91],   // 渦 → 地球
        [7.10, 8.74],   // 地球 → 日本列島
        [11.46, 13.11], // 日本 → 横顔
        [15.84, 17.47], // 横顔 → 文字
        [20.90, 22.37], // 文字 → 外の輪(締めの字幕の背景)
      ];
      const LANDS = [BURST_AT].concat(MORPHS.map(m => m[1]));

      function decode(b64, polar) {
        const bin = atob(b64);
        const out = new Float32Array(N * 4);
        const dv = new DataView(new ArrayBuffer(bin.length));
        for (let i = 0; i < bin.length; i++) dv.setUint8(i, bin.charCodeAt(i));
        for (let i = 0; i < N; i++) {
          const o = i * 7;
          out[i * 4] = dv.getInt16(o, true) / 8000;
          out[i * 4 + 1] = dv.getInt16(o + 2, true) / (polar ? 10000 : 8000);
          out[i * 4 + 2] = dv.getInt16(o + 4, true) / 8000;
          out[i * 4 + 3] = dv.getUint8(o + 6) / 255;
        }
        return out;
      }
      function mulberry32(a) {
        return function () {
          a |= 0; a = (a + 0x6d2b79f5) | 0;
          let t = Math.imul(a ^ (a >>> 15), 1 | a);
          t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
          return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
        };
      }

      const canvas = document.getElementById("stage");
      const renderer = new THREE.WebGLRenderer({ canvas, antialias: false, alpha: false, preserveDrawingBuffer: true, powerPreference: "high-performance" });
      renderer.setPixelRatio(1);
      renderer.setSize(W, H, false);
      renderer.setClearColor(0x020108, 1);
      const scene = new THREE.Scene();
      const FOV = 50;
      const camera = new THREE.PerspectiveCamera(FOV, W / H, 0.05, 100);
      const PROJ = H / (2 * Math.tan((FOV * Math.PI) / 360));

      // ---- 主の粒子 ----
      const geo = new THREE.BufferGeometry();
      const rand = new Float32Array(N * 4);
      const rr = mulberry32(7);
      for (let i = 0; i < N * 4; i++) rand[i] = rr();
      geo.setAttribute("position", new THREE.BufferAttribute(new Float32Array(N * 3), 3));
      for (let k = 0; k < 6; k++) geo.setAttribute("s" + k, new THREE.BufferAttribute(decode(S.data[k], S.polar[k]), 4));
      geo.setAttribute("rnd", new THREE.BufferAttribute(rand, 4));
      geo.boundingSphere = new THREE.Sphere(new THREE.Vector3(), 50);

      const uniforms = {
        uTime: { value: 0 }, uStage: { value: 0 }, uBurst: { value: 0 },
        uEarthA: { value: 0 }, uEarthB: { value: 0 },
        uFocus: { value: 5 }, uAperture: { value: 9 }, uProj: { value: PROJ },
        uSize: { value: 0.0125 }, uAlpha: { value: 0.5 }, uPulse: { value: 0 }, uFlash: { value: 0 },
      };
      const vert = `
        attribute vec4 s0; attribute vec4 s1; attribute vec4 s2; attribute vec4 s3; attribute vec4 s4; attribute vec4 s5; attribute vec4 rnd;
        uniform float uTime, uStage, uBurst, uEarthA, uEarthB, uFocus, uAperture, uProj, uSize, uAlpha, uPulse, uFlash;
        varying vec3 vCol; varying float vA; varying float vBok;
        mat3 rotY(float a){ float c=cos(a), s=sin(a); return mat3(c,0.,-s, 0.,1.,0., s,0.,c); }
        mat3 rotX(float a){ float c=cos(a), s=sin(a); return mat3(1.,0.,0., 0.,c,s, 0.,-s,c); }
        vec3 polarPos(vec4 p, float speed, float tilt){
          float r = p.x; float th = p.y + uTime * speed / (r * 0.7 + 0.22);
          vec3 q = vec3(r * cos(th), p.z, r * sin(th));
          return rotX(tilt + 0.08 * sin(uTime * 0.3)) * q;
        }
        vec4 shapeAt(int k){
          if (k == 0) return vec4(polarPos(s0, 0.55, -1.12), s0.w);
          if (k == 1) return vec4(rotX(uEarthB) * (rotY(uEarthA) * s1.xyz), s1.w);
          if (k == 2) return s2;
          if (k == 3) return s3;
          if (k == 4) return s4;
          return vec4(polarPos(s5, 0.18, -1.25), s5.w);
        }
        vec3 pal(int k, float b, vec4 r, vec3 p){
          if (k == 0) { float t = clamp(length(p.xz) / 1.8, 0., 1.);
            vec3 c = mix(vec3(1.0,0.86,0.62), vec3(0.42,0.36,1.0), smoothstep(0.0,0.45,t));
            return mix(c, vec3(1.0,0.32,0.85), smoothstep(0.45,1.0,t) * r.y); }
          if (k == 1) { return b > 0.5 ? mix(vec3(0.35,0.95,1.0), vec3(0.9,1.0,1.0), r.y*0.6) : vec3(0.2,0.42,1.0); }
          if (k == 2) { return b > 0.9 ? vec3(1.0,0.95,0.8) : (b > 0.2 ? vec3(1.0,0.78,0.42) * 1.35 : vec3(0.35,0.4,0.9)); }
          if (k == 3) { float t = clamp(p.x * 0.4 + 0.5, 0., 1.); return mix(vec3(1.0,0.35,0.85), vec3(0.4,0.95,1.0), t) * (b > 0.9 ? 1.25 : 1.0); }
          if (k == 4) { return b > 0.9 ? vec3(1.0,0.97,0.9) : vec3(1.0,0.8,0.45) * 1.4; }
          return mix(vec3(0.45,0.38,1.0), vec3(0.3,0.85,1.0), r.z);
        }
        void main(){
          int from = int(floor(clamp(uStage, 0.0, 4.999)));
          int to = from + 1;
          float frac = clamp(uStage - float(from), 0.0, 1.0);
          if (uStage >= 5.0) { from = 5; to = 5; frac = 0.0; }
          vec4 A = shapeAt(from); vec4 B = shapeAt(to);
          // 1 粒ずつ少しずれて動き出す(上から下へ流れる波)
          float d = 0.32 * rnd.x + 0.18 * clamp(0.5 - A.y * 0.18, 0., 1.);
          float l = smoothstep(d, d + 0.5, frac);
          vec3 p = mix(A.xyz, B.xyz, l);
          float sw = sin(l * 3.14159);
          p += sw * (vec3(-p.z, 0.0, p.x) * 0.42 + vec3(0.0, sin(p.x * 2.0 + uTime) * 0.25, 0.0) + (rnd.yzw - 0.5) * 0.32);
          float b = mix(A.w, B.w, l);
          vec3 col = mix(pal(from, A.w, rnd, A.xyz), pal(to, B.w, rnd, B.xyz), l);
          // 冒頭: 1 点から爆発的に広がる
          if (uBurst < 1.0) {
            float pp = clamp((uBurst - rnd.y * 0.1) / 0.9, 0.0, 1.0);
            float g = 1.0 - pow(1.0 - pp, 4.0);
            vec3 dir = normalize(p + 1e-4);
            p = p * g + dir * sin(pp * 3.14159) * (0.5 + 1.6 * rnd.z) + normalize(rnd.xyz - 0.5) * 0.14 * pow(rnd.w, 3.0) * (1.0 - g);
          }
          // 生きているような小さな揺れ
          p += 0.012 * vec3(sin(uTime * 1.3 + rnd.x * 40.0), cos(uTime * 1.1 + rnd.y * 40.0), sin(uTime * 0.9 + rnd.z * 40.0));
          vec4 mv = modelViewMatrix * vec4(p, 1.0);
          float dist = -mv.z;
          float base = uSize * (0.55 + 0.75 * b) * (1.0 + 0.3 * uPulse + 0.6 * uFlash) * uProj / dist;
          float coc = abs(dist - uFocus) * uAperture;
          float size = sqrt(base * base + coc * coc);
          gl_PointSize = clamp(size, 1.0, 64.0);
          vA = uAlpha * (0.25 + 0.95 * b) * min(1.0, (base * base) / (size * size) * 1.4) * (1.0 + 0.6 * uPulse + 1.2 * uFlash) * mix(0.035, 1.0, smoothstep(0.0, 0.3, uBurst));
          vBok = smoothstep(4.0, 18.0, coc);
          vCol = col;
          gl_Position = projectionMatrix * mv;
        }`;
      const frag = `
        varying vec3 vCol; varying float vA; varying float vBok;
        void main(){
          float d = length(gl_PointCoord - 0.5) * 2.0;
          if (d > 1.0) discard;
          float g = exp(-d * d * 4.5);
          float disk = (1.0 - smoothstep(0.75, 1.0, d)) * (0.55 + 0.45 * d);
          float a = mix(g, disk * 0.6, vBok);
          gl_FragColor = vec4(vCol * a * vA, 1.0);
        }`;
      const mat = new THREE.ShaderMaterial({
        uniforms, vertexShader: vert, fragmentShader: frag,
        transparent: true, depthWrite: false, depthTest: false,
        blending: THREE.CustomBlending, blendEquation: THREE.AddEquation,
        blendSrc: THREE.OneFactor, blendDst: THREE.OneFactor,
      });
      const points = new THREE.Points(geo, mat);
      points.frustumCulled = false;
      scene.add(points);

      // ---- 手前と奥の塵(ぼけの玉) ----
      const DN = 1800;
      const dgeo = new THREE.BufferGeometry();
      const dpos = new Float32Array(DN * 3), drnd = new Float32Array(DN * 4);
      const dr = mulberry32(99);
      for (let i = 0; i < DN; i++) {
        dpos[i * 3] = (dr() - 0.5) * 9; dpos[i * 3 + 1] = (dr() - 0.5) * 14; dpos[i * 3 + 2] = -9 + dr() * 13;
        for (let j = 0; j < 4; j++) drnd[i * 4 + j] = dr();
      }
      dgeo.setAttribute("position", new THREE.BufferAttribute(dpos, 3));
      dgeo.setAttribute("rnd", new THREE.BufferAttribute(drnd, 4));
      const dmat = new THREE.ShaderMaterial({
        uniforms,
        vertexShader: `
          attribute vec4 rnd; uniform float uTime, uFocus, uAperture, uProj, uPulse, uBurst;
          varying vec3 vCol; varying float vA; varying float vBok;
          void main(){
            vec3 p = position;
            p.x += sin(uTime * 0.2 + rnd.x * 9.0) * 0.3;
            p.y = mod(position.y + 7.0 + uTime * 0.06 * (0.5 + rnd.y), 14.0) - 7.0;
            vec4 mv = modelViewMatrix * vec4(p, 1.0);
            float dist = max(0.3, -mv.z);
            float base = 0.02 * uProj / dist;
            float coc = abs(dist - uFocus) * uAperture * 0.9;
            float size = sqrt(base*base + coc*coc);
            gl_PointSize = clamp(size, 1.0, 90.0);
            vA = (0.10 + 0.25 * rnd.w) * min(1.0, base*base/(size*size) * 6.0) * smoothstep(0.0, 1.0, uBurst) * (1.0 + 0.5*uPulse);
            vBok = smoothstep(4.0, 18.0, coc);
            vCol = mix(vec3(0.45,0.5,1.0), vec3(1.0,0.6,0.9), rnd.x);
            gl_Position = projectionMatrix * mv;
          }`,
        fragmentShader: frag,
        transparent: true, depthWrite: false, depthTest: false,
        blending: THREE.CustomBlending, blendEquation: THREE.AddEquation,
        blendSrc: THREE.OneFactor, blendDst: THREE.OneFactor,
      });
      const dust = new THREE.Points(dgeo, dmat);
      dust.frustumCulled = false;
      scene.add(dust);

      // ---- 時刻 → 絵 ----
      const clamp01 = (x) => Math.min(1, Math.max(0, x));
      const smooth = (a, b, x) => { const t = clamp01((x - a) / (b - a)); return t * t * (3 - 2 * t); };
      const easeOutExpo = (x) => (x >= 1 ? 1 : 1 - Math.pow(2, -10 * x));
      function stageAt(t) {
        let s = 0;
        MORPHS.forEach(([a, b]) => { s += clamp01((t - a) / (b - a)); });
        return s;
      }
      function pulseAt(t) {
        let p = 0;
        for (const b of BEATS) if (t >= b && t - b < 1.2) p = Math.max(p, 0.55 * Math.exp(-(t - b) * 7));
        for (const b of STRONG) if (t >= b && t - b < 1.2) p = Math.max(p, Math.exp(-(t - b) * 6));
        return p;
      }
      function flashAt(t) {
        let f = 0;
        for (const b of LANDS) if (t >= b && t - b < 2) f = Math.max(f, Math.exp(-(t - b) * 5));
        return f;
      }
      const LON0 = (138.5 * Math.PI) / 180, LAT0 = (36 * Math.PI) / 180;
      function draw(t) {
        uniforms.uTime.value = t;
        uniforms.uStage.value = stageAt(t);
        uniforms.uBurst.value = t < BURST_AT ? 0 : clamp01((t - BURST_AT) / 2.2);
        uniforms.uEarthA.value = -LON0 + 0.3 * (t - 7.1);
        uniforms.uEarthB.value = 0.2 + (LAT0 - 0.2) * smooth(4.0, 7.1, t);
        uniforms.uPulse.value = pulseAt(t);
        // 爆発前は 1 点が脈打つ(ためを作る)
        const pre = t < BURST_AT ? 0.6 + 0.4 * Math.sin(t * 40) * (t / BURST_AT) : 0;
        uniforms.uFlash.value = Math.max(flashAt(t), pre * 1.5);
        // カメラ: 近くから一気に引き、あとはゆっくり回る(文字の間だけ正面に寄せる)
        const pull = easeOutExpo(clamp01((t - BURST_AT) / 2.4));
        let dist = 2.6 + (5.5 - 2.6) * pull;
        dist -= 0.45 * smooth(5, 16, t);
        dist += 0.35 * smooth(16, 18, t) + 0.0 * smooth(21, 24, t);
        const front = smooth(15.9, 17.2, t) - smooth(21.8, 23.2, t);
        const az = (0.36 - 0.36 * front) * Math.sin(t * 0.26 + 0.5);
        const el = 0.14 * Math.sin(t * 0.19 + 0.3) * (1 - 0.8 * front);
        camera.position.set(dist * Math.sin(az) * Math.cos(el), dist * Math.sin(el), dist * Math.cos(az) * Math.cos(el));
        camera.up.set(Math.sin(0.04 * Math.sin(t * 0.21)), 1, 0);
        camera.lookAt(0, 0, 0);
        uniforms.uFocus.value = dist;
        renderer.render(scene, camera);
      }
      draw(0);

      // ---- GSAP の時間軸(hyperframes が時刻を合わせる) ----
      window.__timelines = window.__timelines || {};
      const tl = gsap.timeline({ paused: true });
      const clock = { t: 0 };
      tl.to(clock, { t: DURATION, duration: DURATION, ease: "none", onUpdate: () => draw(clock.t) }, 0);

      // 字幕(最小限)
      tl.from("#hook .small", { opacity: 0, y: 30, duration: 0.5, ease: "power3.out" }, 0.8);
      tl.from("#hook .big", { opacity: 0, scale: 1.25, filter: "blur(12px)", duration: 0.6, ease: "expo.out" }, 1.0);
      tl.to("#hook", { opacity: 0, y: -30, duration: 0.5, ease: "power2.in" }, 3.75);
      tl.from("#capA .l1", { opacity: 0, y: 24, duration: 0.6, ease: "power3.out" }, 22.37);
      tl.from("#capA .l2", { opacity: 0, scale: 0.86, filter: "blur(10px)", duration: 0.7, ease: "back.out(1.6)" }, 22.93);
      tl.to("#capA", { opacity: 0, y: -20, duration: 0.35, ease: "power2.in" }, 24.6);
      tl.from("#capC .c1", { opacity: 0, x: -40, duration: 0.6, ease: "expo.out" }, 25.2);
      tl.from("#capC .c2", { opacity: 0, scale: 1.25, filter: "blur(12px)", duration: 0.7, ease: "power4.out" }, 25.65);
      tl.from("#capC .c3", { opacity: 0, y: 30, duration: 0.6, ease: "back.out(1.6)" }, 26.74);
      tl.from("#credit", { opacity: 0, duration: 0.8, ease: "sine.out" }, 25.9);
      tl.to("#fadeout", { opacity: 1, duration: 1.0, ease: "power1.in" }, 29.0);
      window.__timelines["main"] = tl;
    </script>
  </body>
</html>
1本目 tools/bake_shapes.mjs(360行・クリックで開く)
// 粒子の形を焼いて ../shapes.js に書く(決まった種で毎回同じ結果)。
// 形: 0 渦(極座標) / 1 地球 / 2 日本列島 / 3 横顔 / 4 文字「全部 コードで 描いた」 / 5 外の輪(極座標)
// 使い方: cd project/tools && npm install && node bake_shapes.mjs [--preview <dir>]
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { createRequire } from "node:module";
import * as topojson from "topojson-client";
import opentype from "opentype.js";

const require = createRequire(import.meta.url);
const HERE = path.dirname(fileURLToPath(import.meta.url));
const OUT = path.join(HERE, "..", "shapes.js");
const N = 40000;
const FONT_URL =
  "https://raw.githubusercontent.com/google/fonts/main/ofl/zenkakugothicnew/ZenKakuGothicNew-Black.ttf";
const previewIdx = process.argv.indexOf("--preview");
const PREVIEW_DIR = previewIdx > 0 ? process.argv[previewIdx + 1] : null;

// ---------- 乱数(種つき) ----------
function mulberry32(a) {
  return function () {
    a |= 0; a = (a + 0x6d2b79f5) | 0;
    let t = Math.imul(a ^ (a >>> 15), 1 | a);
    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}
const rnd = mulberry32(20261202);
const gauss = () => {
  const u = Math.max(1e-9, rnd()), v = rnd();
  return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
};

// ---------- 塗りつぶし(非ゼロ規則の走査線) ----------
function rasterize(rings, W, H) {
  // rings: [[ [x,y], ... ], ...] 画素座標
  const grid = new Uint8Array(W * H);
  const edges = [];
  for (const ring of rings) {
    for (let i = 0; i < ring.length; i++) {
      const a = ring[i], b = ring[(i + 1) % ring.length];
      if (a[1] === b[1]) continue;      edges.push(a[1] < b[1] ? [a[0], a[1], b[0], b[1], 1] : [b[0], b[1], a[0], a[1], -1]);
    }
  }
  for (let y = 0; y < H; y++) {
    const yc = y + 0.5;
    const xs = [];
    for (const e of edges) {
      if (yc >= e[1] && yc < e[3]) {
        const x = e[0] + ((yc - e[1]) / (e[3] - e[1])) * (e[2] - e[0]);
        xs.push([x, e[4]]);
      }
    }
    xs.sort((p, q) => p[0] - q[0]);
    let w = 0;
    for (let i = 0; i < xs.length - 1; i++) {
      w += xs[i][1];
      if (w !== 0) {
        const x0 = Math.max(0, Math.ceil(xs[i][0] - 0.5));
        const x1 = Math.min(W - 1, Math.floor(xs[i + 1][0] - 0.5));
        for (let x = x0; x <= x1; x++) grid[y * W + x] = 1;
      }
    }
  }
  return grid;
}
function edgeMap(grid, W, H, r) {
  const e = new Uint8Array(W * H);
  for (let y = 0; y < H; y++)
    for (let x = 0; x < W; x++) {
      if (!grid[y * W + x]) continue;
      let edge = false;
      for (let dy = -r; dy <= r && !edge; dy++)
        for (let dx = -r; dx <= r; dx++) {
          const xx = x + dx, yy = y + dy;
          if (xx < 0 || yy < 0 || xx >= W || yy >= H || !grid[yy * W + xx]) { edge = true; break; }
        }
      e[y * W + x] = edge ? 1 : 0;
    }
  return e;
}
function cellsOf(grid, edges, W, H) {
  const inner = [], edge = [];
  for (let i = 0; i < W * H; i++) if (grid[i]) (edges && edges[i] ? edge : inner).push(i);
  return { inner, edge };
}
// 塗った画素から点を取り、中心 0・幅 widthU の世界座標に写す
function samplePlanar(grid, edges, W, H, count, edgeShare, widthU, bEdge, bInner, zJit) {
  const { inner, edge } = cellsOf(grid, edges, W, H);
  let minX = W, maxX = 0, minY = H, maxY = 0;
  for (const list of [inner, edge]) for (const i of list) {
    const x = i % W, y = (i / W) | 0;
    if (x < minX) minX = x; if (x > maxX) maxX = x; if (y < minY) minY = y; if (y > maxY) maxY = y;
  }
  const cx = (minX + maxX + 1) / 2, cy = (minY + maxY + 1) / 2;
  const s = widthU / (maxX - minX + 1);
  const pts = [];
  for (let k = 0; k < count; k++) {
    const useEdge = edge.length && rnd() < edgeShare;
    const list = useEdge ? edge : inner.length ? inner : edge;
    const i = list[(rnd() * list.length) | 0];
    const x = (i % W) + rnd(), y = ((i / W) | 0) + rnd();
    pts.push([(x - cx) * s, -(y - cy) * s, gauss() * zJit, useEdge ? bEdge : bInner * (0.7 + 0.3 * rnd())]);
  }
  return { pts, heightU: (maxY - minY + 1) * s };
}

// ---------- 0 渦 / 5 輪(極座標で持つ: x=r, y=角度, z=厚み) ----------
function vortex(count) {
  const pts = [];
  for (let k = 0; k < count; k++) {
    const arm = k % 3;
    const r = 0.08 + Math.pow(rnd(), 0.75) * 1.75;
    const theta = (arm * 2 * Math.PI) / 3 + r * 2.9 + gauss() * (0.07 + 0.05 * r);
    const h = gauss() * 0.05 * (1.4 - r / 2);
    const core = Math.exp(-r * 2.2);
    pts.push([r, theta, h, 0.35 + 0.65 * Math.min(1, core * 1.6 + 0.25 * rnd())]);
  }
  return pts;
}
function ring(count) {
  const pts = [];
  for (let k = 0; k < count; k++) {
    const r = 1.75 + Math.abs(gauss()) * 0.55 + rnd() * 0.25;
    const theta = rnd() * Math.PI * 2;
    pts.push([r, theta, gauss() * 0.1, 0.4 + 0.6 * rnd() * rnd()]);
  }
  return pts;
}

// ---------- 1 地球 ----------
function earth(count) {
  const land110 = require("world-atlas/land-50m.json");
  const land = topojson.feature(land110, land110.objects.land);
  const W = 2048, H = 1024;
  const rings = [];
  // 日付変更線をまたぐ輪は経度をつなげてから、左右にずらした写しも一緒に塗る
  const addPoly = (poly) => {
    for (const r of poly) {
      let prev = null, off = 0;
      const un = r.map(([lo, la]) => {
        if (prev !== null) { if (lo + off - prev > 180) off -= 360; else if (lo + off - prev < -180) off += 360; }
        prev = lo + off;
        return [((lo + off + 180) / 360) * W, ((90 - la) / 180) * H];
      });
      for (const sh of [-W, 0, W]) rings.push(un.map(([x, y]) => [x + sh, y]));
    }
  };
  for (const f of land.features) {
    const g = f.geometry;
    if (g.type === "Polygon") addPoly(g.coordinates);
    else for (const p of g.coordinates) addPoly(p);
  }
  const grid = rasterize(rings, W, H);
  const isLand = (lon, lat) => {
    const x = Math.min(W - 1, Math.max(0, Math.floor(((lon + 180) / 360) * W)));
    const y = Math.min(H - 1, Math.max(0, Math.floor(((90 - lat) / 180) * H)));
    return grid[y * W + x] === 1;
  };
  const R = 1.05;
  const pts = [];
  const nLand = Math.round(count * 0.66), nSea = Math.round(count * 0.2), nAir = count - nLand - nSea;
  const sph = () => {
    const z = rnd() * 2 - 1, a = rnd() * Math.PI * 2;
    const lat = (Math.asin(z) * 180) / Math.PI, lon = (a * 180) / Math.PI - 180;
    return [lon, lat];
  };
  const xyz = (lon, lat, r) => {
    const p = (lat * Math.PI) / 180, l = (lon * Math.PI) / 180;
    return [r * Math.cos(p) * Math.sin(l), r * Math.sin(p), r * Math.cos(p) * Math.cos(l)];
  };
  let landCount = 0;
  while (landCount < nLand) {
    const [lo, la] = sph();
    if (la < -62) continue; // 南極は少し減らす(形が読めるように)
    if (!isLand(lo, la)) continue;
    pts.push([...xyz(lo, la, R), 0.75 + 0.25 * rnd()]);
    landCount++;
  }
  let sea = 0;
  while (sea < nSea) {
    const [lo, la] = sph();
    if (isLand(lo, la)) continue;
    pts.push([...xyz(lo, la, R * 0.995), 0.1 + 0.08 * rnd()]);
    sea++;
  }
  for (let k = 0; k < nAir; k++) {
    const [lo, la] = sph();
    pts.push([...xyz(lo, la, R * (1.03 + Math.pow(rnd(), 2.5) * 0.16)), 0.06 + 0.08 * rnd()]);
  }
  return { pts, grid, W, H };
}

// ---------- 2 日本列島 ----------
function japan(count) {
  const topo = require("world-atlas/countries-10m.json");
  const fc = topojson.feature(topo, topo.objects.countries);
  const jp = fc.features.find((f) => f.id === "392");
  const merc = (la) => (Math.log(Math.tan(Math.PI / 4 + (la * Math.PI) / 360)) * 180) / Math.PI;
  const lon0 = 128.6, lon1 = 146.2, la0 = 30.6, la1 = 45.7;
  const W = 1100;
  const sx = W / (lon1 - lon0);
  const H = Math.round((merc(la1) - merc(la0)) * sx);
  const rings = [];
  const polys = jp.geometry.type === "Polygon" ? [jp.geometry.coordinates] : jp.geometry.coordinates;
  for (const poly of polys) for (const r of poly) {
    const inBox = r.some(([lo, la]) => lo > lon0 && lo < lon1 && la > la0 && la < la1);
    if (!inBox) continue;
    rings.push(r.map(([lo, la]) => [(lo - lon0) * sx, (merc(la1) - merc(la)) * sx]));
  }
  const grid = rasterize(rings, W, H);
  const edges = edgeMap(grid, W, H, 2);
  const nMain = Math.round(count * 0.9);
  const { pts, heightU } = samplePlanar(grid, edges, W, H, nMain, 0.38, 2.25, 1.0, 0.62, 0.025);
  for (let k = nMain; k < count; k++) {
    pts.push([(rnd() - 0.5) * 3.4, (rnd() - 0.5) * 5.2, (rnd() - 0.5) * 2.5, 0.05 + 0.06 * rnd()]);
  }
  return { pts, grid, W, H, heightU };
}

// ---------- 3 横顔(自前の輪郭・右向き) ----------
function catmull(pts, seg) {
  const out = [];
  const n = pts.length;
  for (let i = 0; i < n; i++) {
    const p0 = pts[(i - 1 + n) % n], p1 = pts[i], p2 = pts[(i + 1) % n], p3 = pts[(i + 2) % n];
    for (let s = 0; s < seg; s++) {
      const t = s / seg, t2 = t * t, t3 = t2 * t;
      const f = (a, b, c, d) => 0.5 * (2 * b + (-a + c) * t + (2 * a - 5 * b + 4 * c - d) * t2 + (-a + 3 * b - 3 * c + d) * t3);
      out.push([f(p0[0], p1[0], p2[0], p3[0]), f(p0[1], p1[1], p2[1], p3[1])]);
    }
  }
  return out;
}
function face(count) {
  const outline = [
    [430, 110], [560, 98], [665, 140], [735, 222], [768, 320], [775, 405], [798, 462],
    [782, 512], [790, 548], [818, 608], [858, 676], [852, 708], [806, 722], [800, 748],
    [822, 778], [808, 800], [818, 826], [795, 862], [796, 900], [775, 948], [722, 975],
    [645, 988], [612, 1030], [602, 1130], [600, 1260], [585, 1400], [175, 1400],
    [225, 1250], [285, 1110], [300, 1010], [235, 905], [190, 760], [176, 590], [205, 405],
    [272, 248], [345, 158],
  ];
  const W = 1000, H = 1420;
  const poly = catmull(outline, 10);
  const grid = rasterize([poly], W, H);
  const edges = edgeMap(grid, W, H, 3);
  // 目(明るい点の集まり)と耳の線を内側に描き足す
  const eye = [];
  for (let a = 0; a < Math.PI * 2; a += 0.05) eye.push([700 + Math.cos(a) * 30, 500 + Math.sin(a) * 12]);
  const eyeGrid = rasterize([eye], W, H);
  for (let i = 0; i < W * H; i++) if (eyeGrid[i]) edges[i] = 1;
  const ear = [];
  for (let a = -1.4; a <= 1.4; a += 0.05) ear.push([440 + Math.cos(a) * 46, 600 + Math.sin(a) * 78]);
  for (let a = 1.4; a >= -1.4; a -= 0.05) ear.push([440 + Math.cos(a) * 34, 600 + Math.sin(a) * 64]);
  const earGrid = rasterize([ear], W, H);
  for (let i = 0; i < W * H; i++) if (earGrid[i]) edges[i] = 1;
  const nMain = Math.round(count * 0.94);
  const { pts, heightU } = samplePlanar(grid, edges, W, H, nMain, 0.42, 2.3, 1.0, 0.42, 0.06);
  for (let k = nMain; k < count; k++) {
    pts.push([(rnd() - 0.5) * 3.6, (rnd() - 0.5) * 5.4, (rnd() - 0.5) * 2.5, 0.05 + 0.05 * rnd()]);
  }
  return { pts, grid, edges, W, H, heightU };
}

// ---------- 4 文字 ----------
async function loadFont() {
  const cache = path.join(HERE, "cache", "ZenKakuGothicNew-Black.ttf");
  if (!fs.existsSync(cache)) {
    fs.mkdirSync(path.dirname(cache), { recursive: true });
    const res = await fetch(FONT_URL);
    if (!res.ok) throw new Error("font download failed " + res.status);
    fs.writeFileSync(cache, Buffer.from(await res.arrayBuffer()));
  }
  const buf = fs.readFileSync(cache);
  return opentype.parse(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
}
function pathToRings(p) {
  const rings = [];
  let cur = [], x = 0, y = 0;
  for (const c of p.commands) {
    if (c.type === "M") { if (cur.length) rings.push(cur); cur = [[c.x, c.y]]; x = c.x; y = c.y; }
    else if (c.type === "L") { cur.push([c.x, c.y]); x = c.x; y = c.y; }
    else if (c.type === "Q") {
      for (let s = 1; s <= 10; s++) { const t = s / 10, u = 1 - t;
        cur.push([u * u * x + 2 * u * t * c.x1 + t * t * c.x, u * u * y + 2 * u * t * c.y1 + t * t * c.y]); }
      x = c.x; y = c.y;
    } else if (c.type === "C") {
      for (let s = 1; s <= 12; s++) { const t = s / 12, u = 1 - t;
        cur.push([u*u*u*x + 3*u*u*t*c.x1 + 3*u*t*t*c.x2 + t*t*t*c.x, u*u*u*y + 3*u*u*t*c.y1 + 3*u*t*t*c.y2 + t*t*t*c.y]); }
      x = c.x; y = c.y;
    } else if (c.type === "Z") { if (cur.length) rings.push(cur); cur = []; }
  }
  if (cur.length) rings.push(cur);
  return rings;
}
async function text(count) {
  const font = await loadFont();
  const lines = ["全部", "コードで", "描いた"];
  const size = 300, lineH = 370, W = 1300, H = 60 + lineH * lines.length;
  const rings = [];
  lines.forEach((ln, i) => {
    const adv = font.getAdvanceWidth(ln, size);
    const p = font.getPath(ln, (W - adv) / 2, 40 + size + i * lineH - 40, size);
    rings.push(...pathToRings(p));
  });
  const grid = rasterize(rings, W, H);
  const edges = edgeMap(grid, W, H, 3);
  const nMain = Math.round(count * 0.95);
  const { pts, heightU } = samplePlanar(grid, edges, W, H, nMain, 0.45, 2.25, 1.0, 0.55, 0.03);
  for (let k = nMain; k < count; k++) {
    pts.push([(rnd() - 0.5) * 3.6, (rnd() - 0.5) * 5.4, (rnd() - 0.5) * 2.5, 0.05 + 0.05 * rnd()]);
  }
  return { pts, grid, edges, W, H, heightU };
}

// ---------- 書き出し ----------
function shuffleInPlace(a) {
  for (let i = a.length - 1; i > 0; i--) { const j = (rnd() * (i + 1)) | 0; [a[i], a[j]] = [a[j], a[i]]; }
  return a;
}
function encode(pts, polar) {
  // xyz を Int16(polar のとき y=角度は 1/4096 rad 単位)、b を Uint8 に詰める
  const buf = Buffer.alloc(pts.length * 7);
  pts.forEach((p, i) => {
    const q = (v, s) => Math.max(-32767, Math.min(32767, Math.round(v * s)));
    buf.writeInt16LE(q(p[0], 8000), i * 7);
    buf.writeInt16LE(polar ? q(((p[1] % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI) - Math.PI, 10000) : q(p[1], 8000), i * 7 + 2);
    buf.writeInt16LE(q(p[2], 8000), i * 7 + 4);
    buf.writeUInt8(Math.max(0, Math.min(255, Math.round(p[3] * 255))), i * 7 + 6);
  });
  return buf.toString("base64");
}
function writePGM(file, grid, W, H, edges) {
  const body = Buffer.alloc(W * H);
  for (let i = 0; i < W * H; i++) body[i] = edges && edges[i] ? 255 : grid[i] ? 110 : 0;
  fs.writeFileSync(file, Buffer.concat([Buffer.from(`P5\n${W} ${H}\n255\n`), body]));
}

const shapes = [];
const v = vortex(N); shuffleInPlace(v);
const e = earth(N); shuffleInPlace(e.pts);
const j = japan(N); shuffleInPlace(j.pts);
const f = face(N); shuffleInPlace(f.pts);
const t = await text(N); shuffleInPlace(t.pts);
const r = ring(N); shuffleInPlace(r);
shapes.push(encode(v, true), encode(e.pts, false), encode(j.pts, false), encode(f.pts, false), encode(t.pts, false), encode(r, true));
const js =
  "// 自動生成: tools/bake_shapes.mjs(手で直さない)\n" +
  `window.PARTICLE_SHAPES = { N: ${N}, names: ["vortex","earth","japan","face","text","ring"], polar: [true,false,false,false,false,true], data: ${JSON.stringify(shapes)} };\n`;
fs.writeFileSync(OUT, js);
console.log("wrote", OUT, (js.length / 1024 / 1024).toFixed(2) + " MB", "japanH", j.heightU.toFixed(2), "faceH", f.heightU.toFixed(2), "textH", t.heightU.toFixed(2));
if (PREVIEW_DIR) {
  fs.mkdirSync(PREVIEW_DIR, { recursive: true });
  writePGM(path.join(PREVIEW_DIR, "land.pgm"), e.grid, e.W, e.H);
  writePGM(path.join(PREVIEW_DIR, "japan.pgm"), j.grid, j.W, j.H);
  writePGM(path.join(PREVIEW_DIR, "face.pgm"), f.grid, f.W, f.H, f.edges);
  writePGM(path.join(PREVIEW_DIR, "text.pgm"), t.grid, t.W, t.H, t.edges);
}

2本目(存在しない街)のコード

index.html は場面の切り替えと文字だけで、街・雲・車の光・夜明けは city.js がThree.jsで組み立てています。assets/three.min.js と assets/gsap.min.js は配布されているライブラリをそのまま置いた物なので載せていません。sound/mix.py は、曲と効果音を30秒の音声1本に混ぜる道具です。書き出しは npx --yes hyperframes@0.8.33 render で作りました。

2本目 index.html(109行・クリックで開く)
<!doctype html>
<html lang="ja">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=1080, height=1920" />
    <title>存在しない街</title>
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@500;700;900&display=block" rel="stylesheet" />
    <style>
      html, body { margin: 0; padding: 0; background: #04060c; }
      #root { position: relative; width: 1080px; height: 1920px; overflow: hidden; background: #04060c; }
      #city { position: absolute; left: 0; top: 0; width: 1080px; height: 1920px; display: block; }
      .cap {
        position: absolute; left: 0; width: 1080px; box-sizing: border-box; padding: 0 70px;
        text-align: center; color: #f6f2ea; font-family: "Noto Sans JP", sans-serif;
        text-shadow: 0 0 30px rgba(2, 4, 12, 0.85), 0 2px 6px rgba(2, 4, 12, 0.9);
        line-height: 1.25; z-index: 5;
      }
      .cap .ln { display: block; white-space: nowrap; }
      .cap .ch { display: inline-block; }
      #hook { top: 300px; font-size: 92px; font-weight: 900; letter-spacing: 0.04em; }
      #hook .sub { font-size: 40px; font-weight: 700; letter-spacing: 0.32em; color: #cfe6ff; margin-bottom: 18px; }
      #l2 { top: 330px; font-size: 56px; font-weight: 700; letter-spacing: 0.03em; }
      #l3 { top: 632px; font-size: 58px; font-weight: 900; letter-spacing: 0.02em; padding: 0 164px 0 44px; line-height: 1.55; z-index: 6; }
      #l3 .accent { color: #ffd9a8; }
      #panel { position: absolute; left: 44px; top: 612px; width: 872px; height: 318px; z-index: 5; border-radius: 36px;
        background: rgba(4, 8, 20, 0.55); opacity: 0; }
      #shade { position: absolute; left: 0; top: 0; width: 1080px; height: 1000px; z-index: 4;
        background: radial-gradient(ellipse 120% 70% at 50% 25%, rgba(2,4,12,0.55) 0%, rgba(2,4,12,0.0) 70%); opacity: 0; }
    </style>
  </head>
  <body>
    <div id="root" data-composition-id="root" data-start="0" data-duration="30" data-width="1080" data-height="1920" data-fps="30">
      <canvas id="city" width="1080" height="1920"></canvas>
      <div id="shade"></div>

      <div id="hook" class="cap clip" data-start="2.0" data-duration="3.6" data-track-index="2">
        <span class="ln sub">AERIAL ・ 空撮</span>
        <span class="ln main">この街は 存在しません</span>
      </div>

      <div id="l2" class="cap clip" data-start="23.6" data-duration="1.7" data-track-index="3">
        <span class="ln">カメラも 映像生成AIも</span>
        <span class="ln">使っていない</span>
      </div>

      <div id="panel" class="clip" data-start="25.1" data-duration="4.9" data-track-index="5"></div>
      <div id="l3" class="cap clip" data-start="25.3" data-duration="4.7" data-track-index="4">
        <span class="ln">こんな動画を作りたい方は</span>
        <span class="ln"><span class="accent">ブログで詳しく解説してます</span></span>
        <span class="ln">コメント欄を見てください👇</span>
      </div>

      <audio id="soundtrack" class="clip" data-start="0" data-duration="30" data-track-index="6" data-volume="1" src="assets/soundtrack.wav"></audio>

      <script src="assets/three.min.js"></script>
      <script src="assets/gsap.min.js"></script>
      <script src="city.js"></script>
      <script>
        (function () {
          // 字幕を 1 文字ずつの span に分ける(同期で行う)
          function split(sel) {
            document.querySelectorAll(sel).forEach(function (ln) {
              var nodes = Array.prototype.slice.call(ln.childNodes);
              ln.innerHTML = "";
              nodes.forEach(function (nd) {
                var txt = nd.textContent, wrap = nd.nodeType === 1 ? nd.cloneNode(false) : null;
                var host = wrap || ln;
                if (wrap) ln.appendChild(wrap);
                for (var i = 0; i < txt.length; i++) {
                  var s = document.createElement("span");
                  s.className = "ch";
                  s.textContent = txt[i] === " " ? " " : txt[i];
                  host.appendChild(s);
                }
              });
            });
          }
          split("#hook .main, #l2 .ln");

          var tl = gsap.timeline({ paused: true });
          var proxy = { t: 0 };
          tl.to(proxy, { t: 30, duration: 30, ease: "none", onUpdate: function () { window.renderCity(proxy.t); } }, 0);

          // 冒頭のつかみ
          tl.fromTo("#shade", { opacity: 0 }, { opacity: 1, duration: 0.6, ease: "power2.out" }, 2.0);
          tl.to("#shade", { opacity: 0, duration: 0.6, ease: "power2.in" }, 5.0);
          tl.fromTo("#hook .sub", { opacity: 0, y: -24 }, { opacity: 1, y: 0, duration: 0.9, ease: "expo.out" }, 2.1);
          tl.fromTo("#hook .main .ch", { opacity: 0, y: 40, filter: "blur(12px)" },
            { opacity: 1, y: 0, filter: "blur(0px)", duration: 0.55, ease: "power3.out", stagger: 0.045 }, 2.25);
          tl.to("#hook", { opacity: 0, y: -30, duration: 0.45, ease: "power2.in" }, 5.1);

          // 締め
          tl.fromTo("#shade", { opacity: 0 }, { opacity: 1, duration: 0.8, ease: "sine.out", immediateRender: false }, 23.4);
          tl.fromTo("#l2 .ch", { opacity: 0, y: 26, filter: "blur(10px)" },
            { opacity: 1, y: 0, filter: "blur(0px)", duration: 0.5, ease: "power2.out", stagger: 0.035 }, 23.65);
          tl.to("#l2", { opacity: 0, y: -16, duration: 0.45, ease: "power1.in" }, 25.0);
          tl.fromTo("#panel", { opacity: 0 }, { opacity: 1, duration: 0.6, ease: "sine.out", immediateRender: false }, 25.1);
          tl.fromTo("#l3 .ln", { opacity: 0, y: 30, filter: "blur(10px)" },
            { opacity: 1, y: 0, filter: "blur(0px)", duration: 0.6, ease: "power3.out", stagger: 0.35 }, 25.4);

          window.__timelines = window.__timelines || {};
          window.__timelines["root"] = tl;
        })();
      </script>
    </div>
  </body>
</html>
2本目 city.js(917行・クリックで開く)
/* 存在しない街 — Three.js で手続き的に作る夜の未来都市。
   すべての絵は時刻 t だけで決まる(乱数は種つき・Date/Math.random は使わない)。
   window.renderCity(t) を GSAP の proxy tween が呼ぶ。 */
(function () {
  "use strict";
  var W = 1080, H = 1920, DUR = 30;
  var canvas = document.getElementById("city");
  var renderer = new THREE.WebGLRenderer({
    canvas: canvas, antialias: false, preserveDrawingBuffer: true,
    powerPreference: "high-performance", alpha: false
  });
  renderer.setPixelRatio(1);
  renderer.setSize(W, H, false);
  renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
  renderer.toneMapping = THREE.NoToneMapping;

  // ---------- 種つき乱数
  function mulberry32(a) {
    return function () {
      a |= 0; a = (a + 0x6d2b79f5) | 0;
      var t = Math.imul(a ^ (a >>> 15), 1 | a);
      t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
      return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
    };
  }
  var rnd = mulberry32(20261202);
  function sstep(a, b, x) { var t = Math.min(Math.max((x - a) / (b - a), 0), 1); return t * t * (3 - 2 * t); }
  function lerp(a, b, t) { return a + (b - a) * t; }

  // ---------- カメラの経路(時刻つきの Catmull-Rom = 時間で滑らか)
  // [t, x, y, z]
  var PK = [
    [0.0, 0, 468, 420], [0.8, 0, 362, 300], [1.6, 0, 250, 215], [3.0, 0, 140, 120],
    [4.6, 0, 62, 20], [6.5, 0, 24, -120], [8.7, 0, 17, -300], [10.5, -3, 22, -415],
    [12.0, -7, 28, -520], [13.1, 7, 32, -604], [15.0, -7, 38, -764], [17.5, 0, 36, -1002],
    [19.0, 0, 48, -1100], [20.5, 0, 125, -1148], [22.0, 0, 265, -1162], [22.93, 0, 335, -1196],
    [24.5, 0, 392, -1256], [30.0, 0, 448, -1368]
  ];
  var LK1 = [[0.0, 0, 395, -900], [0.25, 0, 330, -700], [0.75, 0, 40, 30], [1.6, 0, 0, -30], [3.0, 0, 8, -175], [4.6, 0, 16, -235], [6.0, 0, 18, -300]];
  var LK2 = [[17.0, 0, 60, -1182], [18.6, 0, 110, -1182], [19.0, 0, 150, -1182], [20.5, 0, 275, -1182],
    [22.0, 0, 350, -1205], [22.93, 0, 345, -1330], [24.5, -20, 330, -1950], [30.0, -60, 360, -2300]];
  var FK = [[0, 62], [0.6, 60], [1.6, 68], [6.0, 78], [13.0, 82], [17.5, 86], [19.0, 76], [22.9, 66], [30, 56]];

  function crEval(keys, t, dims) {
    var n = keys.length;
    if (t <= keys[0][0]) return keys[0].slice(1);
    if (t >= keys[n - 1][0]) return keys[n - 1].slice(1);
    var i = 0;
    while (i < n - 2 && t >= keys[i + 1][0]) i++;
    var k1 = keys[i], k2 = keys[i + 1];
    var k0 = i > 0 ? keys[i - 1] : null, k3 = i + 2 < n ? keys[i + 2] : null;
    var t1 = k1[0], t2 = k2[0];
    var t0 = k0 ? k0[0] : t1 - (t2 - t1), t3 = k3 ? k3[0] : t2 + (t2 - t1);
    var out = [];
    for (var d = 1; d <= dims; d++) {
      var p1 = k1[d], p2 = k2[d];
      var p0 = k0 ? k0[d] : 2 * p1 - p2, p3 = k3 ? k3[d] : 2 * p2 - p1;
      var a1 = ((t1 - t) * p0 + (t - t0) * p1) / (t1 - t0);
      var a2 = ((t2 - t) * p1 + (t - t1) * p2) / (t2 - t1);
      var a3 = ((t3 - t) * p2 + (t - t2) * p3) / (t3 - t2);
      var b1 = ((t2 - t) * a1 + (t - t0) * a2) / (t2 - t0);
      var b2 = ((t3 - t) * a2 + (t - t1) * a3) / (t3 - t1);
      out.push(((t2 - t) * b1 + (t - t1) * b2) / (t2 - t1));
    }
    return out;
  }
  function camPos(t) { return crEval(PK, t, 3); }
  function camLook(t) {
    var a = crEval(LK1, t, 3);
    var la = camPos(Math.min(t + 0.75, DUR));
    la[1] -= 4;
    var b = crEval(LK2, t, 3);
    var w1 = sstep(4.0, 5.6, t), w2 = sstep(17.6, 19.0, t);
    var r = [];
    for (var d = 0; d < 3; d++) r.push(lerp(lerp(a[d], la[d], w1), b[d], w2));
    return r;
  }

  // ---------- GLSL の共通部品
  var COMMON = [
    "uniform float uTime; uniform float uDawn; uniform vec3 uSunDir; uniform vec3 uEye; uniform float uDimAll;",
    "float hash11(float p){p=fract(p*.1031);p*=p+33.33;p*=p+p;return fract(p);}",
    "float hash12(vec2 p){vec3 p3=fract(vec3(p.xyx)*.1031);p3+=dot(p3,p3.yzx+33.33);return fract((p3.x+p3.y)*p3.z);}",
    "float hash13(vec3 p3){p3=fract(p3*.1031);p3+=dot(p3,p3.zyx+31.32);return fract((p3.x+p3.y)*p3.z);}",
    "float vnoise(vec2 p){vec2 i=floor(p),f=fract(p);f=f*f*(3.-2.*f);",
    " return mix(mix(hash12(i),hash12(i+vec2(1,0)),f.x),mix(hash12(i+vec2(0,1)),hash12(i+vec2(1,1)),f.x),f.y);}",
    "float fbm(vec2 p){float v=0.,a=.5;mat2 R=mat2(.8,.6,-.6,.8);for(int i=0;i<5;i++){v+=a*vnoise(p);p=R*p*2.03;a*=.5;}return v;}",
    "vec3 skyBase(vec3 d){",
    "  float h=d.y;",
    "  vec3 zen=mix(vec3(.003,.005,.016),vec3(.025,.06,.17),uDawn);",
    "  vec2 dh=normalize(d.xz+1e-5); vec2 sh=normalize(uSunDir.xz);",
    "  float az=max(dot(dh,sh),0.);",
    "  vec3 horNight=vec3(.06,.035,.075);",
    "  vec3 horDawn=mix(vec3(.16,.11,.2),vec3(.95,.38,.14),pow(az,3.));",
    "  vec3 hor=mix(horNight,horDawn,uDawn);",
    "  float t=pow(clamp(1.-max(h,0.),0.,1.),5.);",
    "  vec3 c=mix(zen,hor,t);",
    "  c+=vec3(.07,.026,.045)*pow(clamp(1.-abs(h)*5.,0.,1.),2.)*(1.-uDawn*.7);",
    "  float sd=max(dot(d,uSunDir),0.);",
    "  c+=vec3(1.1,.45,.16)*pow(sd,14.)*uDawn;",
    "  return c;",
    "}",
    "vec3 skyCol(vec3 d){ return skyBase(d)+vec3(7.,3.6,1.5)*pow(max(dot(d,uSunDir),0.),1500.)*uDawn; }",
    "float fogAmt(vec3 wpos){",
    "  vec3 d=wpos-uEye; float dist=length(d);",
    "  float Hf=85.; float y0=max(uEye.y,0.); float y1=max(wpos.y,0.); float dy=y1-y0;",
    "  float k=abs(dy)>.05?(exp(-y0/Hf)-exp(-y1/Hf))/(dy/Hf):exp(-y0/Hf);",
    "  return 1.-exp(-(0.0020*k+0.00008)*dist);",
    "}",
    "vec3 fogCol(vec3 wpos){",
    "  vec3 dir=normalize(wpos-uEye);",
    "  vec3 fc=skyBase(normalize(vec3(dir.x,max(dir.y,0.)*.4+.015,dir.z)));",
    "  return fc*.8+vec3(.035,.016,.024)*(1.-uDawn*.6);",
    "}",
    "vec3 applyFog(vec3 col,vec3 wpos){return mix(col,fogCol(wpos),fogAmt(wpos));}"
  ].join("\n");

  var U = {
    uTime: { value: 0 }, uDawn: { value: 0 },
    uSunDir: { value: new THREE.Vector3(0, -0.04, -1).normalize() },
    uEye: { value: new THREE.Vector3() }, uDimAll: { value: 1 }
  };
  function mkMat(opts) {
    var u = Object.assign({}, U, opts.uniforms || {});
    var m = new THREE.ShaderMaterial({
      uniforms: u, vertexShader: COMMON + "\n" + opts.vs, fragmentShader: COMMON + "\n" + opts.fs,
      transparent: !!opts.transparent, depthWrite: opts.depthWrite !== undefined ? opts.depthWrite : true,
      depthTest: opts.depthTest !== undefined ? opts.depthTest : true,
      blending: opts.blending || THREE.NormalBlending, side: opts.side || THREE.FrontSide
    });
    return m;
  }

  var scene = new THREE.Scene();
  var camera = new THREE.PerspectiveCamera(70, W / H, 0.5, 40000);
  camera.layers.enable(1);

  // ---------- 空
  var skyMat = mkMat({
    vs: "varying vec3 vDir; void main(){ vDir=normalize(position); vec4 p=projectionMatrix*modelViewMatrix*vec4(position,1.); gl_Position=p.xyww; }",
    fs: [
      "varying vec3 vDir;",
      "void main(){ vec3 d=normalize(vDir); vec3 c=skyCol(d);",
      "  float h=d.y;",
      "  vec3 sp=floor(d*520.); float st=hash13(sp); float star=step(.9975,st)*(0.5+2.5*hash13(sp+3.))*smoothstep(.03,.35,h)*(1.-uDawn);",
      "  c+=vec3(.8,.85,1.)*star*0.9;",
      "  vec3 md=normalize(vec3(-.17,.27,-.95)); float mdot=max(dot(d,md),0.);",
      "  c+=vec3(.9,.95,1.1)*(smoothstep(.99955,.9997,mdot)*4.+pow(mdot,300.)*.25)*clamp(1.-uDawn*3.,0.,1.);",
      "  float az=atan(d.x,-d.z);",
      "  float band=smoothstep(.0,.05,h)*(1.-smoothstep(.07,.30,h));",
      "  float cl=fbm(vec2(az*7.,h*38.+az*2.)); cl=smoothstep(.45,.75,cl)*band;",
      "  vec3 clN=vec3(.07,.04,.07); vec3 clD=mix(vec3(.35,.22,.38),vec3(1.5,.62,.35),pow(max(dot(normalize(d.xz+1e-5),normalize(uSunDir.xz)),0.),2.));",
      "  c=mix(c,mix(clN,clD,uDawn),cl*.85);",
      "  gl_FragColor=vec4(c,1.); }"
    ].join("\n"),
    side: THREE.BackSide, depthWrite: false
  });
  var sky = new THREE.Mesh(new THREE.SphereGeometry(9000, 48, 24), skyMat);
  sky.renderOrder = -10;
  sky.frustumCulled = false;
  scene.add(sky);

  // ---------- 街の区画と建物
  var P = 46, SW = 5, CANAL_Z = -322, CANAL_HW = 15;
  function avHalf(z) { return (z < -430 && z > -1120) ? 16 : 11; }
  var MEGA = { x0: -24, x1: 24, z0: -1230, z1: -1182, h: 288 };
  var BRIDGES = [{ z: -520, y0: 50, y1: 54 }, { z: -764, y0: 47, y1: 51 }, { z: -1002, y0: 44.5, y1: 48.5 }];
  var blds = [];
  function heightAt(x, z, r) {
    var dt = Math.exp(-((x * x) / (380 * 380) + ((z + 950) * (z + 950)) / (520 * 520)));
    var dt2 = Math.exp(-(((x - 300) * (x - 300)) / (170 * 170) + ((z + 1800) * (z + 1800)) / (300 * 300)));
    var dt3 = Math.exp(-(((x + 330) * (x + 330)) / (160 * 160) + ((z + 1500) * (z + 1500)) / (260 * 260)));
    var h = 8 + 16 * r + dt * (70 + 190 * r * r) + dt2 * (40 + 150 * r * r) + dt3 * (30 + 140 * r * r);
    if (Math.abs(x) < 60 && z < 80) h = Math.max(h, 26 + 44 * r + dt * 60);
    if (Math.abs(z - CANAL_Z) < 75) h = Math.max(h, 30 + 50 * r);
    var e = Math.abs(x) / 700;
    h *= 1 - 0.5 * sstep(0.6, 1.0, e);
    return h;
  }
  function addB(x0, x1, z0, z1, y0, y1, style, seed, lit) {
    blds.push({ x0: x0, x1: x1, z0: z0, z1: z1, y0: y0, y1: y1, style: style, seed: seed, lit: lit });
  }
  for (var i = -15; i < 15; i++) {
    for (var j = -54; j < 6; j++) {
      var x0 = i * P + SW, x1 = (i + 1) * P - SW, z0 = j * P + SW, z1 = (j + 1) * P - SW;
      var zc = (z0 + z1) / 2;
      if (i === 0) x0 = Math.max(x0, avHalf(zc));
      if (i === -1) x1 = Math.min(x1, -avHalf(zc));
      if (z1 > CANAL_Z - CANAL_HW && z0 < CANAL_Z + CANAL_HW) {
        if (zc < CANAL_Z) z1 = CANAL_Z - CANAL_HW; else z0 = CANAL_Z + CANAL_HW;
      }
      if (x1 - x0 < 6 || z1 - z0 < 6) continue;
      if (x1 > -70 && x0 < 70 && z1 > -1275 && z0 < -1140) continue;
      var r = rnd(), lots = [];
      if (r < 0.28) lots.push([x0, x1, z0, z1]);
      else if (r < 0.52) { var xm = x0 + (x1 - x0) * (0.35 + 0.3 * rnd()); lots.push([x0, xm - 1, z0, z1], [xm + 1, x1, z0, z1]); }
      else if (r < 0.76) { var zm = z0 + (z1 - z0) * (0.35 + 0.3 * rnd()); lots.push([x0, x1, z0, zm - 1], [x0, x1, zm + 1, z1]); }
      else {
        var xm2 = x0 + (x1 - x0) * (0.4 + 0.2 * rnd()), zm2 = z0 + (z1 - z0) * (0.4 + 0.2 * rnd());
        lots.push([x0, xm2 - 1, z0, zm2 - 1], [xm2 + 1, x1, z0, zm2 - 1], [x0, xm2 - 1, zm2 + 1, z1], [xm2 + 1, x1, zm2 + 1, z1]);
      }
      for (var l = 0; l < lots.length; l++) {
        var L = lots[l];
        if (L[1] - L[0] < 4 || L[3] - L[2] < 4) continue;
        var cx = (L[0] + L[1]) / 2, cz = (L[2] + L[3]) / 2;
        var rr = rnd();
        var h = heightAt(cx, cz, rr);
        var dtn = Math.exp(-((cx * cx) / (380 * 380) + ((cz + 950) * (cz + 950)) / (520 * 520)));
        if (dtn > 0.45 && rnd() < 0.08) h = Math.min(h * 1.5, 235);
        var front = (Math.abs(L[0] - avHalf(cz)) < 0.01) || (Math.abs(L[1] + avHalf(cz)) < 0.01);
        for (var b = 0; b < BRIDGES.length; b++) {
          if (front && Math.abs(cz - BRIDGES[b].z) < 26) h = Math.max(h, BRIDGES[b].y1 + 30 + 30 * rnd());
        }
        h = Math.min(h, 250);
        var style = 0, sr = rnd();
        if (sr < (front ? 0.3 : 0.1) + dtn * 0.08) style = 1;
        else if (sr > 0.86 && h > 60) style = 2;
        var lit = 0.10 + 0.32 * rnd() + dtn * 0.12;
        var seed = rnd() * 1000;
        if (h > 75 && rnd() < 0.6) {
          var ix = (L[1] - L[0]) * 0.14, iz = (L[3] - L[2]) * 0.14;
          addB(L[0], L[1], L[2], L[3], 0, h * 0.62, style, seed, lit);
          addB(L[0] + ix, L[1] - ix, L[2] + iz, L[3] - iz, h * 0.62, h * 0.86, style, seed + 1, lit);
          addB(L[0] + 2 * ix, L[1] - 2 * ix, L[2] + 2 * iz, L[3] - 2 * iz, h * 0.86, h, style, seed + 2, lit);
        } else {
          addB(L[0], L[1], L[2], L[3], 0, h, style, seed, lit);
        }
      }
    }
  }
  // 中央の超高層(最後に駆け上がる塔)
  addB(MEGA.x0, MEGA.x1, MEGA.z0, MEGA.z1, 0, MEGA.h, 3, 777, 0.7);
  addB(16.5, 19.5, -1207.5, -1204.5, MEGA.h, MEGA.h + 58, 4, 778, 0);
  addB(-19.5, -16.5, -1207.5, -1204.5, MEGA.h, MEGA.h + 58, 4, 779, 0);
  var nonBridgeCount = blds.length;
  // 空中の渡り廊下(カメラはこの下をくぐる)
  for (var bi = 0; bi < BRIDGES.length; bi++) {
    var BR = BRIDGES[bi], ah = avHalf(BR.z);
    addB(-ah - 1, ah + 1, BR.z - 3.5, BR.z + 3.5, BR.y0, BR.y1, 5, 900 + bi, 0.9);
  }

  // 経路とぶつかる建物を低くする(カメラが壁を抜けないように)
  var samples = [];
  for (var ts = 1.2; ts <= DUR; ts += 1 / 60) samples.push(camPos(ts));
  for (var bb = 0; bb < nonBridgeCount; bb++) {
    var B = blds[bb];
    if (B.style >= 3) continue;
    for (var s = 0; s < samples.length; s++) {
      var S = samples[s];
      var dx = Math.max(Math.abs(S[0] - (B.x0 + B.x1) / 2) - (B.x1 - B.x0) / 2, 0);
      var dz = Math.max(Math.abs(S[2] - (B.z0 + B.z1) / 2) - (B.z1 - B.z0) / 2, 0);
      var dh = Math.sqrt(dx * dx + dz * dz);
      if (dh < 5.5 && B.y1 > S[1] - 9 && B.y0 < S[1] + 9) {
        if (B.y0 < S[1] - 14) B.y1 = S[1] - 14; else { B.y1 = B.y0; }
      }
    }
  }
  blds = blds.filter(function (q) { return q.y1 - q.y0 > 1; });

  var boxGeo = new THREE.BoxGeometry(1, 1, 1);
  boxGeo.translate(0, 0.5, 0);
  var NB = blds.length;
  var aSeed = new Float32Array(NB), aStyle = new Float32Array(NB), aLit = new Float32Array(NB);
  var bGeo = boxGeo.clone();
  bGeo.setAttribute("aSeed", new THREE.InstancedBufferAttribute(aSeed, 1));
  bGeo.setAttribute("aStyle", new THREE.InstancedBufferAttribute(aStyle, 1));
  bGeo.setAttribute("aLit", new THREE.InstancedBufferAttribute(aLit, 1));
  var bMat = mkMat({
    vs: [
      "attribute float aSeed; attribute float aStyle; attribute float aLit;",
      "varying vec3 vW; varying vec3 vN; varying vec3 vL; varying vec3 vSize; varying float vSeed; varying float vStyle; varying float vLit; varying float vBase;",
      "void main(){",
      "  vec4 wp=modelMatrix*instanceMatrix*vec4(position,1.);",
      "  vW=wp.xyz; vN=normalize(mat3(instanceMatrix)*normal);",
      "  vSize=vec3(length(instanceMatrix[0].xyz),length(instanceMatrix[1].xyz),length(instanceMatrix[2].xyz));",
      "  vL=position*vSize; vBase=instanceMatrix[3].y;",
      "  vSeed=aSeed; vStyle=aStyle; vLit=aLit;",
      "  gl_Position=projectionMatrix*viewMatrix*wp; }"
    ].join("\n"),
    fs: [
      "varying vec3 vW; varying vec3 vN; varying vec3 vL; varying vec3 vSize; varying float vSeed; varying float vStyle; varying float vLit; varying float vBase;",
      "vec3 neonC(float s){ float k=hash11(s*1.77); return k<.3?vec3(1.,.12,.55):(k<.55?vec3(.1,.85,1.):(k<.8?vec3(.65,.25,1.):vec3(1.,.55,.12))); }",
      "void main(){",
      "  vec3 n=normalize(vN); vec3 V=normalize(cameraPosition-vW);",
      "  float side=1.-step(.5,abs(n.y));",
      "  float u=abs(n.x)>.5?vL.z:vL.x; float hw=(abs(n.x)>.5?vSize.z:vSize.x)*.5;",
      "  float v=vW.y;",
      "  float faceId=abs(n.x)>.5?(n.x>0.?1.:2.):(n.z>0.?3.:4.);",
      "  float fh=3.1+0.5*floor(hash11(vSeed*7.1)*3.);",
      "  float ww=1.8+1.5*hash11(vSeed*3.3);",
      "  if(vStyle>1.5&&vStyle<2.5){fh=2.6;ww=1.3;}",
      "  if(vStyle>2.5&&vStyle<3.5){fh=3.0;ww=1.6;}",
      "  vec2 cf=vec2((u+hw)/ww,v/fh); vec2 cell=floor(cf); vec2 f=fract(cf);",
      "  vec2 fw=fwidth(cf);",
      "  float mx=smoothstep(.2-fw.x,.2+fw.x,f.x)*(1.-smoothstep(.8-fw.x,.8+fw.x,f.x));",
      "  float my=smoothstep(.3-fw.y,.3+fw.y,f.y)*(1.-smoothstep(.82-fw.y,.82+fw.y,f.y));",
      "  float win=mx*my;",
      "  float lod=clamp(max(fw.x,fw.y)*1.2-.15,0.,1.);",
      "  float rr=hash13(vec3(cell,vSeed*13.7+faceId*31.));",
      "  float lit=step(rr,vLit);",
      "  float fk=step(.992,hash13(vec3(cell.yx,vSeed+faceId)));",
      "  lit=mix(lit,step(.5,hash13(vec3(cell,floor(uTime*1.3+vSeed)))),fk);",
      "  float pc=hash13(vec3(cell*.37,vSeed));",
      "  vec3 wc=pc<.55?vec3(1.,.6,.3):(pc<.86?vec3(1.,.88,.72):vec3(.55,.78,1.));",
      "  float inten=(.25+1.1*pow(hash13(vec3(cell,9.1+vSeed)),2.))*(.6+.6*(1.-f.y));",
      "  if(vStyle>2.5&&vStyle<3.5){wc=mix(vec3(.75,.9,1.),vec3(1.,.8,.55),step(.6,pc)); inten*=1.3;}",
      "  vec3 R=reflect(-V,n);",
      "  vec3 glass=skyCol(normalize(vec3(R.x,abs(R.y)*.8+.05,R.z)))*.3+vec3(.004,.005,.009);",
      "  vec3 wall=vec3(.020,.022,.029)*(.7+.6*hash11(vSeed*5.7));",
      "  wall+=vec3(.012,.006,.007)*(1.-clamp(v/90.,0.,1.));",
      "  wall+=vec3(.05,.07,.10)*uDawn*.6+vec3(1.,.55,.3)*max(dot(n,uSunDir),0.)*uDawn*.25;",
      "  vec3 winCol=mix(glass,wc*inten,lit);",
      "  vec3 fac=mix(wall,winCol,win);",
      "  vec3 avg=mix(wall,mix(glass,wc*.5,vLit),.25);",
      "  fac=mix(fac,avg,lod);",
      "  float shop=(1.-smoothstep(3.6,4.3,v-vBase))*step(.5,v-vBase)*step(vBase,.1);",
      "  vec3 shopC=mix(vec3(1.,.5,.22),vec3(.3,.8,1.),step(.62,hash11(vSeed*2.)))*.9*(.5+.5*hash13(vec3(floor((u+hw)/4.),vSeed,1.)));",
      "  fac=mix(fac,shopC,shop*.55*step(.35,fract((u+hw)/6.)));",
      "  vec3 col=fac;",
      "  if(vStyle>.5&&vStyle<1.5){ float e=1.-smoothstep(.0,.35,hw-abs(u)); col+=neonC(vSeed)*e*2.2; ",
      "     float top=vBase+vSize.y; col+=neonC(vSeed)*(1.-smoothstep(0.,.5,abs(v-(top-1.2))))*2.5; }",
      "  if(vStyle>2.5&&vStyle<3.5){ float e=1.-smoothstep(.0,.6,hw-abs(u)); col+=vec3(.2,.9,1.)*e*4.;",
      "     float s2=1.-smoothstep(0.,.6,abs(mod(u+hw,12.)-6.)); col+=vec3(.2,.9,1.)*s2*1.2*step(20.,v); }",
      "  if(vStyle>3.5&&vStyle<4.5){ col=vec3(.03,.03,.035); }",
      "  if(vStyle>4.5){ float band=step(.25,(v-vBase)/vSize.y)*step((v-vBase)/vSize.y,.8); col=mix(vec3(.025,.03,.04),vec3(1.,.8,.55)*2.2,band*side); col+=vec3(.1,.85,1.)*side*(1.-smoothstep(0.,.25,abs(v-vBase-.15)))*4.; }",
      "  if(side<.5){ vec2 rc=floor(vW.xz/3.); float rl=step(.97,hash12(rc+vSeed)); col=vec3(.012,.013,.017)+vec3(1.,.4,.2)*rl*1.5;",
      "     if(vStyle>.5&&vStyle<1.5){ float ed=min(vSize.x*.5-abs(vL.x),vSize.z*.5-abs(vL.z)); col+=neonC(vSeed)*(1.-smoothstep(0.,.4,ed))*3.; }",
      "     if(vStyle>2.5&&vStyle<3.5){ float ed=min(vSize.x*.5-abs(vL.x),vSize.z*.5-abs(vL.z)); col+=vec3(.2,.9,1.)*(1.-smoothstep(0.,.8,ed))*5.; } }",
      "  col=applyFog(col,vW);",
      "  gl_FragColor=vec4(col,1.); }"
    ].join("\n")
  });
  var bMesh = new THREE.InstancedMesh(bGeo, bMat, NB);
  var mtx = new THREE.Matrix4(), q0 = new THREE.Quaternion(), v3 = new THREE.Vector3(), sc3 = new THREE.Vector3();
  var tallTops = [];
  for (var k = 0; k < NB; k++) {
    var Q = blds[k];
    v3.set((Q.x0 + Q.x1) / 2, Q.y0, (Q.z0 + Q.z1) / 2);
    sc3.set(Q.x1 - Q.x0, Q.y1 - Q.y0, Q.z1 - Q.z0);
    mtx.compose(v3, q0, sc3);
    bMesh.setMatrixAt(k, mtx);
    aSeed[k] = Q.seed; aStyle[k] = Q.style; aLit[k] = Math.min(Q.lit, 0.95);
    if (Q.y1 > 95 && Q.style !== 5) tallTops.push(Q);
  }
  bMesh.instanceMatrix.needsUpdate = true;
  bMesh.frustumCulled = false;
  scene.add(bMesh);

  // ---------- 地面(濡れた道路と運河・映り込み)
  var reflRT = new THREE.WebGLRenderTarget(W / 2, H / 2, { type: THREE.HalfFloatType, depthBuffer: true });
  var texMat = new THREE.Matrix4();
  var groundMat = mkMat({
    uniforms: { tRefl: { value: reflRT.texture }, uTexMat: { value: texMat }, uRain: { value: 1 } },
    vs: "varying vec3 vW; void main(){ vec4 wp=modelMatrix*vec4(position,1.); vW=wp.xyz; gl_Position=projectionMatrix*viewMatrix*wp; }",
    fs: [
      "uniform sampler2D tRefl; uniform mat4 uTexMat; uniform float uRain; varying vec3 vW;",
      "void main(){",
      "  vec2 p=vW.xz; float P=46.;",
      "  float kx=floor(p.x/P+.5); float dx=abs(p.x-kx*P);",
      "  float kz=floor(p.y/P+.5); float dz=abs(p.y-kz*P);",
      "  float avh=(p.y<-430.&&p.y>-1120.)?16.:11.;",
      "  float hwx=(kx==0.)?avh:5.;",
      "  float onX=step(dx,hwx); float onZ=step(dz,5.);",
      "  float plaza=step(abs(p.x),70.)*step(p.y,-1140.)*step(-1275.,p.y);",
      "  float road=max(onX,onZ);",
      "  float water=step(abs(p.y+322.),15.)*(1.-onX);",
      "  float grid=step(abs(p.x),700.)*step(p.y,280.)*step(-2500.,p.y);",
      "  vec3 V=normalize(cameraPosition-vW);",
      "  vec3 alb=mix(vec3(.014,.014,.017),vec3(.005,.005,.006),road);",
      "  alb=mix(alb,vec3(.04,.04,.045),plaza);",
      "  float lane=0.;",
      "  if(kx==0.&&onX>.5){ float d1=abs(abs(p.x)-avh*.5); lane=(1.-smoothstep(.08,.16,d1))*step(.5,fract(p.y/9.)); lane+=(1.-smoothstep(.1,.18,abs(abs(p.x)-.35))); }",
      "  vec3 col=alb*.6+vec3(.9,.85,.7)*lane*.25*(1.-water);",
      "  vec4 rc=uTexMat*vec4(vW,1.); vec2 ruv=rc.xy/rc.w;",
      "  float rough=mix(1.,.35,water)*mix(.6,1.,road);",
      "  vec2 dn=(vec2(vnoise(p*.55),vnoise(p*.55+7.3))-.5);",
      "  vec2 rip=vec2(sin(p.x*.9+uTime*2.1)+sin(p.y*1.3-uTime*1.6),cos(p.y*.8+uTime*1.8))*.0025*water;",
      "  vec3 refl=vec3(0.);",
      "  for(int i=0;i<7;i++){ float o=(float(i)-3.)/3.; refl+=texture2D(tRefl,ruv+dn*.008*rough+rip+vec2(o*.0015,o*.009*rough)).rgb; }",
      "  refl/=7.; refl=min(refl,vec3(1.5));",
      "  float fres=.06+.94*pow(1.-max(V.y,0.),5.);",
      "  float rs=water>.5?mix(.55,1.,fres):(road>.5?mix(.22,.9,fres):mix(.08,.4,fres));",
      "  rs*=mix(.6,1.,uRain);",
      "  col+=refl*rs;",
      "  vec2 q=p; float side=sign(p.x-kx*P+1e-4); float lxp=kx*P+side*(hwx+1.); float lz=floor(p.y/23.+.5)*23.;",
      "  float d2=(p.x-lxp)*(p.x-lxp)+(p.y-lz)*(p.y-lz);",
      "  float side2=sign(p.y-kz*P+1e-4); float lzp=kz*P+side2*6.; float lx2=floor(p.x/23.+.5)*23.;",
      "  float d3=(p.y-lzp)*(p.y-lzp)+(p.x-lx2)*(p.x-lx2);",
      "  float pool=(exp(-d2/28.)*.5+exp(-d2/220.)*.14)*step(dx,hwx+4.)+(exp(-d3/28.)*.5+exp(-d3/220.)*.14)*step(dz,9.);",
      "  col+=vec3(1.,.48,.16)*pool*grid*(1.-water)*.32;",
      "  vec2 fc=p/14.; vec2 fi=floor(fc); float fh=hash12(fi); float dt=1.-smoothstep(.12,.32,length(fract(fc)-.5));",
      "  vec3 lc=fh<.7?vec3(1.,.55,.24):vec3(.9,.85,.8); float on=step(.45,fh)*(.6+1.4*hash12(fi+3.));",
      "  float st=1.-smoothstep(.0,.08,min(abs(fract(p.x/46.)-.5),abs(fract(p.y/46.)-.5))*2.);",
      "  vec3 far=lc*on*dt*1.6+vec3(1.,.5,.2)*st*.35; vec3 farAvg=vec3(1.,.6,.3)*.22;",
      "  far=mix(far,farAvg,clamp(max(fwidth(fc.x),fwidth(fc.y))*1.5,0.,1.));",
      "  col=mix(vec3(.004,.004,.006)+far,col,grid);",
      "  col=applyFog(col,vW);",
      "  gl_FragColor=vec4(col,1.); }"
    ].join("\n")
  });
  var ground = new THREE.Mesh(new THREE.PlaneGeometry(60000, 60000), groundMat);
  ground.rotation.x = -Math.PI / 2;
  ground.position.set(0, 0, -1500);
  ground.layers.set(1);
  ground.frustumCulled = false;
  scene.add(ground);

  // ---------- 光の点(街灯・航空障害灯・遠くの街の灯り)
  function mkPoints(pos, col, size, blink, layer) {
    var g = new THREE.BufferGeometry();
    g.setAttribute("position", new THREE.BufferAttribute(new Float32Array(pos), 3));
    g.setAttribute("aCol", new THREE.BufferAttribute(new Float32Array(col), 3));
    g.setAttribute("aSize", new THREE.BufferAttribute(new Float32Array(size), 1));
    g.setAttribute("aBlink", new THREE.BufferAttribute(new Float32Array(blink), 1));
    var m = mkMat({
      uniforms: { uScale: { value: 1 }, uDim: { value: 1 } },
      vs: [
        "attribute vec3 aCol; attribute float aSize; attribute float aBlink; uniform float uScale; uniform float uDim;",
        "varying vec3 vC; varying float vF;",
        "void main(){ vec4 mv=modelViewMatrix*vec4(position,1.);",
        "  float b=1.; if(aBlink>0.){ b=smoothstep(.0,.08,fract(uTime*.75+aBlink))*(1.-smoothstep(.25,.4,fract(uTime*.75+aBlink))); }",
        "  vC=aCol*b*(aBlink>0.?1.:uDim)*uDimAll; vF=fogAmt(position);",
        "  gl_PointSize=clamp(aSize*uScale/max(-mv.z,1.),1.5,90.);",
        "  gl_Position=projectionMatrix*mv; }"
      ].join("\n"),
      fs: [
        "varying vec3 vC; varying float vF;",
        "void main(){ vec2 c=gl_PointCoord-.5; float r=dot(c,c)*4.; float a=exp(-r*5.)+exp(-r*1.4)*.25;",
        "  gl_FragColor=vec4(vC*a*(1.-vF*.8),1.); }"
      ].join("\n"),
      transparent: true, depthWrite: false, blending: THREE.AdditiveBlending
    });
    var pts = new THREE.Points(g, m);
    pts.frustumCulled = false;
    if (layer) pts.layers.set(layer);
    scene.add(pts);
    return m;
  }
  var pointMats = [];
  (function () {
    var pos = [], col = [], size = [], blink = [];
    for (var kx = -15; kx <= 15; kx++) {
      var hw = kx === 0 ? null : 5;
      for (var z = -2480; z < 270; z += 23) {
        if (Math.abs(kx) <= 1 && z < -1135 && z > -1280) continue;
        var hwx = kx === 0 ? avHalf(z) : 5;
        for (var sd = -1; sd <= 1; sd += 2) {
          pos.push(kx * P + sd * (hwx + 1), 7, z); col.push(1.0, 0.5, 0.2); size.push(200); blink.push(0);
        }
      }
    }
    for (var kz = -54; kz <= 6; kz++) {
      if (kz === -7) continue;
      for (var x = -690; x < 690; x += 23) {
        if (Math.abs(x) < 72 && kz * P < -1135 && kz * P > -1280) continue;
        for (var sd2 = -1; sd2 <= 1; sd2 += 2) { pos.push(x, 7, kz * P + sd2 * 6); col.push(1.0, 0.5, 0.2); size.push(200); blink.push(0); }
      }
    }
    // 運河の橋の欄干の灯り
    for (var kk = -15; kk <= 15; kk++) {
      var hb = kk === 0 ? 11 : 5;
      for (var zz = CANAL_Z - 15; zz <= CANAL_Z + 15; zz += 5) {
        pos.push(kk * P - hb, 1.6, zz, kk * P + hb, 1.6, zz); col.push(0.4, 0.9, 1.4, 0.4, 0.9, 1.4); size.push(120, 120); blink.push(0, 0);
      }
    }
    // 航空障害灯
    for (var t = 0; t < tallTops.length; t++) {
      var Q = tallTops[t];
      var corners = [[Q.x0, Q.z0], [Q.x1, Q.z0], [Q.x0, Q.z1], [Q.x1, Q.z1]];
      var ph = rnd();
      for (var c = 0; c < 4; c++) { pos.push(corners[c][0], Q.y1 + 0.6, corners[c][1]); col.push(4, 0.25, 0.15); size.push(520); blink.push(ph + 0.001); }
    }
    pos.push(18, MEGA.h + 59, -1206, -18, MEGA.h + 59, -1206); col.push(6, 0.3, 0.2, 6, 0.3, 0.2); size.push(1400, 1400); blink.push(0.31, 0.31);
    pointMats.push(mkPoints(pos, col, size, blink, 0));
    // 地平線まで続く街の灯り(区画の外)
    var fp = [], fc = [], fs = [], fb = [];
    var fr = mulberry32(99);
    for (var n = 0; n < 60000; n++) {
      var X = (fr() - 0.5) * 9000, Z = 300 - fr() * 9500;
      if (Math.abs(X) < 720 && Z > -2520) continue;
      X = Math.round(X / 23) * 23 + (fr() < 0.5 ? 0 : (fr() - 0.5) * 30);
      var cw = fr();
      fp.push(X, 3 + fr() * 25, Z);
      if (cw < 0.6) fc.push(1.5, 0.75, 0.3); else if (cw < 0.9) fc.push(1.3, 1.2, 1.0); else fc.push(0.5, 0.8, 1.6);
      fs.push(220 + fr() * 260); fb.push(0);
    }
    pointMats.push(mkPoints(fp, fc, fs, fb, 0));
  })();

  // ---------- 車の光の筋(地上と空中)
  (function () {
    var A = [], Bv = [], C = [];
    var cr2 = mulberry32(7);
    function addStreet(axis, line, lanes, min, max, count, y, spdLo, spdHi, lenLo, lenHi) {
      for (var n = 0; n < count; n++) {
        var dir = cr2() < 0.5 ? 1 : -1;
        var laneIx = Math.floor(cr2() * lanes);
        var off = (1.6 + laneIx * 3.0) * (axis === 0 ? (dir > 0 ? 1 : -1) : (dir > 0 ? -1 : 1));
        var spd = (spdLo + cr2() * (spdHi - spdLo)) * dir;
        A.push(axis, line, off, y);
        Bv.push(min, max, spd, cr2() * (max - min));
        C.push(lenLo + cr2() * (lenHi - lenLo), (axis === 0 ? dir > 0 : dir < 0) ? 0 : 1);
      }
    }
    for (var kx = -15; kx <= 15; kx++) {
      if (kx === 0) {
        addStreet(0, 0, 3, -1130, 260, 260, 0.7, 14, 26, 7, 15);
        addStreet(0, 0, 3, -2480, -1290, 120, 0.7, 14, 26, 7, 15);
      } else if (Math.abs(kx) === 1) {
        addStreet(0, kx * P, 1, -1130, 260, 40, 0.7, 10, 20, 5, 10);
        addStreet(0, kx * P, 1, -2480, -1290, 30, 0.7, 10, 20, 5, 10);
      } else addStreet(0, kx * P, 1, -2480, 260, 70, 0.7, 10, 20, 5, 10);
    }
    for (var kz = -54; kz <= 6; kz++) {
      if (kz === -7) continue;
      var zl = kz * P;
      if (zl < -1135 && zl > -1280) { addStreet(1, zl, 1, -690, -75, 25, 0.7, 10, 20, 5, 10); addStreet(1, zl, 1, 75, 690, 25, 0.7, 10, 20, 5, 10); }
      else addStreet(1, zl, 1, -690, 690, 45, 0.7, 10, 20, 5, 10);
    }
    // 空を走る乗り物
    var skyLanes = [[0, -2 * P + 23, 78], [0, 2 * P - 23, 92], [0, -5 * P + 23, 120], [0, 4 * P + 23, 105], [1, -14 * P + 23, 88], [1, -22 * P + 23, 130], [1, -30 * P + 23, 100], [0, 8 * P + 23, 140]];
    for (var s = 0; s < skyLanes.length; s++) {
      var SL = skyLanes[s];
      addStreet(SL[0], SL[1], 2, SL[0] === 0 ? -2480 : -690, SL[0] === 0 ? 260 : 690, 45, SL[2], 28, 45, 6, 12);
    }
    var N = A.length / 4;
    var g = new THREE.InstancedBufferGeometry();
    var base = new THREE.BoxGeometry(1, 1, 1);
    g.index = base.index;
    g.setAttribute("position", base.getAttribute("position"));
    g.setAttribute("aA", new THREE.InstancedBufferAttribute(new Float32Array(A), 4));
    g.setAttribute("aB", new THREE.InstancedBufferAttribute(new Float32Array(Bv), 4));
    g.setAttribute("aC", new THREE.InstancedBufferAttribute(new Float32Array(C), 2));
    g.instanceCount = N;
    var m = mkMat({
      vs: [
        "attribute vec4 aA; attribute vec4 aB; attribute vec2 aC;",
        "varying float vT; varying float vKind; varying vec3 vW; varying float vSky;",
        "void main(){",
        "  float range=aB.y-aB.x; float sp=aB.z;",
        "  float s=aB.x+mod(aB.w+sp*uTime,range);",
        "  float tt=position.z+.5;",
        "  float along=s-sign(sp)*tt*aC.x;",
        "  float wdt=aA.w>5.?0.9:0.45;",
        "  float across=aA.y+aA.z+position.x*wdt;",
        "  float y=aA.w+(position.y+.5)*0.3;",
        "  vec3 w=aA.x<.5?vec3(across,y,along):vec3(along,y,across);",
        "  vW=w; vT=tt; vKind=aC.y; vSky=step(5.,aA.w);",
        "  gl_Position=projectionMatrix*viewMatrix*vec4(w,1.); }"
      ].join("\n"),
      fs: [
        "varying float vT; varying float vKind; varying vec3 vW; varying float vSky;",
        "void main(){ vec3 c=vKind<.5?vec3(1.,.88,.7)*3.2:vec3(1.,.07,.04)*3.;",
        "  if(vSky>.5) c=vKind<.5?vec3(.5,.95,1.4)*3.5:vec3(1.2,.3,1.)*3.;",
        "  c*=pow(clamp(1.-vT,0.,1.),1.7);",
        "  c*=(1.-fogAmt(vW)*.95)*uDimAll;",
        "  gl_FragColor=vec4(c,1.); }"
      ].join("\n"),
      transparent: true, depthWrite: false, blending: THREE.AdditiveBlending
    });
    var mesh = new THREE.Mesh(g, m);
    mesh.frustumCulled = false;
    scene.add(mesh);
  })();

  // ---------- ネオンの看板(大通りの両側・突き出し看板と壁の看板)
  (function () {
    var mats = [], seeds = [], sizes = [];
    var sr = mulberry32(31);
    for (var k = 0; k < blds.length; k++) {
      var Q = blds[k];
      if (Q.style >= 3 || Q.y0 > 0.1) continue;
      var cz = (Q.z0 + Q.z1) / 2;
      if (cz > -40 || cz < -1130) continue;
      var east = Math.abs(Q.x0 - avHalf(cz)) < 0.01, west = Math.abs(Q.x1 + avHalf(cz)) < 0.01;
      if (!east && !west) continue;
      var top = Q.y1;
      var nS = 1 + Math.floor(sr() * 3);
      for (var n = 0; n < nS; n++) {
        var hgt = 7 + sr() * 9, wd = 2.4 + sr() * 1.4;
        var y = 5 + sr() * Math.max(Math.min(top - hgt - 4, 46) - 5, 0);
        if (y + hgt > top - 2) continue;
        var z = Q.z0 + 3 + sr() * Math.max(Q.z1 - Q.z0 - 6, 0.1);
        var blade = sr() < 0.6;
        var m4 = new THREE.Matrix4();
        var pos = new THREE.Vector3(), rot = new THREE.Quaternion(), scl = new THREE.Vector3();
        if (blade) {
          pos.set(east ? Q.x0 - 0.3 - wd / 2 : Q.x1 + 0.3 + wd / 2, y + hgt / 2, z);
          scl.set(wd, hgt, 1);
        } else {
          pos.set(east ? Q.x0 - 0.15 : Q.x1 + 0.15, y + hgt / 2, z);
          rot.setFromAxisAngle(new THREE.Vector3(0, 1, 0), east ? -Math.PI / 2 : Math.PI / 2);
          scl.set(wd * 1.6, hgt * 0.6, 1);
        }
        m4.compose(pos, rot, scl);
        mats.push(m4); seeds.push(sr() * 100); sizes.push(scl.x, scl.y);
      }
    }
    var N = mats.length;
    var g = new THREE.PlaneGeometry(1, 1);
    g.setAttribute("aSeed", new THREE.InstancedBufferAttribute(new Float32Array(seeds), 1));
    g.setAttribute("aSize", new THREE.InstancedBufferAttribute(new Float32Array(sizes), 2));
    var m = mkMat({
      vs: [
        "attribute float aSeed; attribute vec2 aSize; varying vec2 vUv; varying float vSeed; varying vec2 vSz; varying vec3 vW;",
        "void main(){ vUv=uv; vSeed=aSeed; vSz=aSize; vec4 wp=modelMatrix*instanceMatrix*vec4(position,1.); vW=wp.xyz; gl_Position=projectionMatrix*viewMatrix*wp; }"
      ].join("\n"),
      fs: [
        "varying vec2 vUv; varying float vSeed; varying vec2 vSz; varying vec3 vW;",
        "void main(){ float k=hash11(vSeed*3.1);",
        "  vec3 nc=k<.3?vec3(1.,.1,.5):(k<.55?vec3(.1,.9,1.):(k<.75?vec3(.7,.3,1.):(k<.9?vec3(1.,.6,.1):vec3(.3,1.,.5))));",
        "  vec2 px=vUv*vSz; float bd=min(min(px.x,vSz.x-px.x),min(px.y,vSz.y-px.y));",
        "  float border=1.-smoothstep(.12,.22,abs(bd-.25));",
        "  bool vert=vSz.y>vSz.x; float cols=vert?1.:floor(vSz.x/1.6); float rows=vert?floor(vSz.y/vSz.x*1.1):1.;",
        "  vec2 g=vec2((px.x-.45)/(vSz.x-.9)*cols,(px.y-.45)/(vSz.y-.9)*rows); vec2 gi=floor(g); vec2 gf=fract(g);",
        "  vec2 cp=(gf-.12)/.76; float inside=step(0.,cp.x)*step(cp.x,1.)*step(0.,cp.y)*step(cp.y,1.)*step(0.,g.x)*step(g.x,cols)*step(0.,g.y)*step(g.y,rows);",
        "  vec2 pc=floor(cp*5.); vec2 pcm=vec2(min(pc.x,4.-pc.x),pc.y);",
        "  float on=step(.5,hash13(vec3(gi*7.+pcm,vSeed)));",
        "  float glyph=on*inside;",
        "  float fl=1.; if(hash11(vSeed*9.)<.15){ fl=step(.12,hash12(vec2(floor(uTime*14.),vSeed))); }",
        "  vec3 bg=nc*.06;",
        "  vec3 c=bg+nc*glyph*3.2*fl+nc*border*2.6;",
        "  c=applyFog(c,vW);",
        "  gl_FragColor=vec4(c,1.); }"
      ].join("\n"),
      side: THREE.DoubleSide
    });
    var mesh = new THREE.InstancedMesh(g, m, N);
    for (var i2 = 0; i2 < N; i2++) mesh.setMatrixAt(i2, mats[i2]);
    mesh.instanceMatrix.needsUpdate = true;
    mesh.frustumCulled = false;
    scene.add(mesh);
  })();

  // ---------- 雲の層(冒頭に突き抜ける)
  var cloudMats = [];
  (function () {
    var NL = 12;
    for (var i = 0; i < NL; i++) {
      var m = mkMat({
        uniforms: { uLayer: { value: i } },
        vs: "varying vec3 vW; void main(){ vec4 wp=modelMatrix*vec4(position,1.); vW=wp.xyz; gl_Position=projectionMatrix*viewMatrix*wp; }",
        fs: [
          "uniform float uLayer; varying vec3 vW;",
          "void main(){ vec2 p=vW.xz*.016+vec2(uLayer*3.7,uLayer*1.3);",
          "  float n=fbm(p+vec2(uTime*.012,0.)); float n2=fbm(p*3.1+5.+uTime*.02);",
          "  float d=n*.72+n2*.28;",
          "  float prof=sin(3.14159*(uLayer+.5)/12.);",
          "  float a=smoothstep(.44,.6,d+.07*prof);",
          "  float kk=uLayer/11.;",
          "  vec3 col=mix(vec3(.10,.05,.04),vec3(.21,.24,.34),kk*kk);",
          "  col*=.35+1.1*smoothstep(.45,.85,d);",
          "  col+=vec3(.16,.07,.04)*(1.-kk)*(1.-smoothstep(.4,.7,d));",
          "  float dist=length(vW-cameraPosition);",
          "  a*=smoothstep(4.,45.,dist);",
          "  a*=1.-smoothstep(1800.,3300.,length(vW.xz-cameraPosition.xz)); a*=1.-smoothstep(4.,6.,uTime);",
          "  col=mix(col,fogCol(vW),fogAmt(vW)*.6);",
          "  gl_FragColor=vec4(col,a*.85); }"
        ].join("\n"),
        transparent: true, depthWrite: false, side: THREE.DoubleSide
      });
      var pl = new THREE.Mesh(new THREE.PlaneGeometry(7000, 7000), m);
      pl.rotation.x = -Math.PI / 2;
      pl.position.set(0, 296 + i * 8.5, 250);
      pl.frustumCulled = false;
      scene.add(pl);
      cloudMats.push(m);
    }
  })();

  // ---------- 雨(低い所だけ)
  var rainMat;
  (function () {
    var N = 7000, pos = new Float32Array(N * 2 * 3), endA = new Float32Array(N * 2);
    var rr = mulberry32(5);
    for (var i = 0; i < N; i++) {
      var x = rr() * 140, y = rr() * 90, z = rr() * 140;
      pos.set([x, y, z, x, y, z], i * 6); endA[i * 2] = 0; endA[i * 2 + 1] = 1;
    }
    var g = new THREE.BufferGeometry();
    g.setAttribute("position", new THREE.BufferAttribute(pos, 3));
    g.setAttribute("aEnd", new THREE.BufferAttribute(endA, 1));
    rainMat = mkMat({
      uniforms: { uRain: { value: 1 }, uCam: { value: new THREE.Vector3() } },
      vs: [
        "attribute float aEnd; uniform vec3 uCam; uniform float uRain; varying float vA;",
        "void main(){ vec3 box=vec3(140.,90.,140.); vec3 vel=vec3(-6.,-70.,4.);",
        "  vec3 p=position+vel*uTime; p=mod(p-uCam+box*.5,box)-box*.5+uCam;",
        "  p+=vel*0.022*aEnd;",
        "  float d=length(p-uCam); vA=uRain*(1.-smoothstep(25.,70.,d))*smoothstep(1.,4.,d);",
        "  gl_Position=projectionMatrix*viewMatrix*vec4(p,1.); }"
      ].join("\n"),
      fs: "varying float vA; void main(){ gl_FragColor=vec4(vec3(.5,.56,.72)*vA*.16,1.); }",
      transparent: true, depthWrite: false, blending: THREE.AdditiveBlending
    });
    var ls = new THREE.LineSegments(g, rainMat);
    ls.frustumCulled = false;
    ls.layers.set(1);
    scene.add(ls);
  })();

  // ---------- 後処理(ブルーム・色・ビネット・粒)
  var sceneRT = new THREE.WebGLRenderTarget(W, H, { type: THREE.HalfFloatType, samples: 4, depthBuffer: true });
  function mkRT(w, h) { return new THREE.WebGLRenderTarget(w, h, { type: THREE.HalfFloatType, depthBuffer: false }); }
  var lv = [mkRT(540, 960), mkRT(270, 480), mkRT(135, 240), mkRT(68, 120), mkRT(34, 60)];
  var up = [mkRT(270, 480), mkRT(135, 240), mkRT(68, 120)];
  var streakA = mkRT(135, 480), streakB = mkRT(135, 480);
  var fsCam = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
  var fsScene = new THREE.Scene();
  var fsQuad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2));
  fsQuad.frustumCulled = false;
  fsScene.add(fsQuad);
  var VS_FS = "varying vec2 vUv; void main(){ vUv=uv; gl_Position=vec4(position.xy,0.,1.); }";
  function fsMat(fs, uniforms) {
    return new THREE.ShaderMaterial({ uniforms: uniforms, vertexShader: VS_FS, fragmentShader: fs, depthTest: false, depthWrite: false });
  }
  var brightMat = fsMat([
    "uniform sampler2D tSrc; uniform vec2 uTexel; varying vec2 vUv;",
    "vec3 s(vec2 o){ vec3 c=texture2D(tSrc,vUv+o*uTexel).rgb; c=min(c,vec3(60.)); return c; }",
    "void main(){ vec3 c=(s(vec2(-1,-1))+s(vec2(1,-1))+s(vec2(-1,1))+s(vec2(1,1)))*.25;",
    "  float l=max(c.r,max(c.g,c.b)); float k=max(l-1.3,0.); k=k*k/(k+0.6+1e-4);",
    "  vec3 o=c*(k/max(l,1e-4)); if(any(isnan(o))) o=vec3(0.); gl_FragColor=vec4(o,1.); }"
  ].join("\n"), { tSrc: { value: null }, uTexel: { value: new THREE.Vector2() } });
  var downMat = fsMat([
    "uniform sampler2D tSrc; uniform vec2 uTexel; varying vec2 vUv;",
    "void main(){ vec2 h=uTexel*.5; vec3 c=texture2D(tSrc,vUv).rgb*4.;",
    "  c+=texture2D(tSrc,vUv+vec2(-h.x,-h.y)).rgb+texture2D(tSrc,vUv+vec2(h.x,-h.y)).rgb+texture2D(tSrc,vUv+vec2(-h.x,h.y)).rgb+texture2D(tSrc,vUv+vec2(h.x,h.y)).rgb;",
    "  gl_FragColor=vec4(c/8.,1.); }"
  ].join("\n"), { tSrc: { value: null }, uTexel: { value: new THREE.Vector2() } });
  var upMat = fsMat([
    "uniform sampler2D tSrc; uniform sampler2D tBase; uniform vec2 uTexel; varying vec2 vUv;",
    "void main(){ vec2 h=uTexel*.5; vec3 c=vec3(0.);",
    "  c+=texture2D(tSrc,vUv+vec2(-h.x*2.,0.)).rgb; c+=texture2D(tSrc,vUv+vec2(-h.x,h.y)).rgb*2.;",
    "  c+=texture2D(tSrc,vUv+vec2(0.,h.y*2.)).rgb; c+=texture2D(tSrc,vUv+vec2(h.x,h.y)).rgb*2.;",
    "  c+=texture2D(tSrc,vUv+vec2(h.x*2.,0.)).rgb; c+=texture2D(tSrc,vUv+vec2(h.x,-h.y)).rgb*2.;",
    "  c+=texture2D(tSrc,vUv+vec2(0.,-h.y*2.)).rgb; c+=texture2D(tSrc,vUv+vec2(-h.x,-h.y)).rgb*2.;",
    "  gl_FragColor=vec4(c/12.+texture2D(tBase,vUv).rgb,1.); }"
  ].join("\n"), { tSrc: { value: null }, tBase: { value: null }, uTexel: { value: new THREE.Vector2() } });
  var streakMat = fsMat([
    "uniform sampler2D tSrc; uniform vec2 uTexel; uniform float uStep; varying vec2 vUv;",
    "void main(){ vec3 c=vec3(0.); float wsum=0.;",
    "  for(int i=-7;i<=7;i++){ float fi=float(i); float w=exp(-fi*fi/18.); c+=texture2D(tSrc,vUv+vec2(fi*uStep*uTexel.x,0.)).rgb*w; wsum+=w; }",
    "  gl_FragColor=vec4(c/wsum,1.); }"
  ].join("\n"), { tSrc: { value: null }, uTexel: { value: new THREE.Vector2() }, uStep: { value: 1 } });
  var finalMat = fsMat([
    "uniform sampler2D tScene; uniform sampler2D tBloom; uniform sampler2D tStreak; uniform float uFrame; uniform float uExposure; uniform float uBloom; uniform float uStreak;",
    "uniform float uCloud; uniform float uCloudZoom; uniform float uHole; uniform float uTime2; uniform float uFlash;",
    "varying vec2 vUv;",
    "float h12(vec2 p){vec3 p3=fract(vec3(p.xyx)*.1031);p3+=dot(p3,p3.yzx+33.33);return fract((p3.x+p3.y)*p3.z);}",
    "float vn(vec2 p){vec2 i=floor(p),f=fract(p);f=f*f*(3.-2.*f);return mix(mix(h12(i),h12(i+vec2(1,0)),f.x),mix(h12(i+vec2(0,1)),h12(i+vec2(1,1)),f.x),f.y);}",
    "float fb(vec2 p){float v=0.,a=.5;for(int i=0;i<5;i++){v+=a*vn(p);p=p*2.07+vec2(1.7,9.2);a*=.5;}return v;}",
    "vec3 aces(vec3 x){return clamp((x*(2.51*x+.03))/(x*(2.43*x+.59)+.14),0.,1.);}",
    "uint ihash(uint x){x^=x>>16;x*=0x7feb352du;x^=x>>15;x*=0x846ca68bu;x^=x>>16;return x;}",
    "void main(){",
    "  vec2 uv=vUv; vec2 d=uv-.5;",
    "  float ca=.0016;",
    "  vec3 col; col.r=texture2D(tScene,.5+d*(1.-ca)).r; col.g=texture2D(tScene,uv).g; col.b=texture2D(tScene,.5+d*(1.+ca)).b;",
    "  if(any(isnan(col))||any(isinf(col))) col=vec3(0.);",
    "  col+=texture2D(tBloom,uv).rgb*uBloom;",
    "  col+=texture2D(tStreak,uv).rgb*vec3(.55,.75,1.25)*uStreak;",
    "  if(uCloud>.001){",
    "    vec2 q=d; q.x*=.5625; float r=length(q);",
    "    vec2 pz=q*3.2/(1.+uCloudZoom);",
    "    float n=fb(pz*2.+vec2(3.1,7.7))*.7+fb(pz*5.3+11.)*.3;",
    "    float dens=smoothstep(.32,.58,n+uCloud*.5-.2);",
    "    dens*=uCloud;",
    "    dens*=smoothstep(uHole-.05,uHole+.25,r+n*.25);",
    "    vec3 cc=mix(vec3(.05,.035,.04),vec3(.22,.24,.33),smoothstep(.35,.75,n));",
    "    col=mix(col,cc,clamp(dens,0.,1.));",
    "  }",
    "  col*=uExposure;",
    "  col+=vec3(1.,.8,.6)*uFlash;",
    "  col=aces(col);",
    "  float l=dot(col,vec3(.2126,.7152,.0722));",
    "  col=mix(vec3(l),col,1.12);",
    "  col+=vec3(-.012,.004,.022)*(1.-smoothstep(0.,.5,l));",
    "  col*=mix(vec3(1.),vec3(1.05,1.,.93),smoothstep(.45,1.,l));",
    "  col=clamp(col,0.,1.);",
    "  col=mix(col,col*col*(3.-2.*col),.35);",
    "  vec2 vq=d*vec2(1.,.85); float vig=1.-.6*smoothstep(.12,.62,dot(vq,vq)*2.2);",
    "  col*=vig;",
    "  col=pow(col,vec3(1./2.2));",
    "  uvec2 ip=uvec2(gl_FragCoord.xy); uint hh=ihash(ip.x*1973u+ip.y*9277u+uint(uFrame)*26699u);",
    "  float g=float(hh&0xffffu)/65535.-.5; float g2=float((hh>>16)&0xffffu)/65535.-.5;",
    "  col+=(g+g2)*.5*.06*(1.-abs(l*2.-1.)*.55);",
    "  gl_FragColor=vec4(col,1.); }"
  ].join("\n"), {
    tScene: { value: sceneRT.texture }, tBloom: { value: up[0].texture }, tStreak: { value: streakB.texture },
    uFrame: { value: 0 }, uExposure: { value: 1.0 }, uBloom: { value: 0.55 }, uStreak: { value: 0.3 },
    uCloud: { value: 0 }, uCloudZoom: { value: 0 }, uHole: { value: -1 }, uTime2: { value: 0 }, uFlash: { value: 0 }
  });
  function pass(mat, target) {
    fsQuad.material = mat;
    renderer.setRenderTarget(target);
    renderer.render(fsScene, fsCam);
  }

  // ---------- 鏡のカメラ(地面の映り込み用)
  var mirrorCam = new THREE.PerspectiveCamera();
  mirrorCam.matrixAutoUpdate = false;
  mirrorCam.matrixWorldAutoUpdate = false;
  mirrorCam.layers.set(0);
  var SY = new THREE.Matrix4().makeScale(1, -1, 1);
  var BIAS = new THREE.Matrix4().set(0.5, 0, 0, 0.5, 0, 0.5, 0, 0.5, 0, 0, 0.5, 0.5, 0, 0, 0, 1);

  // ---------- 1 コマを描く
  var tmpUp = new THREE.Vector3(), fwd = new THREE.Vector3(), right = new THREE.Vector3();
  function shake(t, f) { return Math.sin(t * f * 1.0) * 0.5 + Math.sin(t * f * 2.31 + 1.7) * 0.3 + Math.sin(t * f * 5.13 + 4.1) * 0.2; }
  function drawScene(t) {
    t = Math.min(Math.max(t, 0), DUR);
    var p = camPos(t), la = camLook(t);
    var pa = camPos(Math.max(t - 1 / 30, 0)), pb = camPos(Math.min(t + 1 / 30, DUR));
    var speed = Math.hypot(pb[0] - pa[0], pb[1] - pa[1], pb[2] - pa[2]) * 15;
    var amp = 0.06 + 0.0018 * speed;
    p[0] += shake(t, 1.7) * amp; p[1] += shake(t + 3.3, 1.3) * amp * 0.8; p[2] += shake(t + 7.1, 1.1) * amp * 0.5;
    camera.position.set(p[0], p[1], p[2]);
    camera.fov = crEval(FK, t, 1)[0];
    camera.updateProjectionMatrix();
    camera.up.set(0, 1, 0);
    camera.lookAt(la[0], la[1], la[2]);
    // 横の加速でバンク(傾き)
    var h = 0.12;
    var a0 = camPos(Math.max(t - h, 0)), a1 = camPos(t), a2 = camPos(Math.min(t + h, DUR));
    camera.updateMatrixWorld();
    fwd.set(0, 0, -1).applyQuaternion(camera.quaternion);
    right.set(1, 0, 0).applyQuaternion(camera.quaternion);
    var ax = (a0[0] - 2 * a1[0] + a2[0]) / (h * h), az = (a0[2] - 2 * a1[2] + a2[2]) / (h * h);
    var accR = ax * right.x + az * right.z;
    var roll = Math.max(Math.min(-accR * 0.005, 0.32), -0.32) + shake(t + 11, 0.9) * 0.006;
    camera.rotateZ(roll);
    camera.rotateX(shake(t + 5, 1.5) * 0.0035);
    camera.updateMatrixWorld();

    var dawn = 0.85 * Math.pow(sstep(18.0, 28.5, t), 1.15);
    U.uTime.value = t;
    U.uDawn.value = dawn; U.uDimAll.value = lerp(0.35, 1, sstep(300, 255, p[1]));
    U.uSunDir.value.set(-0.13, -0.06 + 0.1 * dawn, -1).normalize();
    var rain = (1 - sstep(17, 21.5, t)) * sstep(1.2, 2.6, t);
    groundMat.uniforms.uRain.value = Math.max(rain, 0.35);
    rainMat.uniforms.uRain.value = rain;
    rainMat.uniforms.uCam.value.copy(camera.position);
    for (var i = 0; i < pointMats.length; i++) pointMats[i].uniforms.uDim.value = (1 - 0.35 * dawn) * lerp(0.12, 1, sstep(300, 255, p[1])); for (var i = 0; i < pointMats.length; i++) pointMats[i].uniforms.uScale.value = (H * 0.5) / Math.tan(THREE.MathUtils.degToRad(camera.fov) / 2) / 260 * 1.0;
    sky.position.copy(camera.position);

    // 映り込み
    var M = new THREE.Matrix4().copy(camera.matrixWorld);
    var Mm = new THREE.Matrix4().multiplyMatrices(SY, M).multiply(SY);
    mirrorCam.matrixWorld.copy(Mm);
    mirrorCam.matrixWorldInverse.copy(Mm).invert();
    mirrorCam.projectionMatrix.copy(camera.projectionMatrix);
    mirrorCam.projectionMatrixInverse.copy(camera.projectionMatrixInverse);
    texMat.copy(BIAS).multiply(mirrorCam.projectionMatrix).multiply(mirrorCam.matrixWorldInverse);
    U.uEye.value.set(camera.position.x, -camera.position.y, camera.position.z);
    renderer.setRenderTarget(reflRT);
    renderer.render(scene, mirrorCam);
    U.uEye.value.copy(camera.position);
    renderer.setRenderTarget(sceneRT);
    renderer.render(scene, camera);
    return { p: p, dawn: dawn };
  }
  // モーションブラー: 1 コマの間(シャッター 180 度 = 1/60 秒)に 3 回描いて平均する
  var accRT = new THREE.WebGLRenderTarget(W, H, { type: THREE.HalfFloatType, depthBuffer: false });
  var accMat = fsMat("uniform sampler2D tSrc; uniform float uW; varying vec2 vUv; void main(){ vec3 c=texture2D(tSrc,vUv).rgb; c=min(c,vec3(80.)); if(any(isnan(c))) c=vec3(0.); gl_FragColor=vec4(c*uW,1.); }",
    { tSrc: { value: sceneRT.texture }, uW: { value: 1 / 3 } });
  accMat.blending = THREE.AdditiveBlending; accMat.transparent = true;
  var MB_N = 3, SHUTTER = 1 / 60;
  function renderCity(t) {
    t = Math.min(Math.max(t, 0), DUR);
    renderer.setRenderTarget(accRT);
    renderer.setClearColor(0x000000, 1);
    renderer.clear();
    var info = null;
    for (var k = 0; k < MB_N; k++) {
      var ts = Math.min(Math.max(t + (k / (MB_N - 1) - 0.5) * SHUTTER, 0), DUR);
      var r = drawScene(ts);
      if (k === (MB_N - 1) / 2) info = r;
      accMat.uniforms.uW.value = 1 / MB_N;
      pass(accMat, accRT);
    }
    U.uTime.value = t;
    var p = info.p, dawn = info.dawn;

    // ブルーム
    brightMat.uniforms.tSrc.value = accRT.texture; brightMat.uniforms.uTexel.value.set(1 / W, 1 / H);
    pass(brightMat, lv[0]);
    for (var l = 1; l < lv.length; l++) {
      downMat.uniforms.tSrc.value = lv[l - 1].texture;
      downMat.uniforms.uTexel.value.set(1 / lv[l - 1].width, 1 / lv[l - 1].height);
      pass(downMat, lv[l]);
    }
    var src = lv[4];
    for (var u = 2; u >= 0; u--) {
      upMat.uniforms.tSrc.value = src.texture; upMat.uniforms.tBase.value = lv[u + 1].texture;
      upMat.uniforms.uTexel.value.set(1 / src.width, 1 / src.height);
      pass(upMat, up[u]); src = up[u];
    }
    // 横に伸びる光(アナモルフィック風)
    streakMat.uniforms.tSrc.value = lv[1].texture; streakMat.uniforms.uTexel.value.set(1 / 135, 1 / 480); streakMat.uniforms.uStep.value = 1.5;
    pass(streakMat, streakA);
    streakMat.uniforms.tSrc.value = streakA.texture; streakMat.uniforms.uStep.value = 4.0;
    pass(streakMat, streakB);

    // 雲を抜ける
    var inC = sstep(400, 382, p[1]) * sstep(276, 300, p[1]);
    finalMat.uniforms.uCloud.value = inC;
    finalMat.uniforms.uCloudZoom.value = Math.max(0, (t - 0.3)) * 2.2;
    finalMat.uniforms.uHole.value = lerp(-0.3, 0.9, sstep(0.95, 1.4, t));
    finalMat.uniforms.tScene.value = accRT.texture;
    finalMat.uniforms.uFrame.value = Math.round(t * 30);
    finalMat.uniforms.uExposure.value = lerp(0.95, 0.85, dawn);
    finalMat.uniforms.uFlash.value = 0.0;
    pass(finalMat, null);
  }
  window.renderCity = renderCity;
  window.__cityInfo = { buildings: NB };
  renderCity(0);
})();
2本目 sound/mix.py(61行・クリックで開く)
"""存在しない街: 曲と効果音を 30 秒の soundtrack.wav に混ぜる。
使い方: python sound/mix.py   (project フォルダで。ffmpeg が要る)
曲: Sascha Ende "Happy Beats / Business Moves Vol. 12" (ende.app, CC BY 4.0)
効果音: earshot で作成(sound/sfx_spec.json → sound/sfx/)
"""
import os
import subprocess
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
PROJ = os.path.dirname(HERE)
SFX = os.path.join(HERE, "sfx")
MUSIC = os.path.join(PROJ, "assets", "music.mp3")
OUT = os.path.join(PROJ, "assets", "soundtrack.wav")

# (ファイル, 開始秒, 音量dB, 追加のフィルタ)  ※開始 = 山の時刻 - peak_s
CUES = [
    ("wind.wav", 0.0, 4.0, "afade=t=in:st=0:d=0.3,afade=t=out:st=4.2:d=2.6"),
    ("punch.wav", 1.20, 8.0, ""),
    ("city.wav", 1.8, 2.0, "afade=t=in:st=0:d=1.5,afade=t=out:st=16.5:d=3.4"),
    ("pass.wav", 8.39, -3.0, ""),
    ("pass.wav", 12.79, -4.0, ""),
    ("pass.wav", 17.19, 0.0, ""),
    ("riser.wav", 20.08, -2.0, ""),
    ("hit.wav", 22.27, 4.0, ""),
]


def main():
    args = ["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-i", MUSIC]
    for f, _, _, _ in CUES:
        args += ["-i", os.path.join(SFX, f)]
    parts = []
    # 曲: 0〜30 秒。山(22.93 秒)の直前 0.35 秒だけ音を下げて、山で戻す。最後はフェードアウト。
    parts.append(
        "[0:a]atrim=0:30,asetpts=PTS-STARTPTS,aresample=48000,"
        "volume='if(between(t,22.55,22.93),0.18,1)':eval=frame,"
        "afade=t=in:st=0:d=0.4,afade=t=out:st=28.3:d=1.7,volume=-3dB[m]"
    )
    labels = ["[m]"]
    for i, (f, st, db, extra) in enumerate(CUES, start=1):
        chain = f"[{i}:a]aresample=48000,aformat=channel_layouts=stereo"
        if extra:
            chain += "," + extra
        chain += f",volume={db}dB,adelay={int(st * 1000)}|{int(st * 1000)}[s{i}]"
        parts.append(chain)
        labels.append(f"[s{i}]")
    parts.append(
        "".join(labels)
        + f"amix=inputs={len(labels)}:normalize=0:duration=first,"
        "atrim=0:30,loudnorm=I=-14:TP=-1.5:LRA=11,aresample=48000[out]"
    )
    args += ["-filter_complex", ";".join(parts), "-map", "[out]", "-ac", "2", "-ar", "48000", OUT]
    r = subprocess.run(args)
    if r.returncode != 0:
        sys.exit(r.returncode)
    print("wrote", OUT)


if __name__ == "__main__":
    main()

3本目(頼みが映像に)のコード

図形・3Dの惑星・文字の爆発・ブラウザの窓まで、全部 index.html の1枚に入っています。中の配列 B は曲の拍の時刻で、場面の切り替えや文字の登場を拍に合わせるのに使っています。tools/make_beats.py は、曲を調べた結果から拍の時刻を取り出す道具です。書き出しは npx --yes hyperframes@0.10.7 render で作りました。

3本目 index.html(655行・クリックで開く)
<!doctype html>
<html lang="ja" data-resolution="portrait">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=1080, height=1920" />
    <title>一行の頼みが映像に</title>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/three@0.149.0/build/three.min.js"></script>
    <style>
      /* 日本語は Noto Sans JP(OFL)を同梱。英数字は同じ書体のラテン部分、コードは JetBrains Mono(OFL)。 */
      @font-face { font-family: "JP"; font-weight: 900; src: url("assets/fonts/noto-sans-jp-japanese-900-normal.woff2") format("woff2"); unicode-range: U+3000-30FF, U+3400-9FFF, U+FF00-FFEF, U+2026; }
      @font-face { font-family: "JP"; font-weight: 700; src: url("assets/fonts/noto-sans-jp-japanese-700-normal.woff2") format("woff2"); unicode-range: U+3000-30FF, U+3400-9FFF, U+FF00-FFEF, U+2026; }
      @font-face { font-family: "JP"; font-weight: 900; src: url("assets/fonts/noto-sans-jp-latin-900-normal.woff2") format("woff2"); unicode-range: U+0000-024F, U+2000-2025, U+2027-206F, U+00D7; }
      @font-face { font-family: "JP"; font-weight: 700; src: url("assets/fonts/noto-sans-jp-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-024F, U+2000-2025, U+2027-206F, U+00D7; }
      @font-face { font-family: "Mono"; font-weight: 400; src: url("assets/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }
      @font-face { font-family: "Mono"; font-weight: 700; src: url("assets/fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2"); }

      :root {
        --ground: #05060a;
        --ink: #f5f2ea;
        --accent: #ff7a45;
        --code: #5be7ff;
        --violet: #8b6cff;
        --dim: #9aa4b8;
      }
      * { margin: 0; padding: 0; box-sizing: border-box; }
      html, body { width: 1080px; height: 1920px; overflow: hidden; background: var(--ground); }
      #root { position: relative; width: 1080px; height: 1920px; overflow: hidden; background: var(--ground); font-family: "JP", sans-serif; color: var(--ink); }
      #cam { position: absolute; inset: 0; transform-origin: 50% 46%; }
      .scene { position: absolute; inset: 0; overflow: hidden; }
      .center-stack { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 220px 90px 420px; }
      .w { display: block; font-weight: 900; line-height: 1.08; letter-spacing: -0.02em; white-space: nowrap; }

      /* S1 フック */
      #s1 { background: radial-gradient(ellipse at 50% 42%, #1a1020 0%, #05060a 62%); }
      #h1 { font-size: 150px; }
      #h2 { font-size: 270px; color: var(--accent); }
      #h3, #h4 { font-size: 210px; }
      #h4 { position: relative; isolation: isolate; }
      #h4bar { position: absolute; left: -10px; right: -10px; bottom: 6px; height: 26px; background: var(--accent); transform-origin: 0 50%; z-index: -1; }

      /* S2 チャット */
      #s2 { background: radial-gradient(ellipse at 50% 50%, #10131c 0%, #05060a 70%); }
      #s2grid { position: absolute; inset: -40px; background-image: linear-gradient(rgba(91,231,255,0.06) 2px, transparent 2px), linear-gradient(90deg, rgba(91,231,255,0.06) 2px, transparent 2px); background-size: 90px 90px; }
      #s2cam { position: absolute; inset: 0; transform-origin: 880px 1150px; }
      #s2stack { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 44px; padding: 200px 70px 420px; }
      #ask { font-size: 76px; font-weight: 900; text-align: center; line-height: 1.2; }
      #ask .hl { color: var(--accent); }
      #card { width: 940px; border-radius: 44px; background: #161922; border: 3px solid #2c3242; box-shadow: 0 40px 120px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03) inset; padding: 40px 44px 36px; display: flex; flex-direction: column; gap: 26px; }
      #cardhead { display: flex; align-items: center; gap: 18px; font-size: 38px; font-weight: 700; color: var(--dim); }
      #dot { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 24px var(--accent); }
      #typed { font-size: 66px; font-weight: 900; line-height: 1.3; min-height: 172px; color: var(--ink); }
      #typed .ch { opacity: 0; }
      #caret { display: inline-block; width: 8px; height: 70px; background: var(--accent); vertical-align: -10px; margin-left: 4px; }
      #cardfoot { display: flex; justify-content: flex-end; }
      #send { width: 120px; height: 120px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 0 rgba(255,122,69,0.6); }
      #send svg { width: 60px; height: 60px; }

      /* S3 コードの滝 */
      #s3 { background: #04060b; }
      #cols { position: absolute; inset: 0; display: flex; gap: 0; }
      .col { flex: 1; overflow: hidden; position: relative; border-right: 2px solid rgba(91,231,255,0.08); }
      .col pre { position: absolute; left: 18px; top: 0; font-family: "Mono", monospace; font-size: 25px; line-height: 38px; white-space: pre; color: #cfe8ff; }
      .k { color: #ff7a45; } .s { color: #9be564; } .n { color: #ffd166; } .c { color: #6b7a90; } .f { color: #5be7ff; }
      #s3band { position: absolute; left: 0; right: 0; top: 760px; height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(5,6,10,0.88); border-top: 4px solid var(--code); border-bottom: 4px solid var(--code); gap: 4px; }
      #s3l1 { font-size: 64px; font-weight: 700; color: var(--code); }
      #s3l2 { font-size: 104px; font-weight: 900; }
      #s3fade { position: absolute; inset: 0; background: linear-gradient(180deg, #04060b 0%, rgba(4,6,11,0) 14%, rgba(4,6,11,0) 86%, #04060b 100%); }

      /* S4 コード→図形(上下分割) */
      #s4 { background: #05060a; }
      #s4top { position: absolute; left: 0; top: 0; width: 1080px; height: 860px; background: #0d1018; border-bottom: 4px solid var(--accent); padding: 230px 60px 40px; display: flex; flex-direction: column; gap: 18px; }
      .tag { align-self: flex-start; font-size: 40px; font-weight: 900; padding: 6px 22px; border-radius: 12px; background: var(--code); color: #05060a; }
      .tag.or { background: var(--accent); }
      .cl { font-family: "Mono", monospace; font-size: 36px; line-height: 64px; padding: 0 18px; border-radius: 10px; white-space: nowrap; color: #cfe8ff; }
      #s4bot { position: absolute; left: 0; top: 860px; width: 1080px; height: 1060px; }
      #s4bot .tag { position: absolute; left: 60px; top: 40px; }
      #s4svg { position: absolute; left: 0; top: 0; width: 1080px; height: 1060px; }

      /* S5 宇宙(Three.js) */
      #s5 { background: #04050a; }
      #spaceWrap { position: absolute; left: 0; top: 0; width: 1080px; height: 1920px; transform-origin: 540px 960px; }
      #gl { position: absolute; left: 0; top: 0; width: 1080px; height: 1920px; }
      #s5label { position: absolute; left: 0; right: 0; top: 250px; text-align: center; font-size: 60px; font-weight: 900; }
      #s5label span { background: rgba(5,6,10,0.7); padding: 8px 26px; border-radius: 14px; border: 3px solid var(--code); }
      #ghost { position: absolute; left: 60px; top: 1330px; background: rgba(5,6,10,0.78); padding: 12px 22px; border-radius: 14px; border-left: 6px solid var(--code); font-family: "Mono", monospace; font-size: 30px; line-height: 46px; color: rgba(91,231,255,0.85); white-space: pre; text-shadow: 0 0 12px rgba(91,231,255,0.6); }
      #darken { position: absolute; inset: 0; background: #05060a; opacity: 0; }

      /* S6 文字の爆発 */
      #s6 { }
      #s6stack { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: 200px 60px 420px; }
      #s6 .line { display: block; white-space: nowrap; font-weight: 900; line-height: 1.12; text-shadow: 0 8px 40px rgba(0,0,0,0.8); }
      #s6 .line span { display: inline-block; }
      #e1 { font-size: 124px; }
      #e2 { font-size: 124px; color: var(--code); }
      #e3 { font-size: 250px; color: var(--accent); }
      #e4 { font-size: 250px; }
      #burst { position: absolute; left: 0; top: 0; width: 1080px; height: 1920px; }

      /* S7 窓の正体 */
      #win { position: absolute; left: 260px; top: 196px; width: 560px; height: 1028px; border-radius: 22px; border: 4px solid #39404f; box-shadow: 0 30px 120px rgba(0,0,0,0.8); }
      #winbar { position: absolute; left: 0; right: 0; top: 0; height: 64px; background: #1b1f29; border-radius: 18px 18px 0 0; display: flex; align-items: center; gap: 12px; padding: 0 20px; }
      #winbar i { width: 18px; height: 18px; border-radius: 50%; background: #ff5f57; display: block; }
      #winbar i:nth-child(2) { background: #febc2e; } #winbar i:nth-child(3) { background: #28c840; }
      #winbar b { font-family: "Mono", monospace; font-size: 28px; color: var(--ink); margin-left: 14px; font-weight: 700; }
      #s7label { position: absolute; left: 0; right: 0; top: 1262px; text-align: center; font-size: 84px; font-weight: 900; }
      #s7label .hl { color: var(--accent); }
      #s7code { position: absolute; left: 90px; right: 90px; top: 1400px; height: 150px; padding: 16px 26px; border-radius: 16px; background: rgba(13,16,24,0.95); border: 3px solid #2c3242; font-family: "Mono", monospace; font-size: 28px; line-height: 40px; white-space: pre; overflow: hidden; color: #cfe8ff; }

      /* S8 種明かし */
      #s8 { background: radial-gradient(ellipse at 50% 40%, #171019 0%, #05060a 65%); }
      #s8stack { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: 200px 70px 380px; }
      #r1 { font-size: 200px; }
      #r2 { font-size: 150px; color: var(--accent); }
      #r3 { font-size: 150px; }
      #r4 { font-size: 220px; position: relative; isolation: isolate; }
      #r4bar { position: absolute; left: -10px; right: -10px; bottom: 10px; height: 30px; background: var(--accent); transform-origin: 0 50%; z-index: -1; }
      #r5 { font-size: 104px; margin-top: 60px; }
      #r6 { font-size: 104px; color: #05060a; background: var(--ink); padding: 4px 30px; border-radius: 18px; margin-top: 10px; }
      #s8blog { position: absolute; left: 0; right: 0; top: 520px; display: flex; flex-direction: column; align-items: center; gap: 50px; text-align: center; white-space: nowrap; }
      #n1 { font-size: 82px; line-height: 1.25; }
      #n2 { font-size: 82px; line-height: 1.25; color: var(--accent); }
      #n3 { font-size: 82px; line-height: 1.25; color: #05060a; background: var(--ink); padding: 10px 40px; border-radius: 18px; }
      #s8cr { position: absolute; left: 0; right: 0; top: 1470px; text-align: center; }
      #credit { margin-top: 0; font-size: 30px; font-weight: 700; color: var(--dim); text-align: center; line-height: 1.5; white-space: nowrap; }
      #s8q { position: absolute; left: 0; right: 0; top: 860px; text-align: center; font-size: 96px; font-weight: 900; color: var(--dim); }
      #s8caret { position: absolute; left: 530px; top: 1000px; width: 20px; height: 120px; background: var(--accent); }

      /* 画面全体の上掛け */
      #flash { position: absolute; inset: 0; background: #ffffff; opacity: 0; pointer-events: none; }
      #glitch { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: difference; }
      #glitch div { position: absolute; left: 0; width: 1080px; opacity: 0; }
      #vig { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 55%, rgba(0,0,0,0.55) 100%); }
    </style>
  </head>
  <body>
    <div id="root" data-composition-id="main" data-start="0" data-duration="30" data-width="1080" data-height="1920">
      <div id="cam">
        <!-- S1 フック 0〜3.263 -->
        <div id="s1" class="scene clip" data-start="0" data-duration="3.263" data-track-index="1">
          <div class="center-stack">
            <span id="h1" class="w">この動画、</span>
            <span id="h2" class="w">カメラ</span>
            <span id="h3" class="w">使って</span>
            <span id="h4" class="w">ません<i id="h4bar"></i></span>
          </div>
        </div>

        <!-- S2 一行の頼み 3.263〜8.000 -->
        <div id="s2" class="scene clip" data-start="3.263" data-duration="4.737" data-track-index="1">
          <div id="s2grid"></div>
          <div id="s2cam">
            <div id="s2stack">
              <div id="ask"><span class="hl">日本語で</span>頼むと…</div>
              <div id="card">
                <div id="cardhead"><i id="dot"></i>Claude に頼む</div>
                <div id="typed"></div>
                <div id="cardfoot">
                  <div id="send"><svg viewBox="0 0 24 24" fill="none" stroke="#05060a" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg></div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- S3 コードの滝 8.000〜10.101 -->
        <div id="s3" class="scene clip" data-start="8" data-duration="2.101" data-track-index="1">
          <div id="cols"><div class="col"><pre id="p0"></pre></div><div class="col"><pre id="p1"></pre></div><div class="col"><pre id="p2"></pre></div></div>
          <div id="s3fade"></div>
          <div id="s3band"><span id="s3l1">押した瞬間、裏で</span><span id="s3l2">コードが書かれる</span></div>
        </div>

        <!-- S4 コード→図形 10.101〜12.214 -->
        <div id="s4" class="scene clip" data-start="10.101" data-duration="2.113" data-track-index="1">
          <div id="s4top">
            <div class="tag">コード</div>
            <div class="cl" id="c1"><span class="f">circle</span>(<span class="n">540</span>, <span class="n">500</span>, <span class="n">230</span>)</div>
            <div class="cl" id="c2"><span class="f">ring</span>(<span class="n">420</span>, <span class="n">110</span>, <span class="n">-12</span>)</div>
            <div class="cl" id="c3"><span class="f">stars</span>(<span class="k">seed</span> <span class="n">42</span>, <span class="n">90</span>)</div>
            <div class="cl" id="c4"><span class="f">fill</span>(<span class="s">"#ff7a45"</span>, <span class="s">"#8b6cff"</span>)</div>
          </div>
          <div id="s4bot">
            <svg id="s4svg" viewBox="0 0 1080 1060">
              <defs>
                <radialGradient id="pg" cx="38%" cy="32%" r="75%"><stop offset="0%" stop-color="#ffd2b0"/><stop offset="35%" stop-color="#ff7a45"/><stop offset="100%" stop-color="#3b1f7a"/></radialGradient>
                <filter id="glow" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="18"/></filter>
              </defs>
              <g id="stars4"></g>
              <circle id="pglow" cx="540" cy="560" r="230" fill="#ff7a45" filter="url(#glow)" opacity="0"/>
              <circle id="pfill" cx="540" cy="560" r="230" fill="url(#pg)" opacity="0"/>
              <circle id="pcirc" cx="540" cy="560" r="230" fill="none" stroke="#5be7ff" stroke-width="8"/>
              <ellipse id="pring" cx="540" cy="560" rx="420" ry="110" fill="none" stroke="#ffd166" stroke-width="10" transform="rotate(-12 540 560)"/>
            </svg>
            <div class="tag or">図形</div>
          </div>
        </div>

        <!-- S5 宇宙 12.214〜24.323(Three.js の本物の 3D) -->
        <div id="s5" class="scene clip" data-start="12.214" data-duration="12.109" data-track-index="2">
          <div id="spaceWrap"><canvas id="gl" width="1080" height="1920"></canvas><div id="darken"></div></div>
          <div id="s5label"><span>図形 → 3D の宇宙</span></div>
          <div id="ghost"></div>
        </div>

        <!-- S6 文字の爆発 16.428〜20.631 -->
        <div id="s6" class="scene clip" data-start="16.428" data-duration="4.203" data-track-index="3">
          <canvas id="burst" width="1080" height="1920"></canvas>
          <div id="s6stack">
            <span id="e1" class="line">日本語の頼みが</span>
            <span id="e2" class="line">コードになって</span>
            <span id="e3" class="line">映像に</span>
            <span id="e4" class="line">なった</span>
          </div>
        </div>

        <!-- S7 正体(ブラウザの窓) 20.631〜24.323 -->
        <div id="s7" class="scene clip" data-start="20.631" data-duration="3.692" data-track-index="3">
          <div id="win"><div id="winbar"><i></i><i></i><i></i><b>index.html</b></div></div>
          <div id="s7label">この映像の<span class="hl">正体</span>は…</div>
          <div id="s7code"></div>
        </div>

        <!-- S8 種明かし 24.323〜30 -->
        <div id="s8" class="scene clip" data-start="24.323" data-duration="5.677" data-track-index="1">
          <div id="s8caret"></div><div id="s8q">答えは…</div>
          <div id="s8stack">
            <span id="r1" class="w">全部</span>
            <span id="r2" class="w">Claude が</span>
            <span id="r3" class="w">コードで</span>
            <span id="r4" class="w">書いた<i id="r4bar"></i></span>
          </div>
          <div id="s8blog">
            <span id="n1" class="w">こんな動画を<br />作りたい方は</span>
            <span id="n2" class="w">ブログで<br />詳しく解説してます</span>
            <span id="n3" class="w">コメント欄を<br />見てください👇</span>
          </div>
          <div id="s8cr"><span id="credit">HyperFrames × Claude Code<br />Music: Sascha Ende, ende.app (CC BY 4.0)</span></div>
        </div>
      </div>

      <div id="glitch"></div>
      <div id="flash"></div>
      <div id="vig"></div>

      <!-- 音: 曲は 8.858 秒目から(映像 8.000 秒=曲のドロップ) -->
      <audio id="music" data-timeline-role="music" src="assets/music/happy-beats-business-moves-vol-11-by-ende-dot-app.mp3" data-start="0" data-duration="30" data-media-start="8.858" data-track-index="10" data-volume="0.8" data-fade-out="0.5"></audio>
      <div id="sfx"></div>
    </div>

    <script>
      (function () {
        window.__timelines = window.__timelines || {};
        // 拍(映像の秒)= assets/music/beats.film.json と同じ値(tools/make_beats.py が作る)
        const B = [0.105,0.639,1.15,1.684,2.206,2.74,3.263,3.797,4.319,4.842,5.364,5.898,6.421,6.955,7.477,8.0,8.534,9.056,9.579,10.101,10.635,11.158,11.68,12.214,12.737,13.259,13.793,14.316,14.838,15.372,15.895,16.428,16.951,17.473,17.996,18.53,19.052,19.575,20.109,20.631,21.154,21.688,22.21,22.733,23.267,23.789,24.323,24.846,25.368,25.902,26.425,26.947,27.47,28.004,28.526,29.06,29.583];
        const S16 = 0.1306; // 16 分音符

        function mulberry32(a) { return function () { a |= 0; a = (a + 0x6d2b79f5) | 0; let t = Math.imul(a ^ (a >>> 15), 1 | a); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; }
        const R = mulberry32(20261202);
        const $ = (s) => document.querySelector(s);
        const tl = gsap.timeline({ paused: true });
        const IR = { immediateRender: false };

        // ---------- 効果音(earshot で作った wav。山の位置を拍に合わせて置く) ----------
        const sfxRoot = $("#sfx");
        let sfxN = 0;
        function sfx(file, cue, peak, vol, mediaStart) {
          const el = document.createElement("audio");
          const ms = mediaStart || 0;
          let start = cue - peak + ms;
          let skip = ms;
          if (start < 0) { skip += -start; start = 0; }
          el.id = "sfx" + sfxN;
          el.src = "assets/sfx/" + file;
          el.setAttribute("data-start", start.toFixed(3));
          el.setAttribute("data-duration", "0.7");
          if (skip > 0) el.setAttribute("data-media-start", skip.toFixed(3));
          el.setAttribute("data-track-index", String(20 + (sfxN % 6)));
          el.setAttribute("data-volume", String(vol));
          sfxRoot.appendChild(el);
          sfxN++;
        }

        // ---------- 上掛け: フラッシュ・グリッチ・カメラ ----------
        function flash(t, peak, dur) { tl.fromTo("#flash", { opacity: peak }, { opacity: 0, duration: dur || 0.28, ease: "power2.out", ...IR }, t); }
        const gRoot = $("#glitch");
        const GB = [];
        const gCols = ["#5be7ff", "#ff7a45", "#ffffff", "#8b6cff"];
        for (let i = 0; i < 12; i++) { const d = document.createElement("div"); d.style.background = gCols[i % 4]; gRoot.appendChild(d); GB.push(d); }
        function glitch(t, dur) {
          const steps = Math.max(2, Math.round(dur / 0.0334));
          for (let s = 0; s < steps; s++) {
            const tt = t + s * 0.0334;
            GB.forEach((d, i) => {
              const on = R() < 0.55;
              tl.set(d, { opacity: on ? 0.9 : 0, y: Math.floor(R() * 1900), height: 8 + Math.floor(R() * 90), x: Math.floor((R() - 0.5) * 300) }, tt);
            });
          }
          GB.forEach((d) => tl.set(d, { opacity: 0 }, t + steps * 0.0334));
          tl.fromTo("#cam", { x: -26, skewX: 8 }, { x: 0, skewX: 0, duration: dur, ease: "steps(" + steps + ")", ...IR }, t);
        }
        function punch(t, from, dur) { tl.fromTo("#cam", { scale: from }, { scale: 1, duration: dur || 0.42, ease: "expo.out", ...IR }, t); }
        function shake(t, amp) { tl.fromTo("#cam", { y: amp, rotation: amp * 0.04 }, { y: 0, rotation: 0, duration: 0.4, ease: "elastic.out(1,0.35)", ...IR }, t); }
        tl.set("#cam", { x: 0, y: 0, scale: 1, rotation: 0, skewX: 0 }, 0);

        // ================= S1 フック =================
        tl.fromTo("#h1", { scale: 1.45, opacity: 1, textShadow: "-14px 0 #5be7ff, 14px 0 #ff3d6e" }, { scale: 1, textShadow: "0px 0 #5be7ff, 0px 0 #ff3d6e", duration: 0.32, ease: "expo.out" }, 0);
        tl.to("#h1", { scale: 1.06, duration: 0.12, yoyo: true, repeat: 1, ease: "power2.out" }, B[1]);
        tl.from("#h2", { scale: 3.2, opacity: 0, rotation: -8, duration: 0.3, ease: "expo.out" }, B[2]);
        tl.from("#h3", { x: 900, skewX: -30, opacity: 0, duration: 0.28, ease: "power4.out" }, B[3]);
        tl.from("#h4", { y: 260, scaleY: 1.8, opacity: 0, duration: 0.3, ease: "back.out(2.2)" }, B[4]);
        tl.from("#h4bar", { scaleX: 0, duration: 0.26, ease: "power3.inOut" }, B[4] + 0.12);
        [B[2], B[3], B[4]].forEach((t, i) => shake(t, 34 - i * 6));
        tl.to("#h2,#h3,#h4,#h1", { textShadow: "-10px 0 #5be7ff, 10px 0 #ff3d6e", duration: 0.08, yoyo: true, repeat: 3, ease: "none" }, B[5]);
        glitch(B[5] + 0.26, 0.24);
        sfx("slam.wav", B[0], 0.32, 1.3);
        sfx("slam.wav", B[2], 0.32, 1.5);
        sfx("slam.wav", B[3], 0.32, 1.3);
        sfx("slam.wav", B[4], 0.32, 1.5);
        sfx("glitch.wav", B[5] + 0.26, 0.05, 1.2);

        // ================= S2 一行の頼み =================
        const PROMPT = "30秒で、宇宙から始まる映像を作って";
        const typed = $("#typed");
        Array.from(PROMPT).forEach((c, i) => { const s = document.createElement("span"); s.className = "ch"; s.textContent = c; typed.appendChild(s); if (i === 8) { const br = document.createElement("span"); br.style.display = "block"; typed.appendChild(br); } });
        const caret = document.createElement("i"); caret.id = "caret"; typed.appendChild(caret);
        tl.from("#s2grid", { opacity: 0, scale: 1.2, duration: 0.6, ease: "power2.out" }, B[6]);
        tl.from("#card", { y: 420, opacity: 0, rotationX: 40, duration: 0.5, ease: "back.out(1.4)" }, B[6]);
        tl.from("#ask", { y: -60, opacity: 0, duration: 0.4, ease: "power3.out" }, B[7]);
        tl.from("#ask .hl", { scale: 1.6, duration: 0.3, ease: "expo.out" }, B[7] + 0.1);
        const chars = typed.querySelectorAll(".ch");
        chars.forEach((el, i) => {
          const t = B[8] + i * S16;
          tl.set(el, { opacity: 1 }, t);
          sfx("key_" + ((i % 6) + 1) + ".wav", t, 0.02, 0.9);
        });
        // カーソルの点滅(拍の裏で)
        for (let k = 0; k < 7; k++) { tl.set("#caret", { opacity: 0 }, B[6] + k * 0.5225 + 0.26); tl.set("#caret", { opacity: 1 }, B[6] + (k + 1) * 0.5225); }
        tl.fromTo("#send", { boxShadow: "0 0 0 0px rgba(255,122,69,0.7)" }, { boxShadow: "0 0 0 46px rgba(255,122,69,0)", duration: 0.5, ease: "power2.out", ...IR }, B[13]);
        tl.to("#send", { scale: 0.82, duration: 0.08, ease: "power2.in" }, B[14]);
        tl.to("#send", { scale: 1, duration: 0.25, ease: "back.out(3)" }, B[14] + 0.08);
        sfx("enter.wav", B[14], 0.01, 1.6);
        tl.to("#s2cam", { scale: 1.9, duration: B[15] - B[14], ease: "power3.in" }, B[14] + 0.05);

        // ================= S3 コードの滝 =================
        const CODE = [
          "const scene = new THREE.Scene();",
          "const camera = new THREE.PerspectiveCamera(42, 9 / 16, 0.1, 200);",
          "const planet = new THREE.Mesh(",
          "  new THREE.SphereGeometry(1, 96, 64),",
          "  new THREE.ShaderMaterial({ uniforms, vertexShader, fragmentShader })",
          ");",
          "scene.add(planet);",
          "// 光の輪",
          "const ring = new THREE.RingGeometry(1.45, 2.4, 160);",
          "ring.rotateX(-Math.PI / 2.3);",
          "for (let i = 0; i < 3000; i++) {",
          "  stars[i * 3] = (rand() - 0.5) * 120;",
          "}",
          "tl.from('#title', { scale: 3.2, duration: 0.3, ease: 'expo.out' }, 1.15);",
          "tl.to(camera.position, { z: 4.2, ease: 'power3.inOut' }, 12.21);",
          "function render(t) {",
          "  uniforms.uTime.value = t;",
          "  camera.lookAt(0, 0.2, 0);",
          "  renderer.render(scene, camera);",
          "}",
          "float band = sin(vUv.y * 38.0 + noise(p * 3.0) * 4.0);",
          "vec3 col = mix(orange, violet, smoothstep(-0.4, 0.8, band));",
          "gl_FragColor = vec4(col + rim * 0.9, 1.0);",
          "window.__timelines['main'] = tl;",
          "const beats = [8.0, 8.534, 9.056, 9.579, 10.101];",
          "glitch(B[23], 0.24); punch(B[25], 1.18);",
          "audio.dataset.mediaStart = '8.858';",
          "<div class=\"scene clip\" data-start=\"12.214\">",
          "<canvas id=\"gl\" width=\"1080\" height=\"1920\"></canvas>",
          "renderer.setSize(1080, 1920, false);",
        ];
        function hl(line) {
          const esc = line.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
          if (/^\s*\/\//.test(line)) return '<span class="c">' + esc + "</span>";
          return esc
            .replace(/(&quot;|"|')(.*?)\1/g, '<span class="s">$1$2$1</span>')
            .replace(/\b(const|let|new|for|function|return|float|vec3)\b/g, '<span class="k">$1</span>')
            .replace(/\b(\d+(?:\.\d+)?)\b/g, '<span class="n">$1</span>')
            .replace(/\b(THREE|Math|tl|gsap|renderer|camera|scene)\b/g, '<span class="f">$1</span>');
        }
        ["#p0", "#p1", "#p2"].forEach((id, ci) => {
          const out = [];
          for (let i = 0; i < 140; i++) { const l = CODE[Math.floor(R() * CODE.length)]; out.push(hl(l.length > 30 ? l.slice(0, 30) : l)); }
          $(id).innerHTML = out.join("\n");
        });
        tl.fromTo("#p0", { y: 400 }, { y: -4200, duration: 2.1, ease: "none" }, B[15]);
        tl.fromTo("#p1", { y: -200 }, { y: -3400, duration: 2.1, ease: "none" }, B[15]);
        tl.fromTo("#p2", { y: 900 }, { y: -4600, duration: 2.1, ease: "none" }, B[15]);
        flash(B[15], 1, 0.35);
        punch(B[15], 1.35, 0.5);
        sfx("drop.wav", B[15], 0.29, 1.8);
        tl.from("#s3band", { scaleY: 0, duration: 0.22, ease: "expo.out" }, B[16]);
        tl.from("#s3l1", { y: 40, opacity: 0, duration: 0.25, ease: "power3.out" }, B[16] + 0.06);
        tl.from("#s3l2", { scale: 2.2, opacity: 0, duration: 0.3, ease: "expo.out" }, B[17]);
        punch(B[17], 1.16);
        glitch(B[18], 0.2);

        // ================= S4 コード→図形 =================
        tl.from("#s4top", { xPercent: -100, duration: 0.3, ease: "expo.out" }, B[19]);
        tl.from("#s4bot", { xPercent: 100, duration: 0.3, ease: "expo.out" }, B[19]);
        tl.from("#s4top .tag", { scale: 0, duration: 0.25, ease: "back.out(3)" }, B[19] + 0.15);
        tl.from("#s4bot .tag", { scale: 0, duration: 0.25, ease: "back.out(3)" }, B[19] + 0.2);
        sfx("whoosh.wav", B[19], 0.04, 1.6);
        const lines4 = ["#c1", "#c2", "#c3", "#c4"];
        lines4.forEach((id, i) => {
          tl.from(id, { x: -80, opacity: 0, duration: 0.2, ease: "power3.out" }, B[19 + i]);
          tl.fromTo(id, { backgroundColor: "rgba(255,122,69,0.55)" }, { backgroundColor: "rgba(255,122,69,0.12)", duration: 0.5, ease: "power2.out", ...IR }, B[19 + i]);
        });
        const C = 2 * Math.PI * 230;
        tl.fromTo("#pcirc", { strokeDasharray: C, strokeDashoffset: C }, { strokeDashoffset: 0, duration: 0.45, ease: "power2.inOut" }, B[19]);
        const RL = 1700;
        tl.fromTo("#pring", { strokeDasharray: RL, strokeDashoffset: RL }, { strokeDashoffset: 0, duration: 0.45, ease: "power2.inOut" }, B[20]);
        const st = $("#stars4");
        for (let i = 0; i < 90; i++) {
          const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
          c.setAttribute("cx", String(60 + R() * 960)); c.setAttribute("cy", String(140 + R() * 860)); c.setAttribute("r", String(2 + R() * 5));
          c.setAttribute("fill", R() < 0.3 ? "#5be7ff" : "#ffffff"); c.setAttribute("class", "st4");
          st.appendChild(c);
        }
        tl.from(".st4", { scale: 0, opacity: 0, transformOrigin: "50% 50%", duration: 0.3, ease: "back.out(3)", stagger: { each: 0.004, from: "center" } }, B[21]);
        tl.to("#pfill", { opacity: 1, duration: 0.3, ease: "power2.out" }, B[22]);
        tl.to("#pglow", { opacity: 0.8, duration: 0.3, ease: "power2.out" }, B[22]);
        tl.fromTo("#pfill", { scale: 0.6, transformOrigin: "540px 560px" }, { scale: 1, duration: 0.4, ease: "back.out(2)" }, B[22]);
        punch(B[22], 1.08);

        // ================= S5 宇宙(Three.js) =================
        const T0 = B[23];
        const renderer = new THREE.WebGLRenderer({ canvas: $("#gl"), antialias: true, preserveDrawingBuffer: true });
        renderer.setPixelRatio(1);
        renderer.setSize(1080, 1920, false);
        renderer.setClearColor(0x04050a, 1);
        const scene = new THREE.Scene();
        const camera = new THREE.PerspectiveCamera(42, 1080 / 1920, 0.1, 400);
        // 星
        const NS = 3500, sp = new Float32Array(NS * 3), sc = new Float32Array(NS * 3);
        for (let i = 0; i < NS; i++) {
          const r = 30 + R() * 140, th = R() * Math.PI * 2, ph = Math.acos(2 * R() - 1);
          sp[i * 3] = r * Math.sin(ph) * Math.cos(th); sp[i * 3 + 1] = r * Math.cos(ph); sp[i * 3 + 2] = r * Math.sin(ph) * Math.sin(th);
          const w = 0.6 + R() * 0.4, blue = R() < 0.25;
          sc[i * 3] = blue ? 0.5 * w : w; sc[i * 3 + 1] = blue ? 0.85 * w : w * 0.95; sc[i * 3 + 2] = w;
        }
        const sg = new THREE.BufferGeometry();
        sg.setAttribute("position", new THREE.BufferAttribute(sp, 3));
        sg.setAttribute("color", new THREE.BufferAttribute(sc, 3));
        const stars = new THREE.Points(sg, new THREE.PointsMaterial({ size: 0.42, vertexColors: true, sizeAttenuation: true, transparent: true, opacity: 0.95, depthWrite: false }));
        scene.add(stars);
        // ワープの光の筋(12.214〜13.3 だけ見える)
        const NW = 900, wp = new Float32Array(NW * 6);
        for (let i = 0; i < NW; i++) {
          const a = R() * Math.PI * 2, r = 1.6 + R() * 14, z0 = -10 + R() * 90, L = 4 + R() * 10;
          const x = Math.cos(a) * r, y = Math.sin(a) * r;
          wp.set([x, y, z0, x, y, z0 + L], i * 6);
        }
        const wg = new THREE.BufferGeometry();
        wg.setAttribute("position", new THREE.BufferAttribute(wp, 3));
        const warpMat = new THREE.LineBasicMaterial({ color: 0xbfefff, transparent: true, opacity: 0, blending: THREE.AdditiveBlending, depthWrite: false });
        const warp = new THREE.LineSegments(wg, warpMat);
        scene.add(warp);
        // 惑星(縞と雲をシェーダーで)
        const uni = { uTime: { value: 0 }, uFlare: { value: 0 } };
        const planet = new THREE.Mesh(
          new THREE.SphereGeometry(1, 128, 96),
          new THREE.ShaderMaterial({
            uniforms: uni,
            vertexShader: "varying vec3 vN; varying vec3 vP; varying vec2 vUv; void main(){ vUv=uv; vN=normalize(normalMatrix*normal); vP=position; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);} ",
            fragmentShader: [
              "uniform float uTime; uniform float uFlare; varying vec3 vN; varying vec3 vP; varying vec2 vUv;",
              "float h(vec3 p){ return fract(sin(dot(p, vec3(12.9898,78.233,37.719)))*43758.5453); }",
              "float n3(vec3 p){ vec3 i=floor(p); vec3 f=fract(p); f=f*f*(3.0-2.0*f);",
              " return mix(mix(mix(h(i),h(i+vec3(1,0,0)),f.x),mix(h(i+vec3(0,1,0)),h(i+vec3(1,1,0)),f.x),f.y),",
              "            mix(mix(h(i+vec3(0,0,1)),h(i+vec3(1,0,1)),f.x),mix(h(i+vec3(0,1,1)),h(i+vec3(1,1,1)),f.x),f.y),f.z); }",
              "void main(){",
              " float a=uTime*0.12; vec3 p=vec3(vP.x*cos(a)-vP.z*sin(a), vP.y, vP.x*sin(a)+vP.z*cos(a));",
              " float nn=n3(p*3.0)*0.6+n3(p*7.0)*0.3+n3(p*15.0)*0.1;",
              " float band=sin(p.y*16.0+nn*5.0);",
              " vec3 c1=vec3(1.0,0.48,0.27); vec3 c2=vec3(0.36,0.22,0.78); vec3 c3=vec3(1.0,0.85,0.65);",
              " vec3 col=mix(c2,c1,smoothstep(-0.6,0.7,band)); col=mix(col,c3,smoothstep(0.75,1.0,band)*0.6);",
              " vec3 L=normalize(vec3(-0.6,0.5,0.7)); float d=max(dot(vN,L),0.0);",
              " float rim=pow(1.0-max(vN.z,0.0),2.5);",
              " col=col*(0.18+0.95*d)+vec3(0.45,0.8,1.0)*rim*(0.9+uFlare*1.5);",
              " gl_FragColor=vec4(col,1.0);",
              "}",
            ].join("\n"),
          })
        );
        scene.add(planet);
        // 光の輪
        const ringGeo = new THREE.RingGeometry(1.45, 2.5, 200, 1);
        const ringMat = new THREE.ShaderMaterial({
          uniforms: uni, transparent: true, side: THREE.DoubleSide, depthWrite: false, blending: THREE.AdditiveBlending,
          vertexShader: "varying vec3 vP; void main(){ vP=position; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);} ",
          fragmentShader: "uniform float uTime; uniform float uFlare; varying vec3 vP; void main(){ float r=length(vP.xy); float t=(r-1.45)/1.05; float s=0.55+0.45*sin(r*60.0)*sin(r*23.0+1.3); float a=smoothstep(0.0,0.08,t)*smoothstep(1.0,0.75,t)*s; vec3 c=mix(vec3(1.0,0.75,0.45),vec3(0.4,0.85,1.0),t); gl_FragColor=vec4(c*(0.9+uFlare*2.0), a*0.85); }",
        });
        const ring = new THREE.Mesh(ringGeo, ringMat);
        ring.rotation.x = -Math.PI / 2.35; ring.rotation.y = 0.28;
        scene.add(ring);
        // 大気の光(後ろの板)
        const glowMat = new THREE.ShaderMaterial({
          uniforms: uni, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending,
          vertexShader: "varying vec2 vUv; void main(){ vUv=uv; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);} ",
          fragmentShader: "uniform float uFlare; varying vec2 vUv; void main(){ float d=length(vUv-0.5)*2.0; float a=smoothstep(1.0,0.35,d)*0.55*(1.0+uFlare); gl_FragColor=vec4(vec3(1.0,0.5,0.3)*a, a); }",
        });
        const glow = new THREE.Mesh(new THREE.PlaneGeometry(5.2, 5.2), glowMat);
        glow.position.z = -0.6;
        scene.add(glow);
        // 拍で広がる光の輪(衝撃波)
        const waves = [];
        const waveTimes = [B[25], B[27], B[29]];
        waveTimes.forEach(() => {
          const m = new THREE.Mesh(new THREE.RingGeometry(0.96, 1.0, 160), new THREE.MeshBasicMaterial({ color: 0x9fe8ff, transparent: true, opacity: 0, side: THREE.DoubleSide, blending: THREE.AdditiveBlending, depthWrite: false }));
          m.rotation.x = -Math.PI / 2.35; m.rotation.y = 0.28;
          scene.add(m); waves.push(m);
        });
        const eOut = gsap.parseEase("expo.out"), eIO = gsap.parseEase("power3.inOut");
        const clamp01 = (x) => Math.max(0, Math.min(1, x));
        function renderSpace(t) {
          const lt = Math.max(0, t - T0);
          uni.uTime.value = lt;
          // 寄り: 遠く(26) → 近く(5.2)。拍ごとに小さく突っ込む
          let z = 7.5 + 70 * Math.pow(1 - eOut(clamp01(lt / 2.6)), 1.0);
          warpMat.opacity = 0.9 * (1 - clamp01((lt - 0.5) / 0.6));
          [B[24], B[25], B[26], B[28], B[30]].forEach((bt) => { const k = t - bt; if (k >= 0 && k < 0.5) z -= 0.9 * (1 - eOut(k / 0.5)); });
          // ムチ振り(14.316)とゆっくり回る
          let ang = -0.35 + lt * 0.05 + 0.75 * eOut(clamp01((t - B[27]) / 0.35)) + 0.6 * eOut(clamp01((t - B[29]) / 0.4));
          // 文字の爆発の間(16.428〜)は少し引く
          z += 2.5 * eIO(clamp01((t - B[31]) / 1.0));
          const y = 0.9 + 0.6 * Math.sin(lt * 0.4);
          camera.position.set(Math.sin(ang) * z, y, Math.cos(ang) * z);
          camera.lookAt(0, 0.12, 0);
          glow.quaternion.copy(camera.quaternion);
          let flare = 0;
          waveTimes.forEach((wt, i) => {
            const k = t - wt; const w = waves[i];
            if (k >= 0 && k < 1.2) { const p = eOut(k / 1.2); w.scale.setScalar(1.3 + p * 5.5); w.material.opacity = 0.9 * (1 - k / 1.2); flare = Math.max(flare, 1 - k / 0.5); }
            else { w.material.opacity = 0; }
          });
          uni.uFlare.value = Math.max(0, flare);
          stars.rotation.y = lt * 0.01;
          renderer.render(scene, camera);
        }
        // 3D の上に重ねる文字と「その形を作ったコード」
        tl.from("#s5label span", { y: -50, opacity: 0, duration: 0.35, ease: "back.out(2)" }, B[24]);
        const GHOST = ["new THREE.SphereGeometry(1, 128, 96)", "new THREE.RingGeometry(1.45, 2.5)", "camera.position.z = 5.2", "renderer.render(scene, camera)"];
        const ghost = $("#ghost");
        GHOST.forEach((g, i) => { const d = document.createElement("div"); d.textContent = "> " + g; d.className = "gl" + i; ghost.appendChild(d); });
        [B[25], B[26], B[27], B[28]].forEach((t, i) => tl.from(".gl" + i, { x: -60, opacity: 0, duration: 0.2, ease: "power3.out" }, t));
        glitch(T0, 0.24);
        tl.from("#ghost", { opacity: 0, duration: 0.15, ease: "power1.out" }, B[25]);
        flash(T0, 0.7, 0.3);
        sfx("glitch.wav", T0, 0.05, 1.4);
        punch(B[25], 1.12); punch(B[27], 1.1); punch(B[29], 1.14);
        tl.to("#s5label, #ghost", { opacity: 0, duration: 0.2, ease: "power1.in" }, B[31] - 0.2);
        tl.to("#darken", { opacity: 0.45, duration: 0.3, ease: "power2.out" }, B[31]);

        // ================= S6 文字の爆発 =================
        ["#e1", "#e2", "#e3", "#e4"].forEach((id) => { const el = $(id); const txt = el.textContent; el.textContent = ""; Array.from(txt).forEach((c) => { const s = document.createElement("span"); s.textContent = c; el.appendChild(s); }); });
        tl.from("#e1 span", { y: 140, opacity: 0, rotation: () => (R() - 0.5) * 60, duration: 0.28, ease: "back.out(2)", stagger: 0.025 }, B[31]);
        tl.from("#e2 span", { scale: 0, opacity: 0, duration: 0.25, ease: "expo.out", stagger: 0.022 }, B[33]);
        tl.from("#e3", { scale: 3.4, opacity: 0, duration: 0.3, ease: "expo.out" }, B[35]);
        tl.from("#e4", { y: 300, opacity: 0, scaleY: 2, duration: 0.3, ease: "back.out(2.4)" }, B[36]);
        shake(B[35], 40); shake(B[36], 30);
        sfx("slam.wav", B[35], 0.32, 1.5);
        sfx("slam.wav", B[36], 0.32, 1.3);
        // 拍 37 で文字が四方に吹き飛ぶ(文字の爆発)
        const allCh = document.querySelectorAll("#s6 .line span");
        allCh.forEach((s) => {
          const a = R() * Math.PI * 2, d = 700 + R() * 1100;
          tl.to(s, { x: Math.cos(a) * d, y: Math.sin(a) * d, rotation: (R() - 0.5) * 720, scale: 0.3 + R() * 2.2, opacity: 0, duration: 0.9, ease: "power3.out" }, B[37]);
        });
        flash(B[37], 0.9, 0.3);
        punch(B[37], 1.3, 0.5);
        sfx("drop.wav", B[37], 0.29, 1.8);
        // 粒の爆発(2D canvas。時刻だけで決まる)
        const bctx = $("#burst").getContext("2d");
        const PB = [];
        [B[37], B[38]].forEach((bt, bi) => {
          for (let i = 0; i < 520; i++) { const a = R() * Math.PI * 2, v = 300 + R() * 2400; PB.push({ t0: bt, a, v, s: 2 + R() * 7, c: ["#ff7a45", "#5be7ff", "#ffffff", "#ffd166", "#8b6cff"][Math.floor(R() * 5)], cx: 540, cy: bi ? 900 : 960 }); }
        });
        function renderBurst(t) {
          bctx.clearRect(0, 0, 1080, 1920);
          PB.forEach((p) => {
            const k = t - p.t0; if (k < 0 || k > 1.6) return;
            const dist = p.v * (1 - Math.exp(-3.2 * k)) / 3.2;
            const x = p.cx + Math.cos(p.a) * dist, y = p.cy + Math.sin(p.a) * dist + 120 * k * k;
            bctx.globalAlpha = Math.max(0, 1 - k / 1.6);
            bctx.fillStyle = p.c;
            bctx.fillRect(x - p.s / 2, y - p.s / 2, p.s, p.s * (1 + 3 * Math.exp(-4 * k)));
          });
          bctx.globalAlpha = 1;
        }
        flash(B[38], 0.5, 0.25);
        punch(B[38], 1.12);

        // ================= S7 正体(ブラウザの窓に縮む) =================
        tl.to("#spaceWrap", { scale: 0.5, y: -250, duration: 0.45, ease: "expo.inOut" }, B[39] - 0.1);
        tl.to("#darken", { opacity: 0, duration: 0.3, ease: "power1.out" }, B[39]);
        tl.from("#win", { opacity: 0, scale: 1.8, duration: 0.45, ease: "expo.inOut" }, B[39] - 0.1);
        sfx("whoosh.wav", B[39], 0.04, 1.6);
        tl.from("#winbar b", { y: -30, opacity: 0, duration: 0.25, ease: "back.out(3)" }, B[40]);
        tl.from("#s7label", { y: 80, opacity: 0, duration: 0.3, ease: "power4.out" }, B[41]);
        tl.from("#s7label .hl", { scale: 2.2, duration: 0.3, ease: "expo.out" }, B[42]);
        const S7C = ["<" + "script src=\"three.min.js\"><" + "/script>","const planet = new THREE.Mesh(...);", "tl.from('#e3', { scale: 3.4 }, 18.53);", "renderer.render(scene, camera);", "window.__timelines['main'] = tl;"];
        const s7 = $("#s7code");
        S7C.forEach((l, i) => { const d = document.createElement("div"); d.innerHTML = hl(l); d.className = "s7l"; s7.appendChild(d); });
        tl.from("#s7code", { y: 60, opacity: 0, duration: 0.3, ease: "power3.out" }, B[42]);
        tl.fromTo(".s7l", { y: 0 }, { y: -80, duration: B[46] - B[43], ease: "none" }, B[43]);
        punch(B[44], 1.08);
        tl.to("#cam", { scale: 1.25, duration: B[46] - B[45], ease: "power3.in" }, B[45]);
        glitch(B[45] + 0.1, 0.36);
        sfx("glitch.wav", B[45] + 0.1, 0.05, 1.3);

        // ================= S8 種明かし =================
        tl.set("#cam", { scale: 1, x: 0, y: 0, rotation: 0, skewX: 0 }, B[46]);
        for (let k = 0; k < 2; k++) { tl.set("#s8caret", { opacity: 0 }, B[46] + k * 0.5225 + 0.26); tl.set("#s8caret", { opacity: 1 }, B[46] + (k + 1) * 0.5225); }
        tl.set("#s8caret", { opacity: 0 }, B[48]);
        tl.from("#s8q", { y: 40, opacity: 0, duration: 0.25, ease: "power3.out" }, B[47]);
        tl.set("#s8q", { opacity: 0 }, B[48]);
        tl.from("#r1", { scale: 3.6, opacity: 0, duration: 0.3, ease: "expo.out" }, B[48]);
        tl.from("#r2", { x: -800, skewX: 30, opacity: 0, duration: 0.3, ease: "power4.out" }, B[49]);
        tl.from("#r3", { x: 800, skewX: -30, opacity: 0, duration: 0.3, ease: "power4.out" }, B[50]);
        tl.from("#r4", { y: 260, scaleY: 1.8, opacity: 0, duration: 0.3, ease: "back.out(2.2)" }, B[51]);
        tl.from("#r4bar", { scaleX: 0, duration: 0.3, ease: "power3.inOut" }, B[51] + 0.12);
        flash(B[48], 0.8, 0.3);
        shake(B[48], 36); shake(B[51], 30);
        sfx("reveal.wav", B[48], 0.24, 1.6);
        sfx("slam.wav", B[51], 0.32, 1.4);
        // ショート版: 「書いた」を見せてから、ブログへの誘導に替える(B[52]=27.47)
        tl.to("#s8stack", { opacity: 0, scale: 0.9, duration: 0.15, ease: "power2.in" }, B[52] - 0.2);
        tl.from("#n1", { y: 80, opacity: 0, duration: 0.3, ease: "power3.out" }, B[52]);
        tl.from("#n2", { x: -800, skewX: 30, opacity: 0, duration: 0.3, ease: "power4.out" }, B[53]);
        tl.from("#n3", { scale: 0, rotation: -6, opacity: 0, duration: 0.35, ease: "back.out(2.6)" }, B[54]);
        sfx("slam.wav", B[52], 0.32, 1.2);
        sfx("slam.wav", B[54], 0.32, 1.0);
        tl.from("#credit", { opacity: 0, duration: 0.4, ease: "power1.out" }, B[53] + 0.2);

        // ---------- 毎コマ描く物(Three.js と粒) ----------
        const proxy = { v: 0 };
        function renderAll() {
          const t = tl.time();
          if (t >= T0 - 0.05 && t <= 24.4) renderSpace(t);
          if (t >= B[37] - 0.05 && t <= 20.7) renderBurst(t);
        }
        tl.to(proxy, { v: 1, duration: 30, ease: "none", onUpdate: renderAll }, 0);
        renderSpace(T0 + 3.5);

        window.__timelines["main"] = tl;
      })();
    </script>
  </body>
</html>
3本目 tools/make_beats.py(10行・クリックで開く)
# 曲の拍(cues json)を映像の秒に直して beats.film.json に書く。
# 使い方: python -X utf8 tools/make_beats.py
# 曲の 8.858 秒目(=ブレイク明けの最初の強拍 16.858 秒の 8 秒前)から使うので、映像の 8.000 秒=曲のドロップ。
import json, pathlib
here = pathlib.Path(__file__).resolve().parent.parent
MEDIA_START = 8.858
src = json.loads((here / "assets/music/happy-beats-business-moves-vol-11-by-ende-dot-app.music-cues.json").read_text(encoding="utf-8"))
beats = [round(b["time"] - MEDIA_START, 3) for b in src["beats"] if 0 <= b["time"] - MEDIA_START <= 30.5]
(here / "assets/music/beats.film.json").write_text(json.dumps({"mediaStart": MEDIA_START, "beats": beats}, ensure_ascii=False), encoding="utf-8")
print(len(beats), beats)

HyperFramesで動画になる仕組み

HyperFramesは、ブラウザで動くページを決まった時刻ごとに1コマずつ撮って、FFmpegでMP4につなぐ道具です。Claude Codeが書くのは、ふつうのWebページと同じHTML・CSS・JavaScriptです。

頼みの文をClaude CodeがHTMLにし、HyperFramesが1コマずつ撮ってMP4にする流れ
頼みの文をClaude CodeがHTMLにし、HyperFramesが1コマずつ撮ってMP4にする流れ(上の10秒の例は1文の頼みから)

この撮ってつなぐ作業を、HyperFramesでは「レンダリング」と呼んでいます。この記事でいう「書き出し」はレンダリングのことです。パラパラ漫画を思い浮かべると分かりやすいです。30fpsで10秒なら300コマ。HyperFramesはページの時計を「0秒、0.033秒、0.066秒…」と1コマ分ずつ進めて、その都度ブラウザの画面を撮ります。私の書き出しのログでも「totalFrames 300」と出ていました。

動きはGSAPという部品の時間軸に書きます。HyperFramesは、その時間軸を window.__timelines という決まった場所から受け取って、好きな時刻に止めて撮ります。だから同じコードなら何度書き出しても同じ絵になります。映像生成AIのように、頼むたびに違う映像が出てくることはありません。

映像生成AIは頼むたびに違う映像になるが、コードで作る動画は同じコードなら毎回同じ絵になる
映像生成AIは頼むたびに違う映像になるが、コードで作る動画は同じコードなら毎回同じ絵になる

この「毎回同じ絵」になる性質のおかげで、直したい所だけ直して書き出し直せます。逆に言うと、Math.random() や今の時刻を使うと撮るたびに絵が変わってしまうので、3本の頼み方の文では「Math.random と Date を使わない」と書いています。

自分で書き出せる最小のコード例

ここからは、私が実際に書き出して動くのを確かめた、10秒の縦型動画の index.html です。輪が回って、タイトルの文字がふわっと出てくるだけの、1場面(1シーン)のアニメーションです。npx hyperframes init で作ったフォルダの index.html を、まるごとこれに置き換えてください。

<!doctype html>
<html lang="ja" data-resolution="portrait">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=1080, height=1920" />
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
    <style>
      html, body { margin: 0; width: 1080px; height: 1920px; overflow: hidden; background: #0b1020; }
      #root, #scene { width: 100%; height: 100%; }
      #scene { display: flex; flex-direction: column; align-items: center;
               justify-content: center; gap: 60px;
               font-family: "Noto Sans JP", sans-serif; color: #fff; }
      #ring { width: 360px; height: 360px; border-radius: 50%;
              border: 24px solid #38bdf8; border-top-color: #f472b6; box-sizing: border-box; }
      #title { font-size: 96px; font-weight: 900; margin: 0; }
      #sub { font-size: 48px; font-weight: 700; color: #94a3b8; margin: 0; }
    </style>
  </head>
  <body>
    <div id="root" data-composition-id="main" data-start="0" data-duration="10"
         data-width="1080" data-height="1920">
      <div id="scene" class="clip" data-start="0" data-duration="10" data-track-index="0">
        <div id="ring"></div>
        <div id="title">コードで作った動画</div>
        <p id="sub">カメラは使っていません</p>
      </div>
    </div>
    <script>
      const tl = gsap.timeline({ paused: true });
      tl.from("#ring", { scale: 0, duration: 1, ease: "back.out(1.7)" }, 0)
        .to("#ring", { rotation: 720, duration: 9, ease: "none" }, 1)
        .from("#title", { y: 120, opacity: 0, duration: 0.8, ease: "power3.out" }, 1)
        .from("#sub", { y: 60, opacity: 0, duration: 0.8, ease: "power3.out" }, 2.5)
        .to(["#title", "#sub", "#ring"], { opacity: 0, duration: 0.6 }, 9.2);
      window.__timelines["main"] = tl;
      tl.seek(0);
    </script>
  </body>
</html>

読み方を少しだけ。data-duration="10" が動画の長さ(秒)、data-width と data-height が画面の大きさです。tl.from(...) の最後の数字は「何秒目に始めるか」で、輪が0秒、見出しが1秒、小見出しが2.5秒に出てきて、9.2秒から消えていきます。

書き出した10秒の動画から5コマを並べると、こうなりました。輪が回りながら、文字が下から順に出てきます。

記事のコードをそのまま書き出した10秒の動画(0.5秒・1.5秒・3秒・5秒・9.5秒のコマ)
記事のコードをそのまま書き出した10秒の動画(0.5秒・1.5秒・3秒・5秒・9.5秒のコマ)

実はこのコード、1回目は失敗しています。最初は輪・見出し・小見出しの3つにそれぞれ class="clip" を付けていたのですが、書き出すと3つが画面の真ん中で重なってしまいました。

失敗例 3つの要素それぞれにclass=clipを付けると、見出しと小見出しと輪が中央で重なった(5秒目のコマを拡大)
失敗例 3つの要素それぞれにclass=clipを付けると、見出しと小見出しと輪が中央で重なった(5秒目のコマを拡大)

重なり方を見る限り、class="clip" を付けた要素はそれぞれ別の部品として重ねて置かれ、縦に並べるCSSが効かなくなるようです(仕組みは見えた結果からの推測です)。上のコードのように、3つを1つの div class="clip" で包むと崩れませんでした。厄介なのは、重なった版でも npx hyperframes lint は「0 errors, 0 warnings」で、何も教えてくれなかったことです。逆に包んだ版は「nested_structure_needs_subcomposition」という警告が1件出ますが、書き出した動画は正しく並んでいます。

では重なりはどう見つけるか。npx hyperframes check を使います。lint に加えて、ヘッドレスのChromeでタイムラインを流しながら画面の並びを検査するコマンドです。重なった版に当てると、lint の部分は「0 errors, 0 warnings」のままでしたが、画面の検査で次のエラーが出て「Check failed」で止まりました(途中の時刻は省略しています)。

✗ t=2.625 … 9.5s content_overlap #title inside #sub "コードで作った動画" — Two text blocks overlap and may render unreadable.

包んだ最終版では、このエラーは消えて「Check passed」です。書き出す前に check、書き出した後にコマを目で見る、の2段で確かめるのが確実でした。なお最終版でも、見出しと小見出しが YouTube ショートや TikTok の画面の端(ボタンなどが重なる所)にかかるという警告(outside_safe_zone)が出ます。ショートに上げるなら、見出しの 96px を小さくするなど文字を内側に寄せてください。もう1つ、0秒目が背景だけだと一覧に出る表紙が空になる、という警告(first_frame_empty)も出ます。最小の例は輪も文字も0から現れるので、表紙を気にするなら0秒目から何か見えるようにします。

HyperFramesの書き出しコマンドと画質の選び方

書き出しは、index.html のあるフォルダで次の1行です。

npx --yes hyperframes@0.10.7 render -o out.mp4

確かめた結果、上の最小の例は「717.4 KB・10.0s video」で書き出され、ffprobeで見ても h264・1080×1920・30fps・10.000秒でした。よく使う設定は次の4つです。

やりたいこと 付けるもの
試し書きを軽く速く --quality draft
仕上げの画質 --quality high(delivery と同じ)
1秒のコマ数を変える --fps 60
背景が透明な動画にする --format webm(CSSの背景を transparent にする)

何も付けないと画質は「looks(CRF 16)」になります(render --help の表示より)。書き出す前に npx --yes hyperframes@0.10.7 check で、書き方の誤り(lint)と画面の重なりをまとめて確かめられます。preview を使うとブラウザで下見できる画面(Studio)が開くと説明されていますが、私は今回使っていません。

透明な背景も試しました。最小の例の background: #0b1020; を background: transparent; に変えて --format webm で書き出すと、「rendered in 47.9s」で1.7MBのWebMができました。5秒目のコマを取り出して数えると、画面の96.5%の画素が完全な透明(アルファ0)で、輪と文字だけが残っていました。ほかの動画の上に重ねる字幕やロゴのアニメーションを作るときに使えます。

重い動画だと時間はかなり延びます。2本目の街(30秒)を、私のPC(Core i7-1360P・内蔵GPUのIris Xe)で書き出し直したところ、「rendered in 3m 36.2s」でした。ビルが6,000棟あってコマごとに3回描いて重ねる作りなので、最小の例とは比べものになりません。

HyperFramesでつまずきやすい所

版を固定しないと中身が変わる

HyperFramesは更新がとても速いので、作った時の版を @ で固定して打つのがおすすめです。npmの公開記録を見ると、0.10.0(11月30日)から0.10.8(12月2日)まで、約2日で7回も新しい版が出ていました(日付は世界標準時・2026年12月2日時点)。この記事を書いている途中にも0.10.8が出ています。

版を付けずに npx hyperframes render と打つと、その日の最新版で動きます。私の3本も、1本目と2本目は0.8.33、3本目は0.10.7で作っていて、同じ日に作ったのに版が違います。0.8.33で作った2本目は、npx --yes hyperframes@0.8.33 render と版を付ければ今でもそのまま書き出せました。init が作る package.json も、npx --yes hyperframes@0.10.7 preview のように版が固定されています。

Chromeの取り込みとGPU

最初の書き出しで Chrome(284MB)を自動で取ってきます。会社のPCなどでダウンロードが止められている場合は、HYPERFRAMES_BROWSER_PATH に手元のChromeの場所を入れると、それを使うと表示されていました(この設定は試していません)。

私のPCでは、書き出しのログに「hardware gpu」と出ていて、内蔵GPUで描いていました。GPUの無いPCでの書き出しは確かめていません。2本目の街のように3Dを重く使う動画は、GPUの無いPCだとどれくらい遅くなるのか、私には分からないままです。

作業フォルダの場所

フォルダのパスが長いと動かない道具もあるので、HyperFramesでも試しました。245字の深いフォルダの中で最小の例を書き出したところ、「rendered in 18.9s」で問題なく通りました(出力ファイルのパスは258字)。Chromeは作業フォルダではなくホームの下に置かれるので、長いパスの影響を受けにくいのだと思います。

音楽を付けたらクレジットを書く

3本の動画の曲は、Sascha Ende さん(ende.app)の「Happy Beats / Business Moves」シリーズで、1本目と2本目が Vol. 12、3本目が Vol. 11 です。ライセンスはCC BY 4.0なので、使うときは「Music: Sascha Ende, ende.app (CC BY 4.0)」のようなクレジット表記が必要です。私は3本ともYouTubeの説明欄に曲名とライセンスを書きました。動画の中にも入れたのは1本目と3本目で(1本目は上のコマ一覧の右下)、2本目は説明欄だけです。ネットで拾った曲をそのまま使うのは避けてください。

よくある質問

Q. プログラミングができなくても作れますか?
A. 作れます。コードを書くのはClaude Codeです。ただ、できた動画を見て「文字が切れている」「もっとゆっくり」と日本語で伝える作業は残ります。上の最小の例の数字を変えて書き出し直してみると、どこが何を決めているかがすぐ分かります。

Q. 本当に無料ですか?
A. HyperFrames・Node.js・FFmpeg・Chromeは無料です。Claude Codeを使うにはClaudeの有料プラン(Pro以上)が要ります。今回の3本で、APIキーや映像生成AIの料金は使っていません。

Q. Remotionとは何が違いますか?
A. どちらもコードで動画を作る道具ですが、RemotionはReact(JavaScriptの部品の書き方)で書き、HyperFramesはふつうのHTMLで書きます。私は今回Remotionを使っていないので、使い勝手の比べはしていません。

📬 新着記事をメールでお届けします

記事公開時にメールでお知らせします。週数本・無料・いつでも 1 クリックで解除できます。

uri uri

uri uriと申します。生成AI専門ブログ「生成AIニスト」運営者。 ChatGPT・Gemini・Claudeなど主要な生成AIを自分で契約し、毎日実際に触って検証しています。記事の手順やエラー対処は、必ず自分の画面で再現し、実機のスクリーンショットで確かめてから公開。料金や仕様は提供元の公式情報で裏取りし、いつ時点の情報かを明記します。「読んだ人が同じ画面で再現できること」を基準に書いています。