/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useRef } from 'react';
/**
* 智算走廊 · 能源到智能 —— 登录页背景动画(三幕式,电影级写实版)
*
* 三幕空间(自左向右,与阅读方向一致的叙事流):
* 第一幕 能源(0~28% 宽):冷却塔(暖调混凝土双曲面 + 环向施工缝 +
* 警示带 + 蒸汽)、白色三叶风机(锥形塔筒 + 法兰线 + 检修门 +
* 红色叶尖警示条 + 航空灯)、近黑深蓝光伏阵列(栅线 + 掠光)
* 第二幕 算力(35~65%):哑光黑机柜双排(现实机柜即黑色),服务器
* 单元分层(面板/通风槽/拉手),绿/青/黄/红状态灯 + 青色活动条
* 第三幕 智能(75~100%):四块悬浮应用屏,各配专属彩色内容 ——
* 心电(绿波形+红十字+心率数字)/雷达(橙色扫掠+红黄目标点)/
* 楼宇(蓝楼体+暖黄窗灯+红色天线灯)/K线(红绿蜡烛+金色趋势线)
*
* 立体纵深(自远及近):星空/月亮/流星(暗)或晨阳/漂浮云(浅) →
* 体积光 → 双层天际线(远层矮淡、近层带窗灯,视差递增) → 反光机房
* 地板(远景+实体倒影、消失点透视网格) → 地平线雾带 → 三幕实体
* (接地阴影) → 贴地低雾。
*
* 所有运动按 60fps 基准 delta-time 推进,高刷屏速度一致;风机航空灯
* 全场同步闪烁(风电场规范)。
*
* 电影质感:teal-orange 好莱坞调色(左暖右冷 screen 叠加)、地平线
* 镜头光斑、胶片颗粒(offscreen 噪声图案,时间抖动)、上下柔和
* letterbox 黑边、收尾 vignette。
*
* 配色约定:实体采用固定写实调色板(风机白、冷却塔混凝土、光伏近黑
* 蓝、机柜哑黑、LED 多彩),不跟随品牌色 —— 品牌色跟随会把全场压成
* 单色调。仅明暗模式实时探测(500ms 轮询)。
*
* 历史坑位:旧版风机叶片是深色剪影粗圆头线条,旋转起来在暗背景上
* 酷似章鱼触手(用户误认为海洋主题残留)。现为白色锥形翼型实体填充。
*
* 工程约定(与本目录其他主题一致):
* - 暗色 = 午夜机房;浅色 = 晨光机房
* - prefers-reduced-motion:静态构图,只留极缓 token;移动端减景减倒影
* - 单 canvas + 单 rAF,dpr 上限 1.5,对象池复用,几何全部按宽高比例
* 计算 —— resize 不重建任何对象、不重抽随机数
*/
// ─── 工具函数 ─────────────────────────────────────────────────
const rgba = (c, a) => `rgba(${c.r}, ${c.g}, ${c.b}, ${a})`;
const lerp = (a, b, t) => a + (b - a) * t;
const clamp01 = (v) => Math.min(1, Math.max(0, v));
const bezierPoint = (p0, p1, p2, p3, t) => {
const mt = 1 - t;
return (
mt * mt * mt * p0 +
3 * mt * mt * t * p1 +
3 * mt * t * t * p2 +
t * t * t * p3
);
};
// 确定性伪随机(mulberry32):所有构造期随机数用它,保证 StrictMode
// 重挂载/多实例下各自稳定,且不依赖 resize 时机
const mulberry32 = (seed) => {
let a = seed >>> 0;
return () => {
a += 0x6d2b79f5;
let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
};
const GLYPHS = ['0', '1', 'λ', 'Σ', '∇', 'ƒ', '>', '{ }'];
// 地平线位置(高度比例):以下为反光地板区
const GROUND = 0.87;
// 写实调色板(全场固定,不随品牌色)
const C = {
amber: { r: 251, g: 191, b: 36 }, // 能量脉冲 / 窗灯
gold: { r: 255, g: 205, b: 92 }, // token 芯片
cyan: { r: 45, g: 212, b: 240 }, // 数据脉冲 / 活动条
sky: { r: 76, g: 175, b: 254 }, // 楼宇 / 地面辉光
green: { r: 52, g: 211, b: 123 }, // 心电 / 正常状态灯 / 阳线
red: { r: 244, g: 84, b: 84 }, // 航空灯 / 告警灯 / 阴线
orange: { r: 251, g: 146, b: 60 }, // 雷达扫掠
violet: { r: 172, g: 148, b: 250 }, // 金融屏边框
yellow: { r: 250, g: 204, b: 21 }, // 趋势线 / 雷达目标
ice: { r: 190, g: 220, b: 255 }, // 星尘 / 星空
teal: { r: 42, g: 168, b: 188 }, // 地平线辉光 / 调色冷端
warm: { r: 255, g: 156, b: 66 }, // 调色暖端 / 晨光
};
// 状态灯配色权重:绿为主(正常),青次之(IO),黄少量(负载),红极少(告警)
const pickLedColor = (roll) => {
if (roll < 0.52) return C.green;
if (roll < 0.74) return C.cyan;
if (roll < 0.92) return C.amber;
return C.red;
};
// 圆柱/塔筒立体感:横向三段渐变(边缘暗、中央亮)
const cylGrad = (ctx, x0, x1, edge, mid) => {
const g = ctx.createLinearGradient(x0, 0, x1, 0);
g.addColorStop(0, edge);
g.addColorStop(0.5, mid);
g.addColorStop(1, edge);
return g;
};
// 接地阴影:实体与地面的接触暗影,立体感的关键一笔
const contactShadow = (ctx, x, y, rx, isDark) => {
ctx.save();
ctx.translate(x, y);
ctx.scale(1, 0.22);
const g = ctx.createRadialGradient(0, 0, 0, 0, 0, rx);
g.addColorStop(0, isDark ? 'rgba(0, 0, 0, 0.5)' : 'rgba(30, 42, 62, 0.3)');
g.addColorStop(1, 'rgba(0, 0, 0, 0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(0, 0, rx, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
};
// ─── 体积光柱 ────────────────────────────────────────────────
// ─── 远景:数据中心天际线(弱视差 + 微亮窗灯) ─────────────────
class Skyline {
constructor(rand, fhMul = 1) {
this.buildings = [];
let fx = -0.02;
while (fx < 1.04) {
const fw = 0.012 + rand() * 0.03;
this.buildings.push({
fx,
fw,
fh: (0.022 + rand() * 0.07) * fhMul,
windows: Array.from({ length: 2 + Math.floor(rand() * 4) }, () => ({
wx: 0.15 + rand() * 0.7,
wy: 0.12 + rand() * 0.72,
warm: rand() < 0.6,
phase: rand() * Math.PI * 2,
})),
});
fx += fw + 0.004 + rand() * 0.014;
}
}
draw(ctx, width, height, ox, now, isDark, alphaMul = 1) {
const gy = height * GROUND;
// 大气透视:远景低对比,贴着地平线一层薄雾感
ctx.fillStyle = isDark
? `rgba(24, 37, 58, ${0.75 * alphaMul})`
: `rgba(152, 168, 190, ${0.4 * alphaMul})`;
for (const b of this.buildings) {
const bx = b.fx * width + ox;
const bw = Math.max(3, b.fw * width);
const bh = b.fh * height;
ctx.fillRect(bx, gy - bh, bw, bh);
}
// 窗灯(时间驱动缓慢明灭,远景不需要逐帧状态)
for (const b of this.buildings) {
const bx = b.fx * width + ox;
const bw = Math.max(3, b.fw * width);
const bh = b.fh * height;
for (const w of b.windows) {
const tw = 0.5 + Math.sin(now * 0.0006 + w.phase) * 0.5;
if (tw < 0.45) continue;
ctx.fillStyle = rgba(
w.warm ? C.amber : C.cyan,
tw * (isDark ? 0.4 : 0.3) * alphaMul,
);
ctx.fillRect(bx + w.wx * bw, gy - bh + w.wy * bh, 1.2, 1.6);
}
}
}
}
// ─── 第一幕:风力发电机(白色实体 + 细节线条 + 航空灯) ────────
class WindTurbine {
constructor(fx, scale, speed, rot) {
this.fx = fx;
this.scale = scale;
this.speed = speed;
this.rot = rot;
// 航空灯相位全场统一为 0:真实风电场按规范同步闪烁
this.beacon = 0;
}
update(on, dt) {
if (!on) return;
this.rot += this.speed * dt;
this.beacon += 0.045 * dt;
}
draw(ctx, width, height, ox, isDark) {
const s = this.scale;
const x = this.fx * width + ox;
const groundY = height * GROUND;
const towerH = height * 0.26 * s;
const hubY = groundY - towerH;
contactShadow(ctx, x, groundY, towerH * 0.3, isDark);
// 塔筒:下宽上窄锥形,横向渐变模拟圆柱受光
const tw0 = 1.3 * s;
const tw1 = 3.6 * s;
ctx.fillStyle = cylGrad(
ctx,
x - tw1,
x + tw1,
isDark ? 'rgba(96, 108, 128, 0.92)' : 'rgba(178, 188, 202, 0.96)',
isDark ? 'rgba(190, 202, 220, 0.92)' : 'rgba(248, 250, 253, 0.98)',
);
ctx.beginPath();
ctx.moveTo(x - tw1, groundY);
ctx.lineTo(x - tw0, hubY);
ctx.lineTo(x + tw0, hubY);
ctx.lineTo(x + tw1, groundY);
ctx.closePath();
ctx.fill();
// 塔筒法兰拼接线(分段钢筒的横缝)
ctx.strokeStyle = isDark
? 'rgba(30, 40, 56, 0.5)'
: 'rgba(120, 132, 150, 0.45)';
ctx.lineWidth = 0.6;
for (const t of [0.35, 0.68]) {
const fy = groundY - towerH * t;
const fw = lerp(tw1, tw0, t);
ctx.beginPath();
ctx.moveTo(x - fw, fy);
ctx.lineTo(x + fw, fy);
ctx.stroke();
}
// 基座检修门
ctx.fillStyle = isDark
? 'rgba(40, 52, 70, 0.9)'
: 'rgba(130, 142, 158, 0.9)';
ctx.beginPath();
ctx.roundRect(x - 1.1 * s, groundY - 4.6 * s, 2.2 * s, 4.2 * s, 0.8 * s);
ctx.fill();
// 机舱
const nw = 7.5 * s;
const nh = 4.2 * s;
const ng = ctx.createLinearGradient(0, hubY - nh / 2, 0, hubY + nh / 2);
ng.addColorStop(
0,
isDark ? 'rgba(168, 182, 202, 0.94)' : 'rgba(236, 242, 248, 0.98)',
);
ng.addColorStop(
1,
isDark ? 'rgba(110, 124, 146, 0.94)' : 'rgba(190, 200, 214, 0.98)',
);
ctx.fillStyle = ng;
ctx.beginPath();
ctx.roundRect(x - nw / 2, hubY - nh / 2, nw, nh, 1.6 * s);
ctx.fill();
// 三叶片:锥形翼型实体(白)+ 红色叶尖警示条 —— 不再是剪影线条,
// 避免旋转时被误看成"触手"
const len = towerH * 0.46;
for (let i = 0; i < 3; i++) {
const a = this.rot + (i * Math.PI * 2) / 3;
ctx.save();
ctx.translate(x, hubY);
ctx.rotate(a);
const bg = ctx.createLinearGradient(0, 0, len, 0);
bg.addColorStop(
0,
isDark ? 'rgba(222, 230, 242, 0.94)' : 'rgba(255, 255, 255, 0.98)',
);
bg.addColorStop(
1,
isDark ? 'rgba(158, 172, 195, 0.76)' : 'rgba(214, 224, 236, 0.92)',
);
ctx.fillStyle = bg;
ctx.beginPath();
ctx.moveTo(0, -1.5 * s);
ctx.quadraticCurveTo(len * 0.42, -2.4 * s, len, -0.5 * s);
ctx.quadraticCurveTo(len * 0.45, 1.5 * s, 0, 1.5 * s);
ctx.closePath();
ctx.fill();
// 叶片背光缘(下缘细阴影线,翼型立体感)
ctx.strokeStyle = isDark
? 'rgba(70, 84, 106, 0.5)'
: 'rgba(150, 163, 180, 0.5)';
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(len * 0.05, 1.4 * s);
ctx.quadraticCurveTo(len * 0.45, 1.4 * s, len, -0.5 * s);
ctx.stroke();
// 叶尖红色警示条(真实风机涂装)
ctx.fillStyle = rgba(C.red, 0.8);
ctx.fillRect(len * 0.78, -1.15 * s, len * 0.08, 2.15 * s);
ctx.restore();
}
// 轮毂(整流罩)
ctx.fillStyle = isDark
? 'rgba(232, 240, 248, 0.96)'
: 'rgba(255, 255, 255, 1)';
ctx.beginPath();
ctx.arc(x, hubY, 2 * s, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = isDark
? 'rgba(120, 134, 155, 0.6)'
: 'rgba(148, 163, 184, 0.7)';
ctx.lineWidth = 0.7;
ctx.stroke();
// 航空障碍灯(机舱顶,红色慢闪)
const blink = Math.max(0, Math.sin(this.beacon)) ** 6;
if (blink > 0.05) {
const by = hubY - nh / 2 - 1.6 * s;
const glow = ctx.createRadialGradient(x, by, 0, x, by, 5 * s);
glow.addColorStop(0, rgba(C.red, 0.5 * blink));
glow.addColorStop(1, rgba(C.red, 0));
ctx.fillStyle = glow;
ctx.beginPath();
ctx.arc(x, by, 5 * s, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = rgba(C.red, 0.9 * blink);
ctx.beginPath();
ctx.arc(x, by, 1.1 * s, 0, Math.PI * 2);
ctx.fill();
}
}
}
// ─── 第一幕:冷却塔(暖调混凝土双曲面 + 施工缝 + 蒸汽) ─────────
class CoolingTower {
constructor(fx, scale, rand) {
this.fx = fx;
this.scale = scale;
this.puffs = Array.from({ length: 6 }, () => ({
t: rand(),
drift: (rand() - 0.5) * 0.5,
speed: 0.0012 + rand() * 0.0016,
}));
}
update(on, dt) {
if (!on) return;
for (const p of this.puffs) {
p.t += p.speed * dt;
if (p.t > 1) p.t = 0;
}
}
draw(ctx, width, height, ox, isDark) {
const x = this.fx * width + ox;
const groundY = height * GROUND;
const h = height * 0.2 * this.scale;
const topY = groundY - h;
const topW = 24 * this.scale;
const waistW = 30 * this.scale;
const botW = 46 * this.scale;
contactShadow(ctx, x, groundY, botW * 0.75, isDark);
const towerPath = () => {
ctx.beginPath();
ctx.moveTo(x - botW / 2, groundY);
ctx.bezierCurveTo(
x - waistW / 2,
groundY - h * 0.45,
x - waistW / 2,
groundY - h * 0.62,
x - topW / 2,
topY,
);
ctx.lineTo(x + topW / 2, topY);
ctx.bezierCurveTo(
x + waistW / 2,
groundY - h * 0.62,
x + waistW / 2,
groundY - h * 0.45,
x + botW / 2,
groundY,
);
ctx.closePath();
};
// 混凝土塔身:暖灰调(真实冷却塔是素混凝土色),横向渐变给体积感
ctx.fillStyle = cylGrad(
ctx,
x - botW / 2,
x + botW / 2,
isDark ? 'rgba(62, 64, 74, 0.95)' : 'rgba(172, 168, 158, 0.95)',
isDark ? 'rgba(140, 140, 146, 0.95)' : 'rgba(235, 231, 222, 0.98)',
);
towerPath();
ctx.fill();
ctx.save();
towerPath();
ctx.clip();
// 环向施工缝(混凝土滑模的水平接缝,随塔身宽度收放)
ctx.strokeStyle = isDark
? 'rgba(20, 22, 30, 0.28)'
: 'rgba(120, 115, 105, 0.22)';
ctx.lineWidth = 0.6;
for (const t of [0.22, 0.42, 0.6, 0.78]) {
const ry = groundY - h * t;
const rw = lerp(botW * 0.92, topW, t ** 0.8);
ctx.beginPath();
ctx.ellipse(x, ry, rw / 2, 1.3, 0, 0, Math.PI * 2);
ctx.stroke();
}
// 竖向施工接缝(极淡)
for (const f of [-0.3, 0.3]) {
ctx.beginPath();
ctx.moveTo(x + topW * f, topY + 2);
ctx.lineTo(x + botW * f * 0.9, groundY);
ctx.stroke();
}
// 顶缘航空警示带(红)
ctx.fillStyle = rgba(C.red, isDark ? 0.38 : 0.52);
ctx.fillRect(x - waistW / 2, topY + 1.5, waistW, 3 * this.scale);
ctx.restore();
// 风筒口(顶部椭圆环 + 内腔暗面)
ctx.fillStyle = isDark ? 'rgba(14, 16, 24, 0.8)' : 'rgba(96, 94, 88, 0.6)';
ctx.beginPath();
ctx.ellipse(x, topY, topW / 2 - 1, 1.6 * this.scale, 0, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = isDark
? 'rgba(205, 214, 228, 0.42)'
: 'rgba(250, 248, 244, 0.85)';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.ellipse(x, topY, topW / 2, 2 * this.scale, 0, 0, Math.PI * 2);
ctx.stroke();
// 蒸汽(升腾、扩散、消隐,双层圆增强蓬松感)
for (const p of this.puffs) {
const py = topY - p.t * h * 0.9;
const px = x + p.drift * p.t * 90;
const r = (5 + p.t * 20) * this.scale;
const a = Math.sin(Math.PI * p.t) * (isDark ? 0.11 : 0.2);
for (const [dx, dy, fr] of [
[0, 0, 1],
[r * 0.4, -r * 0.25, 0.65],
]) {
const g = ctx.createRadialGradient(
px + dx,
py + dy,
0,
px + dx,
py + dy,
r * fr,
);
g.addColorStop(0, `rgba(240, 244, 250, ${a})`);
g.addColorStop(1, 'rgba(240, 244, 250, 0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(px + dx, py + dy, r * fr, 0, Math.PI * 2);
ctx.fill();
}
}
}
}
// ─── 第一幕:光伏阵列(近黑深蓝电池板 + 栅线 + 掠光) ───────────
class SolarArray {
constructor(fx, fw) {
this.fx = fx;
this.fw = fw;
this.glint = 0; // 0~1 扫过,>1 休止
}
update(on, dt) {
if (!on) return;
this.glint += 0.0035 * dt;
if (this.glint > 2.6) this.glint = 0;
}
draw(ctx, width, height, ox, isDark) {
const x0 = this.fx * width + ox;
const w = this.fw * width;
const groundY = height * GROUND - 2;
const rows = 2;
const cols = 4;
const pw = w / cols;
const ph = 9;
for (let r = 0; r < rows; r++) {
const py = groundY - 12 - r * 15;
// 支撑横梁 + 立柱
ctx.strokeStyle = isDark
? 'rgba(96, 106, 122, 0.6)'
: 'rgba(128, 138, 152, 0.65)';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(x0 + 2, py + ph + 2);
ctx.lineTo(x0 + w - 4, py + ph + 2);
for (let c = 0; c <= cols; c += 2) {
const lx = x0 + Math.min(c * pw + 2, w - 5);
ctx.moveTo(lx, py + ph + 2);
ctx.lineTo(lx, groundY + 2);
}
ctx.stroke();
for (let c = 0; c < cols; c++) {
const px = x0 + c * pw;
// 电池板:近黑深蓝(真实单晶硅板),顶缘微弱天光反射
const pg = ctx.createLinearGradient(0, py, 0, py + ph);
if (isDark) {
pg.addColorStop(0, 'rgba(28, 52, 96, 0.92)');
pg.addColorStop(0.25, 'rgba(13, 27, 56, 0.94)');
pg.addColorStop(1, 'rgba(7, 15, 34, 0.95)');
} else {
pg.addColorStop(0, 'rgba(46, 76, 132, 0.95)');
pg.addColorStop(0.25, 'rgba(20, 40, 82, 0.95)');
pg.addColorStop(1, 'rgba(10, 22, 48, 0.95)');
}
ctx.fillStyle = pg;
ctx.beginPath();
ctx.moveTo(px + 3, py);
ctx.lineTo(px + pw - 3, py);
ctx.lineTo(px + pw - 6, py + ph);
ctx.lineTo(px, py + ph);
ctx.closePath();
ctx.fill();
// 电池片栅线(白色细线,真实光伏板纹理)
ctx.strokeStyle = 'rgba(210, 226, 250, 0.2)';
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(px + 1.5, py + ph / 2);
ctx.lineTo(px + pw - 4.5, py + ph / 2);
for (let v = 1; v < 3; v++) {
const fx1 = px + 3 + (v * (pw - 6)) / 3;
ctx.moveTo(fx1, py);
ctx.lineTo(fx1 - 2, py + ph);
}
ctx.stroke();
// 银色铝边框
ctx.strokeStyle = isDark
? 'rgba(198, 210, 226, 0.45)'
: 'rgba(236, 241, 248, 0.9)';
ctx.lineWidth = 0.8;
ctx.beginPath();
ctx.moveTo(px + 3, py);
ctx.lineTo(px + pw - 3, py);
ctx.lineTo(px + pw - 6, py + ph);
ctx.lineTo(px, py + ph);
ctx.closePath();
ctx.stroke();
}
}
// 掠光:一道高光带周期性扫过面板区
if (this.glint <= 1) {
const gx = x0 + this.glint * w;
const a = Math.sin(Math.PI * this.glint) * (isDark ? 0.16 : 0.24);
const g = ctx.createLinearGradient(gx - 26, 0, gx + 26, 0);
g.addColorStop(0, 'rgba(255, 255, 255, 0)');
g.addColorStop(0.5, `rgba(255, 255, 255, ${a})`);
g.addColorStop(1, 'rgba(255, 255, 255, 0)');
ctx.fillStyle = g;
ctx.fillRect(x0, groundY - 12 - 15 - ph, w, 15 + ph + 12);
}
}
}
// ─── 贯穿:流线(能量线 / 数据线共用,脉冲沿 Bezier 移动) ──────
class FlowLine {
constructor(a, b, bend, rand) {
this.a = a; // {fx, fy}
this.b = b;
this.bend = bend; // 弯曲程度(高度比例,负值向上拱)
this.pulses = [];
this.nextSpawn = 0;
this.spawnBase = 900 + rand() * 900;
}
geometry(width, height) {
const ax = this.a.fx * width;
const ay = this.a.fy * height;
const bx = this.b.fx * width;
const by = this.b.fy * height;
const midY = Math.min(ay, by) + this.bend * height;
return {
ax,
ay,
bx,
by,
c1x: lerp(ax, bx, 0.35),
c1y: midY,
c2x: lerp(ax, bx, 0.7),
c2y: midY,
};
}
update(now, flowOn, dt) {
if (flowOn && now >= this.nextSpawn) {
if (this.pulses.length < 3) {
this.pulses.push({
t: 0,
speed: 0.0035 + (this.spawnBase % 97) / 40000,
});
}
this.nextSpawn = now + this.spawnBase;
}
for (const p of this.pulses) p.t += p.speed * dt;
this.pulses = this.pulses.filter((p) => p.t < 1);
}
draw(ctx, width, height, ox, oy, color, isDark) {
const g = this.geometry(width, height);
const pt = (t) => ({
x: bezierPoint(g.ax, g.c1x, g.c2x, g.bx, t) + ox,
y: bezierPoint(g.ay, g.c1y, g.c2y, g.by, t) + oy,
});
// 基线(常显暗线)
ctx.strokeStyle = rgba(color, isDark ? 0.14 : 0.18);
ctx.lineWidth = 1;
ctx.beginPath();
const p0 = pt(0);
ctx.moveTo(p0.x, p0.y);
for (let i = 1; i <= 20; i++) {
const p = pt(i / 20);
ctx.lineTo(p.x, p.y);
}
ctx.stroke();
// 脉冲:亮头 + 渐隐尾
for (const pulse of this.pulses) {
const env = Math.sin(Math.PI * pulse.t);
for (let k = 0; k < 4; k++) {
const tt = pulse.t - k * 0.02;
if (tt < 0) break;
const p = pt(tt);
ctx.fillStyle = rgba(color, (isDark ? 0.6 : 0.5) * (1 - k / 4) * env);
ctx.beginPath();
ctx.arc(p.x, p.y, 2.2 - k * 0.4, 0, Math.PI * 2);
ctx.fill();
}
const head = pt(pulse.t);
const glow = ctx.createRadialGradient(
head.x,
head.y,
0,
head.x,
head.y,
7,
);
glow.addColorStop(0, rgba(color, 0.55 * env));
glow.addColorStop(1, rgba(color, 0));
ctx.fillStyle = glow;
ctx.beginPath();
ctx.arc(head.x, head.y, 7, 0, Math.PI * 2);
ctx.fill();
}
}
}
// ─── 第二幕:服务器机柜(哑光黑柜体 + 分层单元 + 彩色状态灯) ───
class Rack {
constructor(fx, scale, rand) {
this.fx = fx;
this.scale = scale;
this.actPhase = rand() * Math.PI * 2;
this.leds = [];
for (let u = 0; u < 5; u++) {
for (let c = 0; c < 3; c++) {
const color = pickLedColor(rand());
this.leds.push({
u,
c,
color,
phase: rand() * Math.PI * 2,
// 红色告警灯慢闪,其余快速呼吸
speed: color === C.red ? 0.012 + rand() * 0.01 : 0.02 + rand() * 0.05,
});
}
}
}
update(on, dt) {
if (!on) return;
this.actPhase += 0.03 * dt;
for (const led of this.leds) led.phase += led.speed * dt;
}
draw(ctx, width, height, ox, oy, isDark) {
const s = this.scale;
const w = 44 * s;
const h = height * 0.15 * s;
const x = this.fx * width + ox - w / 2;
const groundY = height * GROUND;
const y = groundY - h + oy;
contactShadow(ctx, x + w / 2, groundY + oy, w * 0.85, isDark);
// 柜体:哑光黑金属(真实机柜色),横向渐变(左受光)
const bg = ctx.createLinearGradient(x, 0, x + w, 0);
if (isDark) {
bg.addColorStop(0, 'rgba(44, 50, 62, 0.97)');
bg.addColorStop(0.5, 'rgba(24, 28, 37, 0.97)');
bg.addColorStop(1, 'rgba(13, 16, 22, 0.97)');
} else {
bg.addColorStop(0, 'rgba(96, 104, 116, 0.96)');
bg.addColorStop(0.5, 'rgba(62, 69, 80, 0.96)');
bg.addColorStop(1, 'rgba(42, 48, 58, 0.96)');
}
ctx.fillStyle = bg;
ctx.strokeStyle = isDark
? 'rgba(96, 112, 136, 0.5)'
: 'rgba(140, 152, 168, 0.7)';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.roundRect(x, y, w, h, 3);
ctx.fill();
ctx.stroke();
// 左缘受光高光 + 顶面窄反光(金属质感)
ctx.strokeStyle = isDark
? 'rgba(215, 228, 246, 0.16)'
: 'rgba(255, 255, 255, 0.5)';
ctx.beginPath();
ctx.moveTo(x + 1, y + 3);
ctx.lineTo(x + 1, y + h - 3);
ctx.stroke();
ctx.fillStyle = isDark
? 'rgba(160, 180, 205, 0.18)'
: 'rgba(255, 255, 255, 0.45)';
ctx.fillRect(x + 2, y + 0.8, w - 4, 1);
// 顶部排风口(三个小格栅)
ctx.fillStyle = isDark ? 'rgba(6, 8, 12, 0.9)' : 'rgba(28, 32, 40, 0.85)';
for (let v = 0; v < 3; v++) {
ctx.fillRect(x + 5 + v * ((w - 12) / 3), y + 2.6, (w - 16) / 3, 1.4);
}
// 5 个服务器单元
const uh = (h - 6) / 5;
for (let i = 0; i < 5; i++) {
const uy = y + 5 + i * uh;
// 面板(比柜体略浅一档)
ctx.fillStyle = isDark
? 'rgba(38, 45, 58, 0.94)'
: 'rgba(78, 86, 98, 0.94)';
ctx.beginPath();
ctx.roundRect(x + 2.5, uy, w - 5, uh - 2.5, 1.5);
ctx.fill();
// 面板上缘细高光(单元层次)
ctx.strokeStyle = isDark
? 'rgba(190, 206, 228, 0.1)'
: 'rgba(220, 228, 238, 0.35)';
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(x + 3.5, uy + 0.5);
ctx.lineTo(x + w - 3.5, uy + 0.5);
ctx.stroke();
// 通风槽(右半 3 条)
ctx.strokeStyle = isDark
? 'rgba(5, 7, 11, 0.85)'
: 'rgba(30, 34, 42, 0.7)';
ctx.lineWidth = 1;
for (let v = 0; v < 3; v++) {
const vy = uy + 1.5 + ((v + 1) * (uh - 5)) / 4;
ctx.beginPath();
ctx.moveTo(x + w * 0.48, vy);
ctx.lineTo(x + w - 6, vy);
ctx.stroke();
}
// 抽拉拉手(右缘竖线)
ctx.strokeStyle = isDark
? 'rgba(170, 188, 212, 0.28)'
: 'rgba(210, 220, 232, 0.5)';
ctx.lineWidth = 0.8;
ctx.beginPath();
ctx.moveTo(x + w - 3.6, uy + uh * 0.24);
ctx.lineTo(x + w - 3.6, uy + uh * 0.72);
ctx.stroke();
// 活动条(青色,负载起伏)
const load =
0.35 + (Math.sin(this.actPhase + i * 1.9) * 0.5 + 0.5) * 0.65;
ctx.fillStyle = rgba(C.cyan, isDark ? 0.65 : 0.8);
ctx.fillRect(x + 5, uy + uh - 4.2, w * 0.22 * load, 1.4);
}
// 状态灯(每单元左上 3 颗,彩色)
for (const led of this.leds) {
const b = 0.5 + Math.sin(led.phase) * 0.5;
if (b < 0.25) continue;
const lx = x + 5 + led.c * 4.6 * s;
const ly = y + 6.5 + led.u * uh;
const a = b * (isDark ? 0.95 : 0.9);
// 微光晕
ctx.fillStyle = rgba(led.color, a * 0.28);
ctx.fillRect(lx - 1, ly - 1, 4 * s, 4 * s);
ctx.fillStyle = rgba(led.color, a);
ctx.fillRect(lx, ly, 2 * s, 2 * s);
}
}
}
// ─── 第三幕:AI 应用屏(每屏专属彩色内容) ───────────────────
const SCREEN_ACCENT = {
ecg: C.green,
radar: C.orange,
city: C.sky,
chart: C.violet,
};
class Screen {
constructor(fx, fy, type, tilt, depth, phase) {
this.fx = fx;
this.fy = fy;
this.type = type; // 'ecg' | 'radar' | 'city' | 'chart'
this.tilt = tilt;
this.depth = depth; // 视差深度
this.phase = phase;
// city 型:预生成楼宇高度与窗灯(构造期一次)
this.bars = [0.55, 0.85, 0.4, 1.0, 0.65, 0.78];
}
update(on, dt) {
if (on) this.phase += 0.016 * dt;
}
draw(ctx, width, height, ox, oy, isDark, scale) {
const accent = SCREEN_ACCENT[this.type];
const w = 118 * scale * (0.8 + this.depth * 0.3);
const h = 76 * scale * (0.8 + this.depth * 0.3);
const x = this.fx * width + ox * this.depth;
// 全息屏悬浮感:轻微上下浮动 + 微倾摆(纹丝不动的"悬浮"最出戏)
const bob = Math.sin(this.phase * 0.55) * 2.6;
const y = this.fy * height + oy * this.depth + bob;
const flicker = 0.92 + Math.sin(this.phase * 5.7) * 0.08;
ctx.save();
ctx.translate(x, y);
ctx.rotate(this.tilt + Math.sin(this.phase * 0.33) * 0.008);
ctx.globalAlpha = flicker;
// 屏体(暗玻璃 / 浅磨砂),边框按看板类型着色
ctx.fillStyle = isDark
? 'rgba(7, 15, 30, 0.82)'
: 'rgba(252, 254, 255, 0.62)';
ctx.strokeStyle = rgba(accent, isDark ? 0.65 : 0.55);
ctx.lineWidth = 1.2;
ctx.beginPath();
ctx.roundRect(-w / 2, -h / 2, w, h, 6);
ctx.fill();
ctx.stroke();
// 屏面斜向反光(玻璃质感)
const sheen = ctx.createLinearGradient(-w / 2, -h / 2, w / 2, h / 2);
sheen.addColorStop(0, 'rgba(255, 255, 255, 0.07)');
sheen.addColorStop(0.35, 'rgba(255, 255, 255, 0)');
ctx.fillStyle = sheen;
ctx.beginPath();
ctx.roundRect(-w / 2, -h / 2, w, h, 6);
ctx.fill();
// 屏体辉光(同色)
const glow = ctx.createRadialGradient(0, 0, 0, 0, 0, w * 0.85);
glow.addColorStop(0, rgba(accent, isDark ? 0.1 : 0.06));
glow.addColorStop(1, rgba(accent, 0));
ctx.fillStyle = glow;
ctx.fillRect(-w, -h, w * 2, h * 2);
// 标题条 + 红黄绿状态点(小看板质感)
ctx.fillStyle = rgba(accent, isDark ? 0.5 : 0.45);
ctx.fillRect(-w / 2 + 6, -h / 2 + 6, w * 0.4, 3);
const dots = [C.green, C.amber, C.red];
for (let i = 0; i < 3; i++) {
ctx.fillStyle = rgba(dots[i], 0.85);
ctx.beginPath();
ctx.arc(w / 2 - 8 - i * 6.5, -h / 2 + 7.5, 1.6, 0, Math.PI * 2);
ctx.fill();
}
// 内容区
const cx = -w / 2 + 8;
const cy = -h / 2 + 16;
const cw = w - 16;
const ch = h - 24;
if (this.type === 'ecg') this.drawEcg(ctx, cx, cy, cw, ch, isDark);
else if (this.type === 'radar') this.drawRadar(ctx, cw, ch);
else if (this.type === 'city') this.drawCity(ctx, cx, cy, cw, ch, isDark);
else this.drawChart(ctx, cx, cy, cw, ch);
ctx.restore();
}
// 医疗:绿色心电波形 + 红十字 + 心率数字
drawEcg(ctx, cx, cy, cw, ch, isDark) {
const mid = cy + ch * 0.55;
// 监护仪分格网(医疗屏辨识度)
ctx.strokeStyle = rgba(C.green, 0.12);
ctx.lineWidth = 0.5;
ctx.beginPath();
for (let gx = 1; gx < 6; gx++) {
ctx.moveTo(cx + (gx * cw) / 6, cy + 2);
ctx.lineTo(cx + (gx * cw) / 6, cy + ch - 2);
}
for (let gy = 1; gy < 4; gy++) {
ctx.moveTo(cx + 1, cy + (gy * ch) / 4);
ctx.lineTo(cx + cw - 1, cy + (gy * ch) / 4);
}
ctx.stroke();
ctx.strokeStyle = rgba(C.green, 0.9);
ctx.lineWidth = 1.4;
ctx.lineJoin = 'round';
ctx.beginPath();
const N = 40;
for (let i = 0; i <= N; i++) {
const u = i / N;
const t = (u + this.phase * 0.12) % 1;
let v = Math.sin(t * Math.PI * 6) * 0.04; // 基线小波
if (t > 0.42 && t < 0.47)
v = -(t - 0.42) * 9; // 下探
else if (t >= 0.47 && t < 0.52)
v = (t - 0.47) * 22 - 0.45; // 主峰
else if (t >= 0.52 && t < 0.58) v = 0.65 - (t - 0.52) * 11.5; // 回落(0.58 处落回基线,避免波形折断)
const px = cx + u * cw;
const py = mid - v * ch * 0.55;
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
}
ctx.stroke();
// 红十字标识
ctx.fillStyle = rgba(C.red, 0.85);
ctx.fillRect(cx + 2, cy + 2.5, 6, 2);
ctx.fillRect(cx + 4, cy + 0.5, 2, 6);
// 心率数字(随相位缓变)
const bpm = 72 + Math.round(Math.sin(this.phase * 0.35) * 4);
ctx.fillStyle = isDark
? 'rgba(240, 248, 255, 0.85)'
: 'rgba(30, 41, 59, 0.8)';
ctx.font = '600 8px "JetBrains Mono", monospace';
ctx.textAlign = 'right';
ctx.textBaseline = 'alphabetic';
ctx.fillText(`${bpm}`, cx + cw - 2, cy + 8);
}
// 自动驾驶:绿色刻度环 + 橙色扫掠 + 红黄目标点
drawRadar(ctx, cw, ch) {
const r = Math.min(cw, ch) * 0.42;
ctx.strokeStyle = rgba(C.green, 0.4);
ctx.lineWidth = 0.8;
for (let i = 1; i <= 2; i++) {
ctx.beginPath();
ctx.arc(0, 4, (r * i) / 2, 0, Math.PI * 2);
ctx.stroke();
}
const sweep = this.phase % (Math.PI * 2);
// 扫掠线 + 残影扇形(橙)
ctx.fillStyle = rgba(C.orange, 0.16);
ctx.beginPath();
ctx.moveTo(0, 4);
ctx.arc(0, 4, r, sweep - 0.7, sweep);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = rgba(C.orange, 0.9);
ctx.lineWidth = 1.2;
ctx.beginPath();
ctx.moveTo(0, 4);
ctx.lineTo(Math.cos(sweep) * r, 4 + Math.sin(sweep) * r);
ctx.stroke();
// 目标点(相位固定,被扫过后短暂亮起,红黄交替)
const blips = [
[0.5, 1.2],
[-0.4, 3.9],
[0.15, 5.3],
];
for (let i = 0; i < blips.length; i++) {
const [fr, ang] = blips[i];
let da = sweep - ang;
while (da < 0) da += Math.PI * 2;
const a = Math.max(0, 1 - da / 1.6);
if (a <= 0.02) continue;
ctx.fillStyle = rgba(i % 2 ? C.yellow : C.red, a);
ctx.beginPath();
ctx.arc(
Math.cos(ang) * r * (0.5 + fr * 0.4),
4 + Math.sin(ang) * r * (0.5 + fr * 0.4),
1.8,
0,
Math.PI * 2,
);
ctx.fill();
}
}
// 智慧城市:蓝色楼宇 + 暖黄窗灯 + 天线红灯
drawCity(ctx, cx, cy, cw, ch, isDark) {
const base = cy + ch;
const bw = cw / this.bars.length;
let tallIdx = 0;
for (let i = 0; i < this.bars.length; i++) {
if (this.bars[i] > this.bars[tallIdx]) tallIdx = i;
const bh = this.bars[i] * ch * 0.85;
const bx = cx + i * bw;
ctx.fillStyle = rgba(C.sky, isDark ? 0.34 : 0.42);
ctx.fillRect(bx + 1, base - bh, bw - 3, bh);
// 窗灯:暖黄,按相位错峰闪
for (let wy = 0; wy < Math.floor(bh / 7); wy++) {
const tw = 0.5 + Math.sin(this.phase * 1.7 + i * 2.1 + wy * 1.3) * 0.5;
if (tw < 0.55) continue;
ctx.fillStyle = rgba(C.amber, tw * 0.85);
ctx.fillRect(bx + bw * 0.3, base - bh + 3 + wy * 7, 2, 2);
}
}
// 地基线
ctx.strokeStyle = rgba(C.sky, 0.5);
ctx.lineWidth = 0.7;
ctx.beginPath();
ctx.moveTo(cx, base + 0.5);
ctx.lineTo(cx + cw, base + 0.5);
ctx.stroke();
// 最高楼天线 + 红色警示灯
const tx = cx + tallIdx * bw + bw / 2 - 0.5;
const ty = base - this.bars[tallIdx] * ch * 0.85;
ctx.strokeStyle = rgba(C.sky, 0.6);
ctx.lineWidth = 0.8;
ctx.beginPath();
ctx.moveTo(tx, ty);
ctx.lineTo(tx, ty - 6);
ctx.stroke();
const blink = Math.sin(this.phase * 2.2) > 0.4 ? 0.9 : 0.15;
ctx.fillStyle = rgba(C.red, blink);
ctx.beginPath();
ctx.arc(tx, ty - 7, 1.2, 0, Math.PI * 2);
ctx.fill();
}
// 金融:红绿蜡烛(K线)+ 金色趋势线
drawChart(ctx, cx, cy, cw, ch) {
const base = cy + ch;
const n = 7;
const bw = cw / n;
// 坐标轴(左 + 底,金融终端质感)
ctx.strokeStyle = 'rgba(148, 163, 184, 0.35)';
ctx.lineWidth = 0.6;
ctx.beginPath();
ctx.moveTo(cx + 1, cy);
ctx.lineTo(cx + 1, base);
ctx.lineTo(cx + cw, base);
ctx.stroke();
for (let i = 0; i < n; i++) {
const t = this.phase * 0.9 + i * 1.7;
const v1 = 0.25 + 0.4 * (0.5 + Math.sin(t) * 0.5) + i * 0.03;
const v2 = v1 + 0.12 + 0.08 * (0.5 + Math.sin(t * 1.3) * 0.5);
const col = Math.sin(t * 0.7 + i) > 0 ? C.green : C.red;
const yLo = base - v1 * ch * 0.7;
const yHi = base - v2 * ch * 0.7;
const xm = cx + i * bw + bw / 2;
// 影线
ctx.strokeStyle = rgba(col, 0.75);
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(xm, yHi - 3);
ctx.lineTo(xm, yLo + 3);
ctx.stroke();
// 实体
ctx.fillStyle = rgba(col, 0.85);
ctx.fillRect(xm - (bw - 5) / 2, yHi, bw - 5, Math.max(2, yLo - yHi));
}
// 金色趋势线
ctx.strokeStyle = rgba(C.yellow, 0.9);
ctx.lineWidth = 1.3;
ctx.beginPath();
for (let i = 0; i < n; i++) {
const v =
0.42 +
0.3 * (0.5 + Math.sin(this.phase * 0.9 + i * 1.7 + 1) * 0.5) +
i * 0.05;
const px = cx + i * bw + bw / 2;
const py = base - v * ch * 0.8;
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
}
ctx.stroke();
}
}
// ─── 贯穿:Token 芯片(金色,对象池,自机房升腾右漂) ───────────
class Token {
constructor() {
this.alive = false;
}
spawn(width, height, rand) {
this.alive = true;
this.x = width * (0.38 + rand() * 0.24);
this.y = height * (GROUND - 0.06) - rand() * 20;
this.vy = -(0.25 + rand() * 0.3);
this.drift = 0.06 + rand() * 0.14; // 微微右漂:算力流向应用
this.swayPhase = rand() * Math.PI * 2;
this.depth = 0.55 + rand() * 0.65;
this.glyph = GLYPHS[Math.floor(rand() * GLYPHS.length)];
this.life = 0;
this.topY = height * (0.08 + rand() * 0.12);
this.fadeSpan = height * 0.28;
}
update(width, dt) {
if (!this.alive) return;
this.life += dt;
this.swayPhase += 0.014 * dt;
this.x += (this.drift + Math.sin(this.swayPhase) * 0.12) * dt;
this.y += this.vy * this.depth * dt;
// 升顶或右漂出画布都要回收,否则离屏 token 白占池位
if (this.y < this.topY - 30 || this.x > width + 60) this.alive = false;
}
draw(ctx, ox, oy, isDark) {
if (!this.alive) return;
const fadeIn = clamp01(this.life / 50);
const fadeOut = clamp01((this.y - this.topY) / this.fadeSpan);
const alpha = fadeIn * fadeOut * (0.35 + this.depth * 0.5);
if (alpha <= 0.01) return;
ctx.save();
ctx.translate(this.x + ox * this.depth, this.y + oy * this.depth);
ctx.scale(this.depth, this.depth);
// 光粒凝结阶段:先是小亮点,40 帧后芯片渐显、光粒渐隐(交叉过渡)
const chipIn = clamp01((this.life - 40) / 30);
if (chipIn < 1) {
ctx.fillStyle = rgba(C.gold, fadeIn * 0.85 * (1 - chipIn));
ctx.beginPath();
ctx.arc(0, 0, 1.6 + fadeIn * 2, 0, Math.PI * 2);
ctx.fill();
if (chipIn <= 0) {
ctx.restore();
return;
}
}
ctx.globalAlpha = chipIn;
ctx.font = '500 11px "JetBrains Mono", Consolas, monospace';
const tw = ctx.measureText(this.glyph).width;
const w = tw + 14;
const h = 19;
const glow = ctx.createRadialGradient(0, 0, 0, 0, 0, w * 0.9);
glow.addColorStop(0, rgba(C.gold, alpha * (isDark ? 0.22 : 0.14)));
glow.addColorStop(1, rgba(C.gold, 0));
ctx.fillStyle = glow;
ctx.beginPath();
ctx.arc(0, 0, w * 0.9, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = isDark
? rgba(C.gold, alpha * 0.12)
: `rgba(255, 252, 240, ${alpha * 0.7})`;
ctx.strokeStyle = rgba(C.gold, alpha * (isDark ? 0.65 : 0.6));
ctx.lineWidth = 1;
ctx.beginPath();
ctx.roundRect(-w / 2, -h / 2, w, h, 5);
ctx.fill();
ctx.stroke();
ctx.fillStyle = isDark
? `rgba(255, 236, 190, ${alpha * 0.95})`
: `rgba(161, 106, 16, ${alpha * 0.95})`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(this.glyph, 0, 1);
ctx.restore();
}
}
// ─── 星尘 ────────────────────────────────────────────────────
class Dust {
constructor(width, height, rand) {
this.w = width;
this.h = height;
this.rand = rand;
this.reset(true);
}
reset(randomY = false) {
const rand = this.rand;
this.x = rand() * this.w;
this.y = randomY ? rand() * this.h : this.h + 8;
this.vy = -(0.04 + rand() * 0.1);
this.vx = (rand() - 0.5) * 0.05;
this.size = 0.6 + rand() * 1.2;
this.alpha = 0.06 + rand() * 0.16;
this.twinkle = rand() * Math.PI * 2;
}
resize(w, h) {
this.w = w;
this.h = h;
}
update(dt) {
this.x += this.vx * dt;
this.y += this.vy * dt;
this.twinkle += 0.008 * dt;
if (this.y < -10 || this.x < -10 || this.x > this.w + 10) this.reset();
}
draw(ctx, ox, oy) {
const a = this.alpha * (0.6 + Math.sin(this.twinkle) * 0.4);
ctx.fillStyle = rgba(C.ice, a);
ctx.beginPath();
ctx.arc(this.x + ox, this.y + oy, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
// ─── 明暗模式读取 ────────────────────────────────────────────
const detectDark = () => {
if (document.documentElement.classList.contains('dark')) return true;
if (document.body && document.body.getAttribute('theme-mode') === 'dark')
return true;
// ThemeContext 在浅色模式会移除上面两个标记,此时必须先看用户显式选择,
// 否则"强制浅色 + 系统深色"会被 prefers-color-scheme 兜底误判成暗色
try {
const stored = localStorage.getItem('theme-mode');
if (stored === 'dark') return true;
if (stored === 'light') return false;
} catch {
// localStorage 不可用(隐私模式等)时继续走系统偏好
}
return (
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
);
};
// ─── 组件 ─────────────────────────────────────────────────
const TokenFactory = () => {
const canvasRef = useRef(null);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext('2d');
if (!ctx.roundRect) {
ctx.roundRect = function (x, y, w, h, r) {
this.moveTo(x + r, y);
this.arcTo(x + w, y, x + w, y + h, r);
this.arcTo(x + w, y + h, x, y + h, r);
this.arcTo(x, y + h, x, y, r);
this.arcTo(x, y, x + w, y, r);
this.closePath();
return this;
};
}
let frameId = 0;
let themeTickId = 0;
let width = window.innerWidth;
let height = window.innerHeight;
let dpr = Math.min(window.devicePixelRatio || 1, 1.5);
const isMobile =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
);
const reducedMotion =
window.matchMedia &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const animOn = !reducedMotion;
const rand = mulberry32((Math.random() * 0x7fffffff) | 0);
const COUNT = reducedMotion
? { tokens: 8, dust: 12, spawnMs: 1600, stars: 24 }
: isMobile
? { tokens: 14, dust: 18, spawnMs: 620, stars: 30 }
: { tokens: 24, dust: 30, spawnMs: 460, stars: 64 };
// 倒影是双倍绘制,移动端关闭保帧率
const REFLECT = !isMobile;
let isDark = detectDark();
themeTickId = setInterval(() => {
isDark = detectDark();
}, 500);
let mouseTargetX = 0;
let mouseTargetY = 0;
let mouseX = 0;
let mouseY = 0;
const onMouseMove = (e) => {
if (reducedMotion) return;
mouseTargetX = (e.clientX / width - 0.5) * 2;
mouseTargetY = (e.clientY / height - 0.5) * 2;
};
// 胶片颗粒:offscreen 噪声图,绘制时按时间平移(避免每帧重新生成)
const GRAIN = 96;
const noiseCanvas = document.createElement('canvas');
noiseCanvas.width = GRAIN;
noiseCanvas.height = GRAIN;
const nctx = noiseCanvas.getContext('2d');
const noiseData = nctx.createImageData(GRAIN, GRAIN);
for (let i = 0; i < noiseData.data.length; i += 4) {
const v = (rand() * 255) | 0;
noiseData.data[i] = v;
noiseData.data[i + 1] = v;
noiseData.data[i + 2] = v;
noiseData.data[i + 3] = 255;
}
nctx.putImageData(noiseData, 0, 0);
const grainPattern = ctx.createPattern(noiseCanvas, 'repeat');
// ── 场景搭建(全部按宽高比例定位,resize 无需重建) ──
const stars = Array.from({ length: COUNT.stars }, () => ({
fx: rand(),
fy: rand() * 0.55,
r: 0.4 + rand() * 0.9,
phase: rand() * Math.PI * 2,
speed: 0.5 + rand(),
}));
// 双层天际线:远层更矮更淡、视差更小,纵深翻倍
const skylineFar = new Skyline(rand, 0.55);
const skyline = new Skyline(rand);
const towers = isMobile
? [new CoolingTower(0.05, 0.85, rand)]
: [
new CoolingTower(0.045, 1.05, rand),
new CoolingTower(0.115, 0.85, rand),
];
const turbines = isMobile
? [new WindTurbine(0.14, 0.75, 0.012, rand() * 6)]
: [
new WindTurbine(0.185, 1.0, 0.011, rand() * 6),
new WindTurbine(0.245, 0.78, 0.015, rand() * 6),
];
const solar = new SolarArray(
isMobile ? 0.2 : 0.028,
isMobile ? 0.12 : 0.11,
);
const racks = isMobile
? [
new Rack(0.36, 0.7, rand),
new Rack(0.5, 0.8, rand),
new Rack(0.64, 0.7, rand),
]
: [
// 后排(小)
new Rack(0.425, 0.72, rand),
new Rack(0.495, 0.72, rand),
new Rack(0.565, 0.72, rand),
// 前排(大)
new Rack(0.39, 1.0, rand),
new Rack(0.46, 1.0, rand),
new Rack(0.53, 1.0, rand),
new Rack(0.6, 1.0, rand),
];
// 能量线:能源设施顶部 → 机架区(琥珀金 = 电力)
const energyLines = isMobile
? [
new FlowLine(
{ fx: 0.05, fy: 0.7 },
{ fx: 0.36, fy: 0.8 },
-0.06,
rand,
),
new FlowLine(
{ fx: 0.14, fy: 0.66 },
{ fx: 0.5, fy: 0.79 },
-0.05,
rand,
),
]
: [
new FlowLine(
{ fx: 0.045, fy: 0.66 },
{ fx: 0.39, fy: 0.8 },
-0.06,
rand,
),
new FlowLine(
{ fx: 0.115, fy: 0.7 },
{ fx: 0.46, fy: 0.79 },
-0.05,
rand,
),
new FlowLine(
{ fx: 0.185, fy: 0.61 },
{ fx: 0.53, fy: 0.79 },
-0.04,
rand,
),
new FlowLine(
{ fx: 0.08, fy: 0.84 },
{ fx: 0.42, fy: 0.83 },
-0.03,
rand,
),
];
// 数据线:机架区 → 应用屏(青色 = 数据)
const screens = isMobile
? [
new Screen(0.82, 0.22, 'ecg', 0.03, 0.9, rand() * 6),
new Screen(0.86, 0.44, 'chart', -0.02, 1.1, rand() * 6),
]
: [
new Screen(0.795, 0.28, 'ecg', 0.035, 0.85, rand() * 6),
new Screen(0.9, 0.2, 'radar', -0.03, 1.15, rand() * 6),
new Screen(0.845, 0.52, 'city', 0.02, 1.0, rand() * 6),
new Screen(0.945, 0.46, 'chart', -0.04, 1.25, rand() * 6),
];
const dataLines = isMobile
? [
new FlowLine(
{ fx: 0.64, fy: 0.76 },
{ fx: 0.84, fy: 0.35 },
-0.04,
rand,
),
]
: [
new FlowLine(
{ fx: 0.6, fy: 0.75 },
{ fx: 0.795, fy: 0.33 },
-0.05,
rand,
),
new FlowLine(
{ fx: 0.53, fy: 0.74 },
{ fx: 0.9, fy: 0.26 },
-0.1,
rand,
),
new FlowLine(
{ fx: 0.565, fy: 0.77 },
{ fx: 0.855, fy: 0.56 },
-0.03,
rand,
),
];
const tokenPool = Array.from({ length: COUNT.tokens }, () => new Token());
let nextTokenAt = 0;
const dust = Array.from(
{ length: COUNT.dust },
() => new Dust(width, height, rand),
);
// 浅色模式:漂浮云(三瓣软体积)
const clouds = Array.from({ length: 3 }, () => ({
fx: rand(),
fy: 0.1 + rand() * 0.22,
scale: 0.7 + rand() * 0.9,
speed: 0.00002 + rand() * 0.00004,
}));
// 贴地低雾(缓慢横漂,screen 叠加)
const fogWisps = Array.from({ length: isMobile ? 2 : 3 }, () => ({
fx: rand(),
fw: 0.12 + rand() * 0.12,
speed: 0.00005 + rand() * 0.00007,
phase: rand() * Math.PI * 2,
}));
// 流星(暗色模式偶发点睛)
let shootingStar = null;
let nextShootAt = 7000 + rand() * 9000;
const resize = () => {
width = window.innerWidth;
height = window.innerHeight;
// 跨 DPI 显示器拖动 / 浏览器缩放会改变 devicePixelRatio,需重读
dpr = Math.min(window.devicePixelRatio || 1, 1.5);
canvas.width = width * dpr;
canvas.height = height * dpr;
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
dust.forEach((d) => d.resize(width, height));
};
// ── 天空:夜空/晨光渐变 + 地平线氛围光 + 星空 + 月/日/云 ──
const drawSky = (now, dt) => {
const gy = height * GROUND;
const grad = ctx.createLinearGradient(0, 0, 0, gy);
if (isDark) {
grad.addColorStop(0, '#010409');
grad.addColorStop(0.55, '#041020');
grad.addColorStop(1, '#082030');
} else {
grad.addColorStop(0, '#e9f1fa');
grad.addColorStop(0.55, '#d9e6f4');
grad.addColorStop(1, '#cfdcec');
}
ctx.fillStyle = grad;
ctx.fillRect(0, 0, width, gy + 2);
// 地平线氛围光:暗色 = 数据中心的 teal 辉光;浅色 = 左侧晨光
ctx.save();
ctx.translate(width * (isDark ? 0.5 : 0.32), gy);
ctx.scale(1, 0.32);
const hg = ctx.createRadialGradient(0, 0, 0, 0, 0, width * 0.52);
hg.addColorStop(0, isDark ? rgba(C.teal, 0.16) : rgba(C.warm, 0.2));
hg.addColorStop(1, isDark ? rgba(C.teal, 0) : rgba(C.warm, 0));
ctx.fillStyle = hg;
ctx.beginPath();
ctx.arc(0, 0, width * 0.52, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
// 星空(仅暗色;时间驱动闪烁,无需逐帧状态)
if (isDark) {
for (const st of stars) {
const tw = 0.55 + Math.sin(now * 0.001 * st.speed + st.phase) * 0.45;
ctx.fillStyle = rgba(C.ice, 0.14 + tw * 0.3);
ctx.beginPath();
ctx.arc(st.fx * width, st.fy * height, st.r * tw, 0, Math.PI * 2);
ctx.fill();
}
// 月亮:冷白光晕 + 环形山暗斑(夜景需要一个主体光源)
const mx = width * 0.615;
const my = height * 0.13;
const halo = ctx.createRadialGradient(mx, my, 0, mx, my, 64);
halo.addColorStop(0, 'rgba(210, 228, 250, 0.16)');
halo.addColorStop(1, 'rgba(210, 228, 250, 0)');
ctx.fillStyle = halo;
ctx.beginPath();
ctx.arc(mx, my, 64, 0, Math.PI * 2);
ctx.fill();
const md = ctx.createRadialGradient(mx - 4, my - 4, 2, mx, my, 13);
md.addColorStop(0, 'rgba(234, 241, 250, 0.95)');
md.addColorStop(1, 'rgba(198, 212, 232, 0.88)');
ctx.fillStyle = md;
ctx.beginPath();
ctx.arc(mx, my, 13, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = 'rgba(152, 170, 196, 0.4)';
for (const [dx, dy, r] of [
[-4, -2, 2.6],
[3, 4, 1.8],
[5, -5, 1.4],
]) {
ctx.beginPath();
ctx.arc(mx + dx, my + dy, r, 0, Math.PI * 2);
ctx.fill();
}
} else {
// 晨阳(低角度,随后绘制的天际线会部分遮挡 → 前后纵深)
const sx = width * 0.3;
const sy = gy - height * 0.035;
const halo = ctx.createRadialGradient(sx, sy, 0, sx, sy, 110);
halo.addColorStop(0, rgba(C.warm, 0.4));
halo.addColorStop(1, rgba(C.warm, 0));
ctx.fillStyle = halo;
ctx.beginPath();
ctx.arc(sx, sy, 110, 0, Math.PI * 2);
ctx.fill();
const sd = ctx.createRadialGradient(sx, sy, 0, sx, sy, 20);
sd.addColorStop(0, 'rgba(255, 246, 218, 0.95)');
sd.addColorStop(0.7, 'rgba(255, 226, 170, 0.75)');
sd.addColorStop(1, 'rgba(255, 226, 170, 0)');
ctx.fillStyle = sd;
ctx.beginPath();
ctx.arc(sx, sy, 20, 0, Math.PI * 2);
ctx.fill();
// 漂浮云(极缓右移,三瓣软体积)
for (const cl of clouds) {
if (animOn) {
cl.fx += cl.speed * dt;
if (cl.fx > 1.25) cl.fx = -0.25;
}
const cx0 = cl.fx * width;
const cy0 = cl.fy * height;
const r0 = 44 * cl.scale;
for (const [lx, ly, lr] of [
[-r0 * 0.72, r0 * 0.16, r0 * 0.66],
[0, 0, r0],
[r0 * 0.74, r0 * 0.2, r0 * 0.6],
]) {
const cg = ctx.createRadialGradient(
cx0 + lx,
cy0 + ly,
0,
cx0 + lx,
cy0 + ly,
lr,
);
cg.addColorStop(0, 'rgba(255, 255, 255, 0.5)');
cg.addColorStop(1, 'rgba(255, 255, 255, 0)');
ctx.fillStyle = cg;
ctx.beginPath();
ctx.arc(cx0 + lx, cy0 + ly, lr, 0, Math.PI * 2);
ctx.fill();
}
}
}
};
// ── 流星(暗色偶发,划过上空后重新排期) ──
const updateShootingStar = (now, dt) => {
if (!isDark || !animOn) return;
if (!shootingStar) {
if (now >= nextShootAt) {
shootingStar = {
x: (0.12 + rand() * 0.55) * width,
y: (0.04 + rand() * 0.12) * height,
vx: (2.4 + rand() * 2.2) * (rand() < 0.4 ? -1 : 1),
vy: 1.0 + rand() * 0.9,
life: 0,
max: 42 + rand() * 22,
};
}
return;
}
const st = shootingStar;
st.life += dt;
st.x += st.vx * dt;
st.y += st.vy * dt;
if (st.life > st.max || st.x < -80 || st.x > width + 80) {
shootingStar = null;
nextShootAt = now + 9000 + rand() * 16000;
return;
}
const env = Math.sin(Math.PI * clamp01(st.life / st.max));
const tg = ctx.createLinearGradient(
st.x,
st.y,
st.x - st.vx * 17,
st.y - st.vy * 17,
);
tg.addColorStop(0, `rgba(235, 245, 255, ${0.8 * env})`);
tg.addColorStop(1, 'rgba(235, 245, 255, 0)');
ctx.strokeStyle = tg;
ctx.lineWidth = 1.2;
ctx.beginPath();
ctx.moveTo(st.x, st.y);
ctx.lineTo(st.x - st.vx * 17, st.y - st.vy * 17);
ctx.stroke();
ctx.fillStyle = `rgba(255, 255, 255, ${0.9 * env})`;
ctx.beginPath();
ctx.arc(st.x, st.y, 1.3, 0, Math.PI * 2);
ctx.fill();
};
// ── 贴地低雾(体积氛围,screen 叠加) ──
const drawGroundFog = (now, dt) => {
const gyF = height * GROUND;
ctx.save();
ctx.globalCompositeOperation = 'screen';
for (const f of fogWisps) {
if (animOn) {
f.fx += f.speed * dt;
if (f.fx > 1.2) f.fx = -0.2;
}
const a =
(isDark ? 0.05 : 0.07) *
(0.7 + Math.sin(now * 0.0003 + f.phase) * 0.3);
ctx.save();
ctx.translate(f.fx * width, gyF - 3);
ctx.scale(1, 0.16);
const g = ctx.createRadialGradient(0, 0, 0, 0, 0, f.fw * width);
g.addColorStop(0, `rgba(188, 214, 240, ${a})`);
g.addColorStop(1, 'rgba(188, 214, 240, 0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(0, 0, f.fw * width, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
ctx.restore();
};
// ── 地平线雾带(大气纵深) ──
const drawHorizonFog = () => {
const gy = height * GROUND;
const fog = ctx.createLinearGradient(0, gy - 40, 0, gy + 24);
const fa = isDark ? 0.09 : 0.16;
fog.addColorStop(0, 'rgba(150, 190, 230, 0)');
fog.addColorStop(0.62, `rgba(150, 190, 230, ${fa})`);
fog.addColorStop(1, 'rgba(150, 190, 230, 0)');
ctx.save();
ctx.globalCompositeOperation = 'screen';
ctx.fillStyle = fog;
ctx.fillRect(0, gy - 40, width, 64);
ctx.restore();
};
// ── 反光机房地板:基底 → (外部画倒影) → 渐隐 → 透视网格 → 辉光 ──
const drawFloorBase = () => {
const gy = height * GROUND;
const g = ctx.createLinearGradient(0, gy, 0, height);
if (isDark) {
g.addColorStop(0, '#07202e');
g.addColorStop(0.35, '#04121e');
g.addColorStop(1, '#010509');
} else {
g.addColorStop(0, '#c6d4e4');
g.addColorStop(0.4, '#b4c4d8');
g.addColorStop(1, '#9fb1c8');
}
ctx.fillStyle = g;
ctx.fillRect(0, gy, width, height - gy);
};
const drawFloorFinish = () => {
const gy = height * GROUND;
const fh = height - gy;
// 倒影随距离渐隐(向下沉入地板色)
const fade = ctx.createLinearGradient(0, gy, 0, height);
if (isDark) {
fade.addColorStop(0, 'rgba(2, 8, 14, 0)');
fade.addColorStop(0.55, 'rgba(2, 8, 14, 0.45)');
fade.addColorStop(1, 'rgba(1, 4, 8, 0.9)');
} else {
fade.addColorStop(0, 'rgba(178, 194, 214, 0)');
fade.addColorStop(0.55, 'rgba(172, 188, 208, 0.5)');
fade.addColorStop(1, 'rgba(159, 177, 200, 0.92)');
}
ctx.fillStyle = fade;
ctx.fillRect(0, gy, width, fh);
// 消失点透视网格(机房地砖)
const vpx = width * 0.5;
ctx.strokeStyle = rgba(C.cyan, isDark ? 0.08 : 0.1);
ctx.lineWidth = 1;
ctx.beginPath();
for (let i = -6; i <= 6; i++) {
ctx.moveTo(vpx, gy);
ctx.lineTo(vpx + i * width * 0.14, height + 2);
}
// 横向砖缝:靠近地平线越密(透视压缩)
for (const t of [0.1, 0.24, 0.45, 0.72]) {
const ly = gy + t * fh;
ctx.moveTo(0, ly);
ctx.lineTo(width, ly);
}
ctx.stroke();
// 地面辉光:中央青蓝(机房) + 左侧暖橙(能源)
ctx.save();
ctx.globalCompositeOperation = 'screen';
const g1 = ctx.createRadialGradient(
width * 0.5,
gy,
0,
width * 0.5,
gy,
width * 0.34,
);
g1.addColorStop(0, rgba(C.sky, isDark ? 0.12 : 0.1));
g1.addColorStop(1, rgba(C.sky, 0));
ctx.fillStyle = g1;
ctx.fillRect(0, gy, width, fh);
const g2 = ctx.createRadialGradient(
width * 0.12,
gy,
0,
width * 0.12,
gy,
width * 0.2,
);
g2.addColorStop(0, rgba(C.amber, isDark ? 0.08 : 0.07));
g2.addColorStop(1, rgba(C.amber, 0));
ctx.fillStyle = g2;
ctx.fillRect(0, gy, width * 0.4, fh);
ctx.restore();
// 地平线接缝细线
ctx.strokeStyle = rgba(C.sky, isDark ? 0.2 : 0.18);
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(0, gy);
ctx.lineTo(width, gy);
ctx.stroke();
};
// ── 地平线镜头光斑(anamorphic 水平光条) ──
const drawLensStreak = (now) => {
const gy = height * GROUND;
const breathe = animOn ? Math.sin(now * 0.0004) : 0;
const a = (isDark ? 0.1 : 0.06) * (0.65 + breathe * 0.35);
ctx.save();
ctx.globalCompositeOperation = 'screen';
const g = ctx.createLinearGradient(width * 0.16, 0, width * 0.84, 0);
g.addColorStop(0, 'rgba(140, 215, 255, 0)');
g.addColorStop(0.5, `rgba(160, 225, 255, ${a})`);
g.addColorStop(1, 'rgba(140, 215, 255, 0)');
ctx.fillStyle = g;
ctx.fillRect(width * 0.16, gy - 2.5, width * 0.68, 5);
// 中心亮核
const core = ctx.createRadialGradient(
width * 0.5,
gy,
0,
width * 0.5,
gy,
46,
);
core.addColorStop(0, `rgba(200, 240, 255, ${a * 1.6})`);
core.addColorStop(1, 'rgba(200, 240, 255, 0)');
ctx.fillStyle = core;
ctx.fillRect(width * 0.5 - 46, gy - 46, 92, 92);
ctx.restore();
};
// ── 好莱坞 teal-orange 调色(左暖右冷,screen 轻叠) ──
const drawColorGrade = () => {
ctx.save();
ctx.globalCompositeOperation = 'screen';
const g = ctx.createLinearGradient(0, 0, width, 0);
g.addColorStop(0, rgba(C.warm, isDark ? 0.055 : 0.05));
g.addColorStop(0.45, 'rgba(0, 0, 0, 0)');
g.addColorStop(1, rgba(C.teal, isDark ? 0.07 : 0.055));
ctx.fillStyle = g;
ctx.fillRect(0, 0, width, height);
ctx.restore();
};
const drawVignette = () => {
const cx = width / 2;
const cy = height * 0.42;
const vig = ctx.createRadialGradient(
cx,
cy,
Math.min(width, height) * 0.4,
cx,
cy,
Math.max(width, height) * 0.85,
);
vig.addColorStop(0, 'rgba(0, 0, 0, 0)');
vig.addColorStop(
1,
isDark ? 'rgba(0, 0, 0, 0.58)' : 'rgba(35, 52, 80, 0.17)',
);
ctx.fillStyle = vig;
ctx.fillRect(0, 0, width, height);
};
// ── 胶片颗粒(overlay 轻叠,时间平移) ──
const drawGrain = (now) => {
if (!grainPattern) return;
ctx.save();
ctx.globalCompositeOperation = 'overlay';
ctx.globalAlpha = isDark ? 0.05 : 0.035;
const jx = animOn ? (now * 0.61) % GRAIN : 0;
const jy = animOn ? (now * 0.83) % GRAIN : 0;
ctx.translate(-jx, -jy);
ctx.fillStyle = grainPattern;
ctx.fillRect(0, 0, width + GRAIN, height + GRAIN);
ctx.restore();
};
// ── 柔和 letterbox 黑边(电影画幅) ──
const drawLetterbox = () => {
const barH = height * 0.055;
const cc = isDark ? '0, 0, 0' : '10, 20, 34';
const aMax = isDark ? 0.82 : 0.45;
const top = ctx.createLinearGradient(0, 0, 0, barH);
top.addColorStop(0, `rgba(${cc}, ${aMax})`);
top.addColorStop(1, `rgba(${cc}, 0)`);
ctx.fillStyle = top;
ctx.fillRect(0, 0, width, barH);
const bot = ctx.createLinearGradient(0, height - barH, 0, height);
bot.addColorStop(0, `rgba(${cc}, 0)`);
bot.addColorStop(1, `rgba(${cc}, ${aMax})`);
ctx.fillStyle = bot;
ctx.fillRect(0, height - barH, width, barH);
};
let lastFrameAt = 0;
const animate = () => {
const now = performance.now();
// 帧率无关:60fps 基准时间步长。高刷屏(120/144Hz)速度一致;
// 后台恢复时钳位到 50ms,防止一帧大跳
const dt = lastFrameAt
? Math.min(Math.max(now - lastFrameAt, 0), 50) / 16.67
: 1;
lastFrameAt = now;
if (animOn) {
mouseX = lerp(mouseX, mouseTargetX, 0.035);
mouseY = lerp(mouseY, mouseTargetY, 0.035);
}
const pan = animOn ? Math.sin(now * 0.0001) * 12 : 0;
const gy = height * GROUND;
// 视觉时钟:星空/窗灯/低雾等"时间驱动"闪烁统一走它,
// reduced-motion 时冻结为 0 → 相位为常量,画面完全静止
const vnow = animOn ? now : 0;
// ── 更新(每帧一次;绘制有倒影双 pass,必须与更新分离) ──
towers.forEach((t) => t.update(animOn, dt));
turbines.forEach((t) => t.update(animOn, dt));
solar.update(animOn, dt);
racks.forEach((r) => r.update(animOn, dt));
energyLines.forEach((l) => l.update(now, animOn, dt));
dataLines.forEach((l) => l.update(now, animOn, dt));
screens.forEach((s) => s.update(animOn, dt));
const ox1 = pan * 0.6 + mouseX * 9;
const oxRack = pan * 0.8 + mouseX * 12;
const oyRack = mouseY * 7;
// ── 由远及近分层绘制 ──
drawSky(vnow, dt);
updateShootingStar(now, dt);
skylineFar.draw(
ctx,
width,
height,
pan * 0.15 + mouseX * 1.8,
vnow,
isDark,
0.55,
);
skyline.draw(ctx, width, height, pan * 0.25 + mouseX * 3, vnow, isDark);
drawFloorBase();
// 地板倒影:镜像重绘远景与地面实体,裁剪在地板区内
if (REFLECT) {
ctx.save();
ctx.beginPath();
ctx.rect(0, gy, width, height - gy);
ctx.clip();
ctx.translate(0, gy * 2);
ctx.scale(1, -1);
ctx.globalAlpha = isDark ? 0.24 : 0.18;
skyline.draw(
ctx,
width,
height,
pan * 0.25 + mouseX * 3,
vnow,
isDark,
0.6,
);
towers.forEach((t) => t.draw(ctx, width, height, ox1, isDark));
turbines.forEach((t) => t.draw(ctx, width, height, ox1, isDark));
solar.draw(ctx, width, height, ox1, isDark);
// oy 取反:镜像后倒影底部才能与柜体底部贴合,
// 否则鼠标垂直视差会让倒影脱节
racks.forEach((r) =>
r.draw(ctx, width, height, oxRack, -oyRack, isDark),
);
ctx.restore();
}
drawFloorFinish();
// 雾带必须晚于地板,否则下半段被地板盖出一条硬切线
drawHorizonFog();
// 三幕实体(正常 pass)
towers.forEach((t) => t.draw(ctx, width, height, ox1, isDark));
turbines.forEach((t) => t.draw(ctx, width, height, ox1, isDark));
solar.draw(ctx, width, height, ox1, isDark);
racks.forEach((r) => r.draw(ctx, width, height, oxRack, oyRack, isDark));
drawGroundFog(vnow, dt);
// 能量流入(琥珀金)
energyLines.forEach((l) =>
l.draw(
ctx,
width,
height,
pan * 0.7 + mouseX * 11,
mouseY * 6,
C.amber,
isDark,
),
);
// 数据流出(青色)
dataLines.forEach((l) =>
l.draw(
ctx,
width,
height,
pan * 0.9 + mouseX * 13,
mouseY * 8,
C.cyan,
isDark,
),
);
// 第三幕:应用屏
screens.forEach((s) =>
s.draw(
ctx,
width,
height,
pan + mouseX * 14,
mouseY * 9,
isDark,
Math.max(0.7, Math.min(1.15, height / 900)),
),
);
// token 升腾
if (now >= nextTokenAt) {
const idle = tokenPool.find((tk) => !tk.alive);
if (idle) idle.spawn(width, height, rand);
nextTokenAt = now + COUNT.spawnMs + rand() * COUNT.spawnMs;
}
tokenPool.forEach((tk) => {
tk.update(width, dt);
tk.draw(ctx, pan + mouseX * 16, mouseY * 10, isDark);
});
// 星尘(reduced-motion 时静止,只画不动)
dust.forEach((d) => {
if (animOn) d.update(dt);
d.draw(ctx, pan * 1.3 + mouseX * 22, mouseY * 13);
});
// ── 电影级后期:光斑 → 调色 → 暗角 → 颗粒 → 画幅黑边 ──
drawLensStreak(now);
drawColorGrade();
drawVignette();
drawGrain(now);
drawLetterbox();
frameId = requestAnimationFrame(animate);
};
window.addEventListener('resize', resize);
window.addEventListener('mousemove', onMouseMove);
resize();
animate();
return () => {
window.removeEventListener('resize', resize);
window.removeEventListener('mousemove', onMouseMove);
cancelAnimationFrame(frameId);
clearInterval(themeTickId);
};
}, []);
return (
);
};
export default TokenFactory;