正文
增加 41 行删除 41 行
11 行未改动12131415161718192045 行未改动66676869707172737431 行未改动10610710810911011111211311411511611711811912012112212383 行未改动207208209210211212213214215216217218219220221222117 行未改动全部展开34034134234334434534634734815 行未改动36436536636736836937037137244 行未改动41741841942042142242342442516 行未改动44244344444544644744844945011 行未改动4624634644654664674684694706 行未改动4774784794804814824834844854864874884894904914924934 行未改动49849950050150250350450550622 行未改动52953053153253353453553653753853954054116 行未改动5585595605615625635645655668 行未改动57557657757857958058158258358458558658758858959059159259359459559659710 行未改动60860961061161261361461561621 行未改动6386396406416426436446456463 行未改动65065165265365465565665765829 行未改动68868969069169269369469569621 行未改动71871972072172272372472572672772834 行未改动7637647657667677687697707712 行未改动77477577677777877978078178223 行未改动80680780880981081181281381429 行未改动84484584684784884985085185285385485585685785885923 行未改动88388488588688788888989089112 行未改动90490590690790890991091191230 行未改动94394494594694794894995095116 行未改动96896997097197297397497597610 行未改动98798898999099199299399499599699799820 行未改动10191020102110221023102410251026102736 行未改动11 行未改动--bg-primary: #0a0a0a;--card-w: 420px;--card-h: 600px;--font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;/* 动态主题色 - JS会更新这些 */--theme-hue: 210;--theme-sat: 50%;--theme-light: 50%;45 行未改动height: 100%;position: relative;border-radius: 30px;overflow: hidden;box-shadow:0 30px 60px -15px rgba(0,0,0,0.5),0 0 0 1px rgba(255,255,255,0.05) inset;transform-style: preserve-3d;transition: transform 0.2s ease-out, box-shadow 0.5s ease;31 行未改动justify-content: space-between;background: linear-gradient(180deg, rgba(0,0,0,0.2) 0%, transparent 30%, rgba(0,0,0,0.4) 100%);pointer-events: none; /* 让鼠标事件穿透到 Canvas */}/* 顶部信息栏 */.top-bar {display: flex;justify-content: space-between;align-items: flex-start;}.location-group h3 { font-size: 1.8rem; font-weight: 600; letter-spacing: 0.5px; text-shadow: 0 2px 10px rgba(0,0,0,0.2); }.location-group p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 5px; display: flex; align-items: center; gap: 6px; }.live-indicator {width: 8px; height: 8px; background: #0f0; border-radius: 50%;box-shadow: 0 0 10px #0f0;animation: pulse 2s infinite;83 行未改动font-size: 0.8rem;}.track-label { opacity: 0.5; font-size: 0.7rem; letter-spacing: 1px; text-transform: uppercase; }.track-name { font-weight: 500; margin-top: 2px; }.audio-controls { display: flex; align-items: center; gap: 15px; }#volume-slider {width: 80px; height: 4px; border-radius: 2px;-webkit-appearance: none; background: rgba(255,255,255,0.2); outline: none;}#volume-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: #fff; border-radius: 50%; cursor: pointer; }#play-btn {width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3);background: transparent; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;transition: all 0.2s ease;117 行未改动全部展开this.ctx = window.AudioContext || window.webkitAudioContext;this.ac = null; // 延迟初始化this.masterGain = null;this.analyser = null;// 场景音频节点容器this.scenes = { sunny: null, rainy: null, snowy: null, windy: null };this.activeSceneStr = null;this.loops = []; // 存储活跃的调度循环15 行未改动// 仅当切换到该场景时才连接并开始生成}resume() { if (this.ac && this.ac.state === 'suspended') this.ac.resume(); }setVolume(val) {if (!this.masterGain) return;// 指数型音量过渡更自然this.masterGain.gain.setTargetAtTime(val, this.ac.currentTime, 0.1);44 行未改动// --- 场景切换器 ---async switchScene(weather) {if (!this.ac) return;this.resume();const fadeTime = 3;const now = this.ac.currentTime;// 淡出当前场景16 行未改动const newScene = this.scenes[weather];newScene.gain.gain.setValueAtTime(0, now);newScene.gain.connect(this.masterGain);newScene.gain.gain.setTargetAtTime(1, now + 0.1, fadeTime / 3);if (newScene.start) newScene.start();// 更新 UI 音乐名称const trackNames = {11 行未改动// ☀️ 晴天:温暖的大调和弦,鸟鸣,轻柔底噪createSunnyScene() {const sceneGain = this.ac.createGain();// 1. 底噪 (模拟温暖空气/远处活动)const noise = this.createNoise('pink');const noiseFilter = this.ac.createBiquadFilter();noiseFilter.type = 'lowpass'; noiseFilter.frequency.value = 400;6 行未改动// 添加延迟效果器模拟混响const delay = this.ac.createDelay(); delay.delayTime.value = 0.4;const delayGain = this.ac.createGain(); delayGain.gain.value = 0.3;delay.connect(delayGain).connect(delay).connect(sceneGain);const playNote = () => {const now = this.ac.currentTime;const note = notes[Math.floor(Math.random() * notes.length)];const dur = rnd(2, 6); // 长音符// 偶尔双音叠加this.playTone(note, now, dur, 'sine', rnd(0.05, 0.15), sceneGain);if(Math.random()>0.7) this.playTone(notes[0]/2, now, dur+2, 'sine', 0.05, sceneGain); // 低音根音// 发送部分信号到延迟// (这里简化处理,上面直接 playTone 到了 sceneGain,实际应该分轨)};this.loops.push(setInterval(playNote, 4000)); // 每4秒尝试演奏4 行未改动const now = this.ac.currentTime;const osc = this.ac.createOscillator();const mod = this.ac.createOscillator(); // 调制器const gain = this.ac.createGain();mod.frequency.value = rnd(30, 70);const modGain = this.ac.createGain();modGain.gain.value = rnd(300, 900);mod.connect(modGain).connect(osc.frequency);22 行未改动// 1. 雨声 (主要的持续底噪)const rain = this.createNoise('white');const rainFilter = this.ac.createBiquadFilter();rainFilter.type = 'lowpass'; rainFilter.frequency.value = 3000; // 闷闷的雨声const rainGain = this.ac.createGain();rainGain.gain.value = 0.4;// 用 LFO 轻微调制雨声音量,模拟雨势波动const lfo = this.ac.createOscillator(); lfo.frequency.value = 0.2;const lfoGain = this.ac.createGain(); lfoGain.gain.value = 0.1;lfo.connect(lfoGain).connect(rainGain.gain); lfo.start();rain.connect(rainFilter).connect(rainGain).connect(sceneGain);16 行未改动}, 8000));return { gain: sceneGain, stop: () => { rain.stop(); lfo.stop(); } };}// 触发一次雷声triggerThunder(dest) {const now = this.ac.currentTime;// 两个噪声源:一个是爆发的高频(近处),一个是隆隆低频(远处)8 行未改动boomGain.gain.exponentialRampToValueAtTime(0.001, now + rnd(2, 4)); // 缓慢消逝boom.connect(boomFilter).connect(boomGain).connect(dest || this.masterGain);boom.start(now); boom.stop(now + 5);// 视觉联动:闪电flashLightning();}// ❄️ 雪天:带通滤波风声,极为空灵的长音createSnowyScene() {const sceneGain = this.ac.createGain();// 1. 寒风 (带通滤波扫描的粉红噪声)const wind = this.createNoise('pink');const windFilter = this.ac.createBiquadFilter();windFilter.type = 'bandpass';windFilter.Q.value = 4; // 窄频带制造"哨声"感const lfo = this.ac.createOscillator();lfo.frequency.value = 0.08; // 极慢的扫描const lfoGain = this.ac.createGain(); lfoGain.gain.value = 400; // 扫描范围lfo.connect(lfoGain).connect(windFilter.frequency);10 行未改动const osc = this.ac.createOscillator();osc.type = 'sine'; osc.frequency.value = freq;const gain = this.ac.createGain();gain.gain.value = 0.04 / (i + 1); // 高音音量更小// 让每个音符的音量独立缓慢呼吸const breathe = this.ac.createOscillator();breathe.frequency.value = rnd(0.05, 0.2);const breatheGain = this.ac.createGain();21 行未改动const sceneGain = this.ac.createGain();// 强风:类似雪天的风,但更猛烈、低沉、混乱const wind1 = this.createNoise('pink');const wind2 = this.createNoise('brown'); // 加入褐噪增加低频轰鸣const filter1 = this.ac.createBiquadFilter();filter1.type = 'lowpass'; filter1.frequency.value = 600;const filter2 = this.ac.createBiquadFilter();filter2.type = 'bandpass'; filter2.Q.value = 1;3 行未改动const gustGain = this.ac.createGain(); gustGain.gain.value = 500;gustLFO.connect(gustGain).connect(filter2.frequency);filter2.frequency.setValueAtTime(800, this.ac.currentTime);gustLFO.start();wind1.connect(filter2).connect(sceneGain);wind2.connect(filter1).connect(sceneGain);wind1.start(); wind2.start();29 行未改动// 简易 2D 噪声用于云和自然纹理const noise2D = (() => {// 极简的伪随机数哈希,不追求 Perlin 的完美但足够用const k = new Uint8Array(512);for (let i=0; i<512; i++) k[i] = (Math.sin(i*0.1)*127+128)|0;const fade = t => t * t * t * (t * (t * 6 - 15) + 10);const lerp = (a, b, t) => (1 - t) * a + t * b;return (x, y) => { // 返回 [-1, 1]const X = Math.floor(x) & 255, Y = Math.floor(y) & 255;21 行未改动this.clouds = []; // 用于绘制云的"粒子"this.w = 0; this.h = 0;this.resize();window.addEventListener('resize', () => this.resize());// 闪电状态this.lightning = 0;}resize() {const rect = $('weather-card').getBoundingClientRect();34 行未改动for(let i=0; i<30; i++) this.particles.push(this.createDebris());} else if (newW === 'sunny') {for(let i=0; i<20; i++) this.particles.push(this.createDust());}// 更新 CSS 变量用于 UI 主题const themes = {sunny: {h:35, s:'85%', l:'60%', t: 28, desc: '灿烂暖阳'},rainy: {h:220, s:'30%', l:'40%', t: 19, desc: '滂沱大雨'},2 行未改动};const t = themes[newW];document.documentElement.style.setProperty('--theme-hue', t.h);document.documentElement.style.setProperty('--theme-sat', t.s);// 平滑过渡温度数值STATE.targetTemp = t.t;$('weather-desc').textContent = t.desc;}23 行未改动this.particles.forEach(p => {if (w === 'rainy') {p.y += p.v;// 风力影响: 鼠标 x 位置稍微影响雨倾斜p.x += (STATE.mouse.x - 0.5) * 2;if(p.y > this.h) { p.y = -p.l; p.x = rnd(0, this.w); }} else if (w === 'snowy') {p.y += p.v;p.x += Math.sin(time + p.sw) * 0.5 + (STATE.mouse.x-0.5); // 飘荡29 行未改动if (w === 'sunny') {// 随鼠标移动太阳位置 (视差)const sunX = this.w * (1 - STATE.mouse.x * 0.3);const sunY = this.h * 0.2 * (1 + STATE.mouse.y * 0.5);grad = ctx.createRadialGradient(sunX, sunY, 10, sunX, sunY, this.w*0.8);grad.addColorStop(0, '#ffd700'); // 太阳核心grad.addColorStop(0.2, '#ffaa00');grad.addColorStop(1, '#4da6ff');ctx.fillStyle = grad;ctx.fillRect(0,0,this.w,this.h);// God rays (简单模拟: 旋转的大透明三角形)ctx.save();ctx.translate(sunX, sunY);ctx.rotate(t * 0.05);23 行未改动grad.addColorStop(0, '#a8c0ff');grad.addColorStop(1, '#3f2b96'); // 冷紫色调ctx.fillStyle = grad;ctx.fillRect(0,0,this.w,this.h);// 极光 (多层正弦波叠加)/* 省略复杂极光,用简单渐变色块代替以节省篇幅,实际可用复杂正弦波 */} else if (w === 'windy') {12 行未改动drawScene(ctx) {const w = STATE.weather;ctx.fillStyle = '#fff'; ctx.strokeStyle = 'rgba(255,255,255,0.5)';this.particles.forEach(p => {if (w === 'rainy') {ctx.lineWidth = 1.5;ctx.globalAlpha = p.a;30 行未改动let x = 0;for(let i = 0; i < bufferLength; i++) {const barH = dataArray[i] / 2; // 缩放一下// 颜色根据天气变化const hue = STATE.weather === 'sunny' ? 45 : 200;ctx.fillStyle = `hsla(${hue}, 100%, 70%, 0.3)`;ctx.fillRect(x, this.h - barH - 100, barW, barH); // 绘制到底部上方一点x += barW + 1;}16 行未改动const rect = $('container').getBoundingClientRect();// 计算鼠标相对于卡片中心的归一化坐标 (-1 到 1)const x = (e.clientX - rect.left) / rect.width * 2 - 1;const y = (e.clientY - rect.top) / rect.height * 2 - 1;// 更新全局鼠标状态供 canvas 使用 (0 到 1)STATE.mouse.x = (x + 1) / 2;STATE.mouse.y = (y + 1) / 2;10 行未改动// 首次交互解锁音频$('start-overlay').addEventListener('click', async () => {Audio.init();await Audio.ac.resume();$('start-overlay').style.opacity = 0;setTimeout(() => $('start-overlay').remove(), 1000);// 开始默认场景Visual.start();togglePlay(true); // 自动开始播放Audio.switchScene('sunny');20 行未改动$('play-btn').addEventListener('click', () => togglePlay());function togglePlay(forceState) {STATE.isPlaying = forceState !== undefined ? forceState : !STATE.isPlaying;// 切换图标const icon = $('play-icon');if(STATE.isPlaying) {Audio.resume();36 行未改动11 行未改动12131415161718192045 行未改动66676869707172737431 行未改动10610710810911011111211311411511611711811912012112212383 行未改动207208209210211212213214215216217218219220221222117 行未改动全部展开34034134234334434534634734815 行未改动36436536636736836937037137244 行未改动41741841942042142242342442516 行未改动44244344444544644744844945011 行未改动4624634644654664674684694706 行未改动4774784794804814824834844854864874884894904914924934 行未改动49849950050150250350450550622 行未改动52953053153253353453553653753853954054116 行未改动5585595605615625635645655668 行未改动57557657757857958058158258358458558658758858959059159259359459559659710 行未改动60860961061161261361461561621 行未改动6386396406416426436446456463 行未改动65065165265365465565665765829 行未改动68868969069169269369469569621 行未改动71871972072172272372472572672772834 行未改动7637647657667677687697707712 行未改动77477577677777877978078178223 行未改动80680780880981081181281381429 行未改动84484584684784884985085185285385485585685785885923 行未改动88388488588688788888989089112 行未改动90490590690790890991091191230 行未改动94394494594694794894995095116 行未改动96896997097197297397497597610 行未改动98798898999099199299399499599699799820 行未改动10191020102110221023102410251026102736 行未改动11 行未改动--bg-primary: #0a0a0a;--card-w: 420px;--card-h: 600px;--font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;/* 动态主题色 - JS会更新这些 */--theme-hue: 210;--theme-sat: 50%;--theme-light: 50%;45 行未改动height: 100%;position: relative;border-radius: 30px;overflow: hidden;box-shadow:0 30px 60px -15px rgba(0,0,0,0.5),0 0 0 1px rgba(255,255,255,0.05) inset;transform-style: preserve-3d;transition: transform 0.2s ease-out, box-shadow 0.5s ease;31 行未改动justify-content: space-between;background: linear-gradient(180deg, rgba(0,0,0,0.2) 0%, transparent 30%, rgba(0,0,0,0.4) 100%);pointer-events: none; /* 让鼠标事件穿透到 Canvas */}/* 顶部信息栏 */.top-bar {display: flex;justify-content: space-between;align-items: flex-start;}.location-group h3 { font-size: 1.8rem; font-weight: 600; letter-spacing: 0.5px; text-shadow: 0 2px 10px rgba(0,0,0,0.2); }.location-group p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 5px; display: flex; align-items: center; gap: 6px; }.live-indicator {width: 8px; height: 8px; background: #0f0; border-radius: 50%;box-shadow: 0 0 10px #0f0;animation: pulse 2s infinite;83 行未改动font-size: 0.8rem;}.track-label { opacity: 0.5; font-size: 0.7rem; letter-spacing: 1px; text-transform: uppercase; }.track-name { font-weight: 500; margin-top: 2px; }.audio-controls { display: flex; align-items: center; gap: 15px; }#volume-slider {width: 80px; height: 4px; border-radius: 2px;-webkit-appearance: none; background: rgba(255,255,255,0.2); outline: none;}#volume-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: #fff; border-radius: 50%; cursor: pointer; }#play-btn {width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3);background: transparent; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;transition: all 0.2s ease;117 行未改动全部展开this.ctx = window.AudioContext || window.webkitAudioContext;this.ac = null; // 延迟初始化this.masterGain = null;this.analyser = null;// 场景音频节点容器this.scenes = { sunny: null, rainy: null, snowy: null, windy: null };this.activeSceneStr = null;this.loops = []; // 存储活跃的调度循环15 行未改动// 仅当切换到该场景时才连接并开始生成}resume() { if (this.ac && this.ac.state === 'suspended') this.ac.resume(); }setVolume(val) {if (!this.masterGain) return;// 指数型音量过渡更自然this.masterGain.gain.setTargetAtTime(val, this.ac.currentTime, 0.1);44 行未改动// --- 场景切换器 ---async switchScene(weather) {if (!this.ac) return;this.resume();const fadeTime = 3;const now = this.ac.currentTime;// 淡出当前场景16 行未改动const newScene = this.scenes[weather];newScene.gain.gain.setValueAtTime(0, now);newScene.gain.connect(this.masterGain);newScene.gain.gain.setTargetAtTime(1, now + 0.1, fadeTime / 3);if (newScene.start) newScene.start();// 更新 UI 音乐名称const trackNames = {11 行未改动// ☀️ 晴天:温暖的大调和弦,鸟鸣,轻柔底噪createSunnyScene() {const sceneGain = this.ac.createGain();// 1. 底噪 (模拟温暖空气/远处活动)const noise = this.createNoise('pink');const noiseFilter = this.ac.createBiquadFilter();noiseFilter.type = 'lowpass'; noiseFilter.frequency.value = 400;6 行未改动// 添加延迟效果器模拟混响const delay = this.ac.createDelay(); delay.delayTime.value = 0.4;const delayGain = this.ac.createGain(); delayGain.gain.value = 0.3;delay.connect(delayGain).connect(delay).connect(sceneGain);const playNote = () => {const now = this.ac.currentTime;const note = notes[Math.floor(Math.random() * notes.length)];const dur = rnd(2, 6); // 长音符// 偶尔双音叠加this.playTone(note, now, dur, 'sine', rnd(0.05, 0.15), sceneGain);if(Math.random()>0.7) this.playTone(notes[0]/2, now, dur+2, 'sine', 0.05, sceneGain); // 低音根音// 发送部分信号到延迟// (这里简化处理,上面直接 playTone 到了 sceneGain,实际应该分轨)};this.loops.push(setInterval(playNote, 4000)); // 每4秒尝试演奏4 行未改动const now = this.ac.currentTime;const osc = this.ac.createOscillator();const mod = this.ac.createOscillator(); // 调制器const gain = this.ac.createGain();mod.frequency.value = rnd(30, 70);const modGain = this.ac.createGain();modGain.gain.value = rnd(300, 900);mod.connect(modGain).connect(osc.frequency);22 行未改动// 1. 雨声 (主要的持续底噪)const rain = this.createNoise('white');const rainFilter = this.ac.createBiquadFilter();rainFilter.type = 'lowpass'; rainFilter.frequency.value = 3000; // 闷闷的雨声const rainGain = this.ac.createGain();rainGain.gain.value = 0.4;// 用 LFO 轻微调制雨声音量,模拟雨势波动const lfo = this.ac.createOscillator(); lfo.frequency.value = 0.2;const lfoGain = this.ac.createGain(); lfoGain.gain.value = 0.1;lfo.connect(lfoGain).connect(rainGain.gain); lfo.start();rain.connect(rainFilter).connect(rainGain).connect(sceneGain);16 行未改动}, 8000));return { gain: sceneGain, stop: () => { rain.stop(); lfo.stop(); } };}// 触发一次雷声triggerThunder(dest) {const now = this.ac.currentTime;// 两个噪声源:一个是爆发的高频(近处),一个是隆隆低频(远处)8 行未改动boomGain.gain.exponentialRampToValueAtTime(0.001, now + rnd(2, 4)); // 缓慢消逝boom.connect(boomFilter).connect(boomGain).connect(dest || this.masterGain);boom.start(now); boom.stop(now + 5);// 视觉联动:闪电flashLightning();}// ❄️ 雪天:带通滤波风声,极为空灵的长音createSnowyScene() {const sceneGain = this.ac.createGain();// 1. 寒风 (带通滤波扫描的粉红噪声)const wind = this.createNoise('pink');const windFilter = this.ac.createBiquadFilter();windFilter.type = 'bandpass';windFilter.Q.value = 4; // 窄频带制造"哨声"感const lfo = this.ac.createOscillator();lfo.frequency.value = 0.08; // 极慢的扫描const lfoGain = this.ac.createGain(); lfoGain.gain.value = 400; // 扫描范围lfo.connect(lfoGain).connect(windFilter.frequency);10 行未改动const osc = this.ac.createOscillator();osc.type = 'sine'; osc.frequency.value = freq;const gain = this.ac.createGain();gain.gain.value = 0.04 / (i + 1); // 高音音量更小// 让每个音符的音量独立缓慢呼吸const breathe = this.ac.createOscillator();breathe.frequency.value = rnd(0.05, 0.2);const breatheGain = this.ac.createGain();21 行未改动const sceneGain = this.ac.createGain();// 强风:类似雪天的风,但更猛烈、低沉、混乱const wind1 = this.createNoise('pink');const wind2 = this.createNoise('brown'); // 加入褐噪增加低频轰鸣const filter1 = this.ac.createBiquadFilter();filter1.type = 'lowpass'; filter1.frequency.value = 600;const filter2 = this.ac.createBiquadFilter();filter2.type = 'bandpass'; filter2.Q.value = 1;3 行未改动const gustGain = this.ac.createGain(); gustGain.gain.value = 500;gustLFO.connect(gustGain).connect(filter2.frequency);filter2.frequency.setValueAtTime(800, this.ac.currentTime);gustLFO.start();wind1.connect(filter2).connect(sceneGain);wind2.connect(filter1).connect(sceneGain);wind1.start(); wind2.start();29 行未改动// 简易 2D 噪声用于云和自然纹理const noise2D = (() => {// 极简的伪随机数哈希,不追求 Perlin 的完美但足够用const k = new Uint8Array(512);for (let i=0; i<512; i++) k[i] = (Math.sin(i*0.1)*127+128)|0;const fade = t => t * t * t * (t * (t * 6 - 15) + 10);const lerp = (a, b, t) => (1 - t) * a + t * b;return (x, y) => { // 返回 [-1, 1]const X = Math.floor(x) & 255, Y = Math.floor(y) & 255;21 行未改动this.clouds = []; // 用于绘制云的"粒子"this.w = 0; this.h = 0;this.resize();window.addEventListener('resize', () => this.resize());// 闪电状态this.lightning = 0;}resize() {const rect = $('weather-card').getBoundingClientRect();34 行未改动for(let i=0; i<30; i++) this.particles.push(this.createDebris());} else if (newW === 'sunny') {for(let i=0; i<20; i++) this.particles.push(this.createDust());}// 更新 CSS 变量用于 UI 主题const themes = {sunny: {h:35, s:'85%', l:'60%', t: 28, desc: '灿烂暖阳'},rainy: {h:220, s:'30%', l:'40%', t: 19, desc: '滂沱大雨'},2 行未改动};const t = themes[newW];document.documentElement.style.setProperty('--theme-hue', t.h);document.documentElement.style.setProperty('--theme-sat', t.s);// 平滑过渡温度数值STATE.targetTemp = t.t;$('weather-desc').textContent = t.desc;}23 行未改动this.particles.forEach(p => {if (w === 'rainy') {p.y += p.v;// 风力影响: 鼠标 x 位置稍微影响雨倾斜p.x += (STATE.mouse.x - 0.5) * 2;if(p.y > this.h) { p.y = -p.l; p.x = rnd(0, this.w); }} else if (w === 'snowy') {p.y += p.v;p.x += Math.sin(time + p.sw) * 0.5 + (STATE.mouse.x-0.5); // 飘荡29 行未改动if (w === 'sunny') {// 随鼠标移动太阳位置 (视差)const sunX = this.w * (1 - STATE.mouse.x * 0.3);const sunY = this.h * 0.2 * (1 + STATE.mouse.y * 0.5);grad = ctx.createRadialGradient(sunX, sunY, 10, sunX, sunY, this.w*0.8);grad.addColorStop(0, '#ffd700'); // 太阳核心grad.addColorStop(0.2, '#ffaa00');grad.addColorStop(1, '#4da6ff');ctx.fillStyle = grad;ctx.fillRect(0,0,this.w,this.h);// God rays (简单模拟: 旋转的大透明三角形)ctx.save();ctx.translate(sunX, sunY);ctx.rotate(t * 0.05);23 行未改动grad.addColorStop(0, '#a8c0ff');grad.addColorStop(1, '#3f2b96'); // 冷紫色调ctx.fillStyle = grad;ctx.fillRect(0,0,this.w,this.h);// 极光 (多层正弦波叠加)/* 省略复杂极光,用简单渐变色块代替以节省篇幅,实际可用复杂正弦波 */} else if (w === 'windy') {12 行未改动drawScene(ctx) {const w = STATE.weather;ctx.fillStyle = '#fff'; ctx.strokeStyle = 'rgba(255,255,255,0.5)';this.particles.forEach(p => {if (w === 'rainy') {ctx.lineWidth = 1.5;ctx.globalAlpha = p.a;30 行未改动let x = 0;for(let i = 0; i < bufferLength; i++) {const barH = dataArray[i] / 2; // 缩放一下// 颜色根据天气变化const hue = STATE.weather === 'sunny' ? 45 : 200;ctx.fillStyle = `hsla(${hue}, 100%, 70%, 0.3)`;ctx.fillRect(x, this.h - barH - 100, barW, barH); // 绘制到底部上方一点x += barW + 1;}16 行未改动const rect = $('container').getBoundingClientRect();// 计算鼠标相对于卡片中心的归一化坐标 (-1 到 1)const x = (e.clientX - rect.left) / rect.width * 2 - 1;const y = (e.clientY - rect.top) / rect.height * 2 - 1;// 更新全局鼠标状态供 canvas 使用 (0 到 1)STATE.mouse.x = (x + 1) / 2;STATE.mouse.y = (y + 1) / 2;10 行未改动// 首次交互解锁音频$('start-overlay').addEventListener('click', async () => {Audio.init();await Audio.ac.resume();$('start-overlay').style.opacity = 0;setTimeout(() => $('start-overlay').remove(), 1000);// 开始默认场景Visual.start();togglePlay(true); // 自动开始播放Audio.switchScene('sunny');20 行未改动$('play-btn').addEventListener('click', () => togglePlay());function togglePlay(forceState) {STATE.isPlaying = forceState !== undefined ? forceState : !STATE.isPlaying;// 切换图标const icon = $('play-icon');if(STATE.isPlaying) {Audio.resume();36 行未改动