一个治愈系网页

前两天看到一个网页,很有意思。作者还把用 DeepSeek Vibe Coding 的过程分享出来了!

https://chat.deepseek.com/share/vvxp19xmnl9mndybpo

打开后,深蓝色的背景,像深海。前景是一排排竖着的中文词语,像窗帘一样缓缓往下滚动。鼠标滑过去,窗帘会被拨开,文字还会碎裂成粒子。背景里有一条虎鲸在游动,点击它会发出海豚音。

整个页面没有服务器,纯前端。Three.js 画虎鲸,p5.js 画窗帘和粒子。音频用 Web Audio API 生成。

实现思路

1. 虎鲸部分(Three.js)

用 LatheGeometry 旋转体轮廓生成身体,再加背鳍、胸鳍、尾鳍。全部转成粒子点云,看起来半透明、发光。鼠标控制位置,滚轮控制大小。背后还有一条更大的阴影虎鲸在缓慢旋转。

核心是定义虎鲸的身体轮廓曲线:

1
2
3
4
5
6
7
const BODY_PROFILE = [
[0.0, 2.35], [0.15, 2.32], [0.35, 2.25], [0.55, 2.12],
[0.75, 1.95], [0.95, 1.75], [1.12, 1.45], [1.22, 1.15],
[1.28, 0.85], [1.32, 0.55], [1.34, 0.25], [1.32, -0.05],
[1.25, -0.35], [1.12, -0.65], [0.95, -0.95], [0.72, -1.25],
[0.48, -1.55], [0.28, -1.85], [0.12, -2.1], [0.0, -2.3]
];

然后通过 CatmullRomCurve3 生成平滑曲线,再用 LatheGeometry 旋转成型。关键是将网格转为粒子点云:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function meshToPoints(geometry, color, size = 0.04, opacity = 0.35) {
const positions = geometry.attributes.position.array;
const colors = new Float32Array(positions.length);
const colorObj = new THREE.Color(color);
for (let i = 0; i < positions.length; i += 3) {
colors[i] = colorObj.r;
colors[i + 1] = colorObj.g;
colors[i + 2] = colorObj.b;
}
const pointGeo = new THREE.BufferGeometry();
pointGeo.setAttribute('position', new THREE.BufferAttribute(positions.slice(), 3));
pointGeo.setAttribute('color', new THREE.BufferAttribute(colors, 3));
return new THREE.Points(pointGeo, new THREE.PointsMaterial({
size, vertexColors: true,
blending: THREE.AdditiveBlending,
depthWrite: false, transparent: true, opacity
}));
}

虎鲸的腹部白色和背部深蓝色通过顶点颜色混合实现:

1
2
3
4
5
6
7
8
9
10
for (let i = 0; i < bPA.count; i++) {
const y = bPA.getY(i);
let c;
if (y > 0.05) c = dB; // 背部深蓝
else if (y < -0.05) c = pW; // 腹部白色
else c = new THREE.Color().lerpColors(pW, dB, (y + 0.05) / 0.1); // 过渡带
bCol[i * 3] = c.r;
bCol[i * 3 + 1] = c.g;
bCol[i * 3 + 2] = c.b;
}

动画部分通过 lerp 实现平滑跟随,胸鳍和尾鳍用 sin 波形摆动:

1
2
3
4
5
orcaGroup.position.lerp(targetPos, 0.1);
lPG.rotation.x = -0.25 + Math.sin(t * 3.5) * 0.35; // 左胸鳍
rPG.rotation.x = -0.25 + Math.sin(t * 3.5 + Math.PI) * 0.35; // 右胸鳍
const tf = Math.sin(t * 4.5) * 0.35;
tTG.rotation.x = -Math.PI / 2 + tf; // 尾鳍

2. 窗帘部分(p5.js)

每列是一个 CurtainColumn,里面是随机从词库抽的中文短句,竖直滚动。鼠标移动时给附近的列施加力,像拨窗帘。速度够快时,碰到的字符会碎裂成粒子,并播放一小段音效。

词库是一组治愈系中文短句:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const wordPool = [
'早安', '午安', '晚安', '好梦', '休息', '放松',
'阳光', '微风', '细雨', '星空', '月光', '云朵',
'海浪', '森林', '山谷', '溪流', '花瓣', '落叶',
'猫咪', '小狗', '兔子', '小鸟', '金鱼', '蝴蝶',
'书页', '咖啡', '热茶', '毛毯', '沙发', '台灯',
'代码', '画笔', '音符', '诗歌', '故事', '日记',
'晴天', '彩虹', '晚霞', '晨露', '雪花', '春风',
'港湾', '小憩', '发呆', '散步', '深呼吸', '慢慢来',
'今天很好', '明天也是', '没事的', '我在呢',
'放轻松', '别着急', '你很好', '会好的',
'吃了吗', '睡了吗', '想你了', '等你呢',
'光', '暖', '静', '安', '闲', '梦',
'虎鲸', 'Deepseek', '稳稳的接住', '你说得对', '看见', '靠近',
];

窗帘的物理模拟用弹簧+阻尼模型:

1
2
3
4
5
6
7
8
9
update() {
this.prevOffsetX = this.offsetX;
const stiffness = 0.08, damping = 0.78;
this.velocityX = (this.velocityX - this.offsetX * stiffness) * damping;
this.offsetX += this.velocityX;
this.offsetX = constrain(this.offsetX, -this.maxOffset, this.maxOffset);
this.glowAlpha *= 0.9;
this.scrollOffset += this.scrollSpeed;
}

鼠标快速划过时,文字碎裂成粒子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
checkShatter(mx, my, ms) {
if (ms < 5) return;
const x = this.baseX + this.offsetX;
const chars = this.phrase.split('');
const startY = -this.scrollOffset;
for (let i = 0; i < chars.length; i++) {
if (this.shatteredIndices.has(i)) continue;
const y = startY + i * this.charSpacing;
const d = dist(mx, my, x, y);
const threshold = this.fontSize * 0.8;
if (d < threshold) {
this.shatteredIndices.add(i);
const count = floor(random(8, 16));
for (let j = 0; j < count; j++) {
shatterParticles.push(new ShatterParticle(x, y, this.r, this.g, this.b));
}
return true;
}
}
return false;
}

碎裂粒子有重力、衰减、发光效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class ShatterParticle {
constructor(x, y, r, g, b) {
this.x = x; this.y = y;
this.vx = (random() - 0.5) * 4.5;
this.vy = (random() - 0.5) * 4.5 - random() * 2;
this.life = 1.0;
this.decay = 0.025 + random() * 0.04;
this.size = random(2, 6);
this.r = r + random() * 40;
this.g = g + random() * 25;
this.b = b + random() * 20;
this.glow = random() > 0.5;
}
update() {
this.x += this.vx;
this.y += this.vy;
this.vy += 0.04; // 重力
this.life -= this.decay;
this.size *= 0.985;
}
}

3. 声音(Web Audio API)

全部用 Web Audio API 合成,不依赖任何音频文件:

  • 拨动窗帘:五声音阶的轻响(triangle 波 + sine 泛音)
  • 点击虎鲸:上升的正弦波,模拟海豚音
  • 文字碎裂:短促的带通滤波声
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function playDolphinSound() {
const now = audioCtx.currentTime;
const duration = 0.25;
const baseFreq = 750 + Math.random() * 450;
const endFreq = baseFreq * 1.6;
const osc = audioCtx.createOscillator();
osc.type = 'sine';
osc.frequency.setValueAtTime(baseFreq, now);
osc.frequency.linearRampToValueAtTime(endFreq, now + duration);
const gain = audioCtx.createGain();
gain.gain.setValueAtTime(0, now);
gain.gain.linearRampToValueAtTime(0.18, now + 0.02);
gain.gain.exponentialRampToValueAtTime(0.001, now + duration);
osc.connect(gain).connect(masterGain);
osc.start(now);
osc.stop(now + duration);
}

五声音阶的随机轻响营造治愈氛围:

1
let pentatonicScale = [523.25, 587.33, 659.25, 783.99, 880.0, 1046.5, 1174.66];

4. 氛围层

背景有缓慢下沉的星点、水波纹、小鱼群。底部和顶部还有淡淡的渐变光。

  • 星点:100 个随机粒子,缓慢上浮+闪烁
  • 水波纹:多层正弦波叠加,模拟水面光影
  • 小鱼群:32 条 p5.js 绘制的卡通小鱼,随机游动
  • Three.js 远景鱼群:200 个点粒子在三维空间中游动
  • 星海:900 个球面分布的远景点

水波纹用多层正弦波叠加:

1
2
3
4
5
6
7
8
9
10
11
for (let y = 0; y < height; y += 4) {
let wv = sin(y * 0.018 + frameCount * 0.022) * 0.45
+ sin(y * 0.027 - frameCount * 0.016 + 1.7) * 0.35;
wv += cos(y * 0.009 + frameCount * 0.011 + 3.1) * 0.28
+ sin(y * 0.035 + frameCount * 0.028 + 5.4) * 0.2;
const a = constrain((wv + 1.28) * 4.5, 0, 13);
if (a > 0.4) {
ctxWater.fillStyle = `rgba(175,210,240,${a / 255})`;
ctxWater.fillRect(0, y, width, 3.5);
}
}

技术架构总结

层 技术 职责
背景层(z-index: 1) Three.js 虎鲸、阴影虎鲸、远景鱼群、星海
前景层(z-index: 2) p5.js 窗帘文字、碎裂粒子、水波纹、小鱼、涟漪
音频层 Web Audio API 五声音阶轻响、海豚音、碎裂声
UI 层(z-index: 10) HTML/CSS 提示文字

完整源码

保存成 .html 文件,用浏览器打开就能跑(需要联网加载 Three.js 和 p5.js)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>窗帘代码雨 · 虎鲸深海</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #0a0e1a;
overflow: hidden;
font-family: 'Courier New', 'PingFang SC', 'Microsoft YaHei', monospace;
cursor: default;
}
#orca-canvas {
position: fixed; top: 0; left: 0;
z-index: 1; pointer-events: none;
}
.p5canvas {
position: fixed; top: 0; left: 0;
z-index: 2; pointer-events: auto;
}
.hint {
position: fixed; bottom: 26px; left: 50%;
transform: translateX(-50%); z-index: 10;
color: rgba(170, 210, 240, 0.45);
font-size: 12px; letter-spacing: 0.05em;
pointer-events: none;
text-shadow: 0 0 14px rgba(150, 200, 235, 0.35);
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
transition: opacity 1.8s;
}
</style>
</head>
<body>
<div class="hint" id="hint">✨ 拨动窗帘 · 文字碎裂 · 点击虎鲸听海豚音</div>

<script type="importmap">
{ "imports": { "three": "https://unpkg.com/three@0.128.0/build/three.module.js" } }
</script>
<script type="module">
import * as THREE from 'three';
const DEEP_BLUE = 0x5577cc;
const WHITE = 0xddeeff;
const BODY_PROFILE = [
[0.0, 2.35], [0.15, 2.32], [0.35, 2.25], [0.55, 2.12],
[0.75, 1.95], [0.95, 1.75], [1.12, 1.45], [1.22, 1.15],
[1.28, 0.85], [1.32, 0.55], [1.34, 0.25], [1.32, -0.05],
[1.25, -0.35], [1.12, -0.65], [0.95, -0.95], [0.72, -1.25],
[0.48, -1.55], [0.28, -1.85], [0.12, -2.1], [0.0, -2.3]
];

function meshToPoints(geometry, color, size = 0.04, opacity = 0.35) {
const positions = geometry.attributes.position.array;
const colors = new Float32Array(positions.length);
const colorObj = new THREE.Color(color);
for (let i = 0; i < positions.length; i += 3) {
colors[i] = colorObj.r; colors[i + 1] = colorObj.g; colors[i + 2] = colorObj.b;
}
const pointGeo = new THREE.BufferGeometry();
pointGeo.setAttribute('position', new THREE.BufferAttribute(positions.slice(), 3));
pointGeo.setAttribute('color', new THREE.BufferAttribute(colors, 3));
return new THREE.Points(pointGeo, new THREE.PointsMaterial({
size, vertexColors: true, blending: THREE.AdditiveBlending,
depthWrite: false, transparent: true, opacity
}));
}

function meshToPointsWithVertexColors(geometry, size = 0.04, opacity = 0.35) {
const posAttr = geometry.attributes.position;
const colAttr = geometry.attributes.color;
if (!colAttr) return meshToPoints(geometry, WHITE, size, opacity);
const pointGeo = new THREE.BufferGeometry();
pointGeo.setAttribute('position', new THREE.BufferAttribute(posAttr.array.slice(), 3));
pointGeo.setAttribute('color', new THREE.BufferAttribute(colAttr.array.slice(), 3));
return new THREE.Points(pointGeo, new THREE.PointsMaterial({
size, vertexColors: true, blending: THREE.AdditiveBlending,
depthWrite: false, transparent: true, opacity
}));
}

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 1000);
camera.position.set(5.8, 2.2, 10.5);
camera.lookAt(0, 0, 0);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.domElement.id = 'orca-canvas';
document.body.appendChild(renderer.domElement);

const shadowOrcaGroup = new THREE.Group();
shadowOrcaGroup.scale.set(1.5, 1.5, 1.5);
shadowOrcaGroup.position.set(0, -0.8, -4.5);
scene.add(shadowOrcaGroup);

const shadowProfile = BODY_PROFILE.map(([r, y]) => new THREE.Vector2(r, y));
const shadowCurve = new THREE.CatmullRomCurve3(
shadowProfile.map(p => new THREE.Vector3(p.x, p.y, 0)), false, 'catmullrom', 0.5
);
const shadowPts = shadowCurve.getPoints(160);
const shadowBodyGeo = new THREE.LatheGeometry(
shadowPts.map(p => new THREE.Vector2(p.x, p.y)), 64
);
shadowBodyGeo.rotateZ(Math.PI / 2);
const sPA = shadowBodyGeo.attributes.position;
for (let i = 0; i < sPA.count; i++) {
const y = sPA.getY(i);
if (y < 0) sPA.setY(i, y * 0.54);
else if (y > 0.2) sPA.setY(i, y * 0.95);
}
shadowBodyGeo.computeVertexNormals();
shadowOrcaGroup.add(meshToPoints(shadowBodyGeo, 0x334466, 0.06, 0.12));

const sDorsal = new THREE.Shape();
sDorsal.moveTo(-0.55, 0);
sDorsal.bezierCurveTo(-0.4, 0.5, -0.2, 1.1, 0.15, 1.5);
sDorsal.bezierCurveTo(0.3, 1.7, 0.5, 1.95, 0.6, 2.0);
sDorsal.bezierCurveTo(0.68, 1.85, 0.7, 1.65, 0.6, 1.45);
sDorsal.bezierCurveTo(0.45, 1.0, 0.3, 0.5, 0.2, 0);
sDorsal.lineTo(-0.55, 0);
const sDGeo = new THREE.ExtrudeGeometry(sDorsal, {
steps: 1, depth: 0.04, bevelEnabled: true,
bevelThickness: 0.008, bevelSize: 0.008, bevelSegments: 1
});
const sDP = meshToPoints(sDGeo, 0x334466, 0.06, 0.12);
sDP.position.set(-0.08, 0, -0.02);
const sDG = new THREE.Group();
sDG.add(sDP);
sDG.position.set(-0.35, 1.15, 0);
sDG.rotation.set(0, 0, -0.08);
sDG.scale.set(0.7, 0.42, 0.7);
shadowOrcaGroup.add(sDG);

const sPec = new THREE.Shape();
sPec.moveTo(0.6, 0);
sPec.quadraticCurveTo(1.2, 0.7, 1.9, 0.9);
sPec.quadraticCurveTo(2.1, 0.35, 1.5, -0.05);
sPec.quadraticCurveTo(1.1, -0.12, 0.6, 0);
const sPE = {
steps: 1, depth: 0.05, bevelEnabled: true,
bevelThickness: 0.025, bevelSize: 0.02, bevelSegments: 1
};
const sLPGeo = new THREE.ExtrudeGeometry(sPec, sPE);
const sLPG = new THREE.Group();
sLPG.add(meshToPoints(sLPGeo, 0x334466, 0.06, 0.12));
sLPG.position.set(-0.85, 0.15, -0.72);
sLPG.rotation.set(-0.25, Math.PI / 3.5, 0.15);
shadowOrcaGroup.add(sLPG);
const sRPGeo = new THREE.ExtrudeGeometry(sPec, sPE);
sRPGeo.applyMatrix4(new THREE.Matrix4().makeScale(1, 1, -1));
sRPGeo.computeVertexNormals();
const sRPG = new THREE.Group();
sRPG.add(meshToPoints(sRPGeo, 0x334466, 0.06, 0.12));
sRPG.position.set(-0.85, 0.15, 0.72);
sRPG.rotation.set(-0.25, -Math.PI / 3.5, -0.15);
shadowOrcaGroup.add(sRPG);

const cSTail = (sign) => {
const shape = new THREE.Shape();
shape.moveTo(2.2, 0);
shape.quadraticCurveTo(2.9, 0.55 * sign, 3.45, 1.05 * sign);
shape.quadraticCurveTo(3.75, 0.7 * sign, 3.2, 0.0);
shape.quadraticCurveTo(2.6, -0.15 * sign, 2.2, 0);
const geo = new THREE.ExtrudeGeometry(shape, {
steps: 1, depth: 0.07, bevelEnabled: true,
bevelThickness: 0.04, bevelSize: 0.03, bevelSegments: 1
});
const pts = meshToPoints(geo, 0x334466, 0.06, 0.12);
pts.rotation.x = -Math.PI / 2;
return pts;
};
shadowOrcaGroup.add(cSTail(1));
shadowOrcaGroup.add(cSTail(-1));

const fishCount = 200;
const fishGeo = new THREE.BufferGeometry();
const fishPos = new Float32Array(fishCount * 3);
const fishVel = [];
for (let i = 0; i < fishCount; i++) {
fishPos[i * 3] = (Math.random() - 0.5) * 22;
fishPos[i * 3 + 1] = (Math.random() - 0.5) * 14;
fishPos[i * 3 + 2] = -5 + (Math.random() - 0.5) * 12;
fishVel.push({
x: (Math.random() - 0.5) * 0.018,
y: (Math.random() - 0.5) * 0.01,
z: (Math.random() - 0.5) * 0.012
});
}
fishGeo.setAttribute('position', new THREE.BufferAttribute(fishPos, 3));
const fishMat = new THREE.PointsMaterial({
color: 0xaaccff, size: 0.16, transparent: true, opacity: 0.65,
blending: THREE.AdditiveBlending, depthWrite: false
});
const fishPts = new THREE.Points(fishGeo, fishMat);
scene.add(fishPts);

const starGeo = new THREE.BufferGeometry();
const starArr = new Float32Array(900 * 3);
for (let i = 0; i < 900 * 3; i += 3) {
const r = 16 + Math.random() * 22;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
starArr[i] = r * Math.sin(phi) * Math.cos(theta);
starArr[i + 1] = r * Math.sin(phi) * Math.sin(theta) * 0.7;
starArr[i + 2] = r * Math.cos(phi) * 1.1;
}
starGeo.setAttribute('position', new THREE.BufferAttribute(starArr, 3));
const starF = new THREE.Points(starGeo, new THREE.PointsMaterial({
color: 0x99bbee, size: 0.09, transparent: true, opacity: 0.5,
blending: THREE.AdditiveBlending, depthWrite: false
}));
scene.add(starF);

const orcaGroup = new THREE.Group();
orcaGroup.scale.set(0.28, 0.28, 0.28);
scene.add(orcaGroup);
const pV = BODY_PROFILE.map(([r, y]) => new THREE.Vector2(r, y));
const curve = new THREE.CatmullRomCurve3(
pV.map(p => new THREE.Vector3(p.x, p.y, 0)), false, 'catmullrom', 0.5
);
const sPts = curve.getPoints(200);
const bodyGeo = new THREE.LatheGeometry(
sPts.map(p => new THREE.Vector2(p.x, p.y)), 48
);
bodyGeo.rotateZ(Math.PI / 2);
const bPA = bodyGeo.attributes.position;
for (let i = 0; i < bPA.count; i++) {
const y = bPA.getY(i);
if (y < 0) bPA.setY(i, y * 0.54);
else if (y > 0.2) bPA.setY(i, y * 0.95);
}
bodyGeo.computeVertexNormals();
const bCol = new Float32Array(bPA.count * 3);
const dB = new THREE.Color(DEEP_BLUE);
const pW = new THREE.Color(WHITE);
for (let i = 0; i < bPA.count; i++) {
const y = bPA.getY(i);
let c;
if (y > 0.05) c = dB;
else if (y < -0.05) c = pW;
else c = new THREE.Color().lerpColors(pW, dB, (y + 0.05) / 0.1);
bCol[i * 3] = c.r; bCol[i * 3 + 1] = c.g; bCol[i * 3 + 2] = c.b;
}
bodyGeo.setAttribute('color', new THREE.BufferAttribute(bCol, 3));
orcaGroup.add(meshToPointsWithVertexColors(bodyGeo, 0.035, 0.3));

const dShape = new THREE.Shape();
dShape.moveTo(-0.55, 0);
dShape.bezierCurveTo(-0.4, 0.5, -0.2, 1.1, 0.15, 1.5);
dShape.bezierCurveTo(0.3, 1.7, 0.5, 1.95, 0.6, 2.0);
dShape.bezierCurveTo(0.68, 1.85, 0.7, 1.65, 0.6, 1.45);
dShape.bezierCurveTo(0.45, 1.0, 0.3, 0.5, 0.2, 0);
dShape.lineTo(-0.55, 0);
const dGeo = new THREE.ExtrudeGeometry(dShape, {
steps: 1, depth: 0.04, bevelEnabled: true,
bevelThickness: 0.008, bevelSize: 0.008, bevelSegments: 1
});
const dPts = meshToPoints(dGeo, DEEP_BLUE, 0.04, 0.32);
dPts.position.set(-0.08, 0, -0.02);
const dFG = new THREE.Group();
dFG.add(dPts);
dFG.position.set(-0.35, 1.15, 0);
dFG.rotation.set(0, 0, -0.08);
dFG.scale.set(0.7, 0.42, 0.7);
orcaGroup.add(dFG);

const cTail = (sign) => {
const shape = new THREE.Shape();
shape.moveTo(2.2, 0);
shape.quadraticCurveTo(2.9, 0.55 * sign, 3.45, 1.05 * sign);
shape.quadraticCurveTo(3.75, 0.7 * sign, 3.2, 0.0);
shape.quadraticCurveTo(2.6, -0.15 * sign, 2.2, 0);
const geo = new THREE.ExtrudeGeometry(shape, {
steps: 1, depth: 0.07, bevelEnabled: true,
bevelThickness: 0.04, bevelSize: 0.03, bevelSegments: 1
});
const pts = meshToPoints(geo, DEEP_BLUE, 0.04, 0.32);
const g = new THREE.Group();
g.add(pts);
g.rotation.x = -Math.PI / 2;
return g;
};
const tTG = cTail(1);
const tBG = cTail(-1);
orcaGroup.add(tTG); orcaGroup.add(tBG);

const pecShape = new THREE.Shape();
pecShape.moveTo(0.6, 0);
pecShape.quadraticCurveTo(1.2, 0.7, 1.9, 0.9);
pecShape.quadraticCurveTo(2.1, 0.35, 1.5, -0.05);
pecShape.quadraticCurveTo(1.1, -0.12, 0.6, 0);
const pES = {
steps: 1, depth: 0.05, bevelEnabled: true,
bevelThickness: 0.025, bevelSize: 0.02, bevelSegments: 1
};
const lPGeo = new THREE.ExtrudeGeometry(pecShape, pES);
const lPG = new THREE.Group();
lPG.add(meshToPoints(lPGeo, DEEP_BLUE, 0.04, 0.32));
lPG.position.set(-0.85, 0.15, -0.72);
lPG.rotation.set(-0.25, Math.PI / 3.5, 0.15);
orcaGroup.add(lPG);
const rPGeo = new THREE.ExtrudeGeometry(pecShape, pES);
rPGeo.applyMatrix4(new THREE.Matrix4().makeScale(1, 1, -1));
rPGeo.computeVertexNormals();
const rPG = new THREE.Group();
rPG.add(meshToPoints(rPGeo, DEEP_BLUE, 0.04, 0.32));
rPG.position.set(-0.85, 0.15, 0.72);
rPG.rotation.set(-0.25, -Math.PI / 3.5, -0.15);
orcaGroup.add(rPG);

const magShape = new THREE.Shape();
magShape.moveTo(0, 0.12);
magShape.bezierCurveTo(0.2, 0.32, 0.6, 0.28, 0.65, 0.05);
magShape.bezierCurveTo(0.68, -0.08, 0.52, -0.22, 0.33, -0.18);
magShape.bezierCurveTo(0.18, -0.14, 0.08, -0.04, 0.03, 0.05);
magShape.bezierCurveTo(0.0, 0.1, -0.02, 0.12, 0, 0.12);
const browPath = new THREE.Path(magShape.getPoints(64));
const dashPts = browPath.getPoints(28);
const dashArr = dashPts.map(p => [p.x, p.y, 0]).flat();
const dashGeo = new THREE.BufferGeometry();
dashGeo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(dashArr), 3));
const dashMat = new THREE.PointsMaterial({
color: 0xffffff, size: 0.04, blending: THREE.AdditiveBlending,
depthWrite: false, transparent: true, opacity: 0.95
});
const browDots = new THREE.Points(dashGeo, dashMat);
const eyeGeo = new THREE.SphereGeometry(0.18, 16, 16);
const createEye = () => {
const g = new THREE.Group();
g.add(browDots.clone());
const eb = meshToPoints(eyeGeo, WHITE, 0.04, 0.3);
eb.position.set(-0.09, -0.14, 0.02);
eb.scale.set(0.8, 0.8, 0.45);
g.add(eb);
g.position.set(-1.55, 0.45, -0.93);
g.rotation.set(0.25, 0.5, 0.08);
g.scale.set(1.15, 0.6, 0.95);
return g;
};
orcaGroup.add(createEye());
const rEye = createEye();
rEye.applyMatrix4(new THREE.Matrix4().makeScale(1, 1, -1));
orcaGroup.add(rEye);

const glowGeo = new THREE.BufferGeometry();
const glowArr = new Float32Array(200 * 3);
for (let i = 0; i < 200 * 3; i += 3) {
const a = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
const r = 2.2 + Math.random() * 1.6;
glowArr[i] = r * Math.sin(phi) * Math.cos(a);
glowArr[i + 1] = r * Math.sin(phi) * Math.sin(a);
glowArr[i + 2] = r * Math.cos(phi);
}
glowGeo.setAttribute('position', new THREE.BufferAttribute(glowArr, 3));
const glowP = new THREE.Points(glowGeo, new THREE.PointsMaterial({
color: 0xaaccff, size: 0.06, transparent: true, opacity: 0.3,
blending: THREE.AdditiveBlending, depthWrite: false
}));
orcaGroup.add(glowP);

const targetPos = new THREE.Vector3(0, 0, 0);
window.addEventListener('mousemove', (e) => {
const x = (e.clientX / innerWidth) * 2 - 1;
const y = -(e.clientY / innerHeight) * 2 + 1;
targetPos.set(x * 5.8, y * 3.2, -1.5);
});
let whaleScale = 0.28;
window.addEventListener('wheel', (e) => {
e.preventDefault();
whaleScale += e.deltaY * -0.0005;
whaleScale = Math.max(0.12, Math.min(0.65, whaleScale));
}, { passive: false });

function animate() {
requestAnimationFrame(animate);
const t = Date.now() * 0.001;
orcaGroup.position.lerp(targetPos, 0.1);
const dir = new THREE.Vector3().subVectors(targetPos, orcaGroup.position).normalize();
const tQ = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, 1), dir);
const eu = new THREE.Euler().setFromQuaternion(tQ);
orcaGroup.rotation.y += (eu.y - orcaGroup.rotation.y) * 0.15;
orcaGroup.rotation.z += (Math.sin(t * 0.8) * 0.025 - orcaGroup.rotation.z) * 0.06;
orcaGroup.scale.set(whaleScale, whaleScale, whaleScale);
lPG.rotation.x = -0.25 + Math.sin(t * 3.5) * 0.35;
rPG.rotation.x = -0.25 + Math.sin(t * 3.5 + Math.PI) * 0.35;
const tf = Math.sin(t * 4.5) * 0.35;
tTG.rotation.x = -Math.PI / 2 + tf;
tBG.rotation.x = -Math.PI / 2 + tf;
shadowOrcaGroup.rotation.y += 0.0015;
shadowOrcaGroup.rotation.z = Math.sin(t * 0.3) * 0.05;
const bfa = fishGeo.attributes.position.array;
for (let i = 0; i < fishCount; i++) {
const idx = i * 3;
bfa[idx] += fishVel[i].x;
bfa[idx + 1] += fishVel[i].y;
bfa[idx + 2] += fishVel[i].z;
if (bfa[idx] > 11) bfa[idx] = -11;
if (bfa[idx] < -11) bfa[idx] = 11;
if (bfa[idx + 1] > 7) bfa[idx + 1] = -7;
if (bfa[idx + 1] < -7) bfa[idx + 1] = 7;
if (bfa[idx + 2] > 6) bfa[idx + 2] = -6;
if (bfa[idx + 2] < -10) bfa[idx + 2] = 2;
}
fishGeo.attributes.position.needsUpdate = true;
starF.rotation.y += 0.0002;
starF.rotation.x += 0.0001;
glowP.rotation.y += 0.0015;
glowP.rotation.x += 0.0008;
const sp = orcaGroup.position.clone().project(camera);
window.orcaScreenX = (sp.x * 0.5 + 0.5) * innerWidth;
window.orcaScreenY = (-sp.y * 0.5 + 0.5) * innerHeight;
window.orcaScale = whaleScale;
renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>

<!-- P5.js 前景层 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"></script>
<script>
let columns = [];
let bgStars = [];
let ripples = [];
let fishes = [];
let shatterParticles = [];
let prevMouseX = 0, prevMouseY = 0, mouseSpeed = 0;
let audioCtx = null, masterGain = null;
let pentatonicScale = [523.25, 587.33, 659.25, 783.99, 880.0, 1046.5, 1174.66];
let breezeTimer = 0, breezeInterval = 80;
let hintElement = null, hintAlpha = 1.0, hintFadeTimer = 0;

const wordPool = [
'早安', '午安', '晚安', '好梦', '休息', '放松',
'阳光', '微风', '细雨', '星空', '月光', '云朵',
'海浪', '森林', '山谷', '溪流', '花瓣', '落叶',
'猫咪', '小狗', '兔子', '小鸟', '金鱼', '蝴蝶',
'书页', '咖啡', '热茶', '毛毯', '沙发', '台灯',
'代码', '画笔', '音符', '诗歌', '故事', '日记',
'晴天', '彩虹', '晚霞', '晨露', '雪花', '春风',
'港湾', '小憩', '发呆', '散步', '深呼吸', '慢慢来',
'今天很好', '明天也是', '没事的', '我在呢',
'放轻松', '别着急', '你很好', '会好的',
'吃了吗', '睡了吗', '想你了', '等你呢',
'光', '暖', '静', '安', '闲', '梦',
'虎鲸', 'Deepseek', '稳稳的接住', '你说得对', '看见', '靠近',
];

class Ripple {
constructor(x, y, maxRadius, duration, strength = 1.0) {
this.x = x; this.y = y; this.radius = 0; this.maxRadius = maxRadius;
this.duration = duration; this.age = 0; this.strength = strength; this.alive = true;
this.baseR = 175; this.baseG = 210; this.baseB = 242;
}
update() {
this.age++;
const p = this.age / this.duration;
this.radius = this.maxRadius * (1 - Math.pow(1 - p, 3));
if (this.age >= this.duration) this.alive = false;
}
getOpacity() {
const p = this.age / this.duration;
if (p < 0.15) return (p / 0.15) * 0.55 * this.strength;
return (1 - (p - 0.15) / 0.85) * 0.55 * this.strength;
}
draw() {
const op = this.getOpacity();
if (op < 0.003 || this.radius < 0.5) return;
const ctx = drawingContext;
ctx.save();
const g = ctx.createRadialGradient(
this.x, this.y, this.radius * 0.78,
this.x, this.y, this.radius * 1.06
);
g.addColorStop(0, `rgba(${this.baseR},${this.baseG},${this.baseB},0)`);
g.addColorStop(0.55, `rgba(${this.baseR},${this.baseG},${this.baseB},${op * 0.35})`);
g.addColorStop(0.78, `rgba(${this.baseR},${this.baseG},${this.baseB},${op * 0.7})`);
g.addColorStop(0.9, `rgba(${this.baseR + 15},${this.baseG + 10},${this.baseB + 5},${op * 0.35})`);
g.addColorStop(1, `rgba(${this.baseR},${this.baseG},${this.baseB},0)`);
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius * 1.06, 0, Math.PI * 2);
ctx.fill();
if (this.radius > 14 && op > 0.02) {
const g2 = ctx.createRadialGradient(
this.x, this.y, this.radius * 1.04,
this.x, this.y, this.radius * 1.22
);
g2.addColorStop(0, `rgba(${this.baseR},${this.baseG},${this.baseB},0)`);
g2.addColorStop(0.4, `rgba(${this.baseR + 10},${this.baseG + 8},${this.baseB + 5},${op * 0.2})`);
g2.addColorStop(0.65, `rgba(${this.baseR + 10},${this.baseG + 8},${this.baseB + 5},${op * 0.35})`);
g2.addColorStop(0.85, `rgba(${this.baseR + 10},${this.baseG + 8},${this.baseB + 5},${op * 0.12})`);
g2.addColorStop(1, `rgba(${this.baseR},${this.baseG},${this.baseB},0)`);
ctx.fillStyle = g2;
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius * 1.22, 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
}
isAlive() { return this.alive; }
}

class ShatterParticle {
constructor(x, y, r, g, b) {
this.x = x; this.y = y;
this.vx = (random() - 0.5) * 4.5;
this.vy = (random() - 0.5) * 4.5 - random() * 2;
this.life = 1.0;
this.decay = 0.025 + random() * 0.04;
this.size = random(2, 6);
this.r = r + random() * 40;
this.g = g + random() * 25;
this.b = b + random() * 20;
this.glow = random() > 0.5;
}
update() {
this.x += this.vx; this.y += this.vy;
this.vy += 0.04;
this.life -= this.decay;
this.size *= 0.985;
}
draw() {
if (this.life <= 0) return;
const alpha = this.life * 220;
noStroke();
if (this.glow) {
drawingContext.shadowBlur = 6;
drawingContext.shadowColor = `rgba(${Math.floor(this.r)},${Math.floor(this.g)},${Math.floor(this.b)},${alpha / 300})`;
}
fill(this.r, this.g, this.b, alpha);
circle(this.x, this.y, this.size);
drawingContext.shadowBlur = 0;
}
isAlive() { return this.life > 0; }
}

class Fish {
constructor() {
this.x = random(width * 0.1, width * 0.9);
this.y = random(height * 0.1, height * 0.9);
this.size = random(9, 19);
this.vx = random(-1.2, 1.2);
this.vy = random(-0.5, 0.5);
if (abs(this.vx) < 0.3) this.vx = (random() > 0.5 ? 1 : -1) * random(0.5, 1.2);
this.direction = this.vx > 0 ? 1 : -1;
this.r = 140 + random(55);
this.g = 195 + random(35);
this.b = 220 + random(30);
this.alpha = 180 + random(70);
this.bodyRatio = 0.5 + random() * 0.35;
this.tailWiggle = random(TWO_PI);
this.wiggleSpeed = 0.04 + random() * 0.08;
}
update() {
this.x += this.vx; this.y += this.vy;
this.tailWiggle += this.wiggleSpeed;
if (this.x > width + 60) this.x = -60;
if (this.x < -60) this.x = width + 60;
if (this.y > height + 60) this.y = -60;
if (this.y < -60) this.y = height + 60;
if (this.vx > 0.15) this.direction = 1;
if (this.vx < -0.15) this.direction = -1;
if (random() < 0.015) {
this.vx += random(-0.4, 0.4);
this.vy += random(-0.25, 0.25);
this.vx = constrain(this.vx, -1.8, 1.8);
this.vy = constrain(this.vy, -0.9, 0.9);
}
}
draw() {
push(); translate(this.x, this.y); scale(this.direction, 1);
noStroke();
const tailSwing = sin(this.tailWiggle) * 0.3;
fill(this.r - 25, this.g - 30, this.b - 20, this.alpha * 0.7);
const tailW = this.size * 0.55, tailH = this.size * 0.35;
push(); translate(-this.size * 0.32, 0); rotate(tailSwing);
triangle(0, 0, -tailW, -tailH, -tailW, tailH);
pop();
fill(this.r - 15, this.g - 20, this.b - 10, this.alpha * 0.55);
triangle(
-this.size * 0.05, -this.size * this.bodyRatio * 0.48,
this.size * 0.22, -this.size * this.bodyRatio * 0.58,
this.size * 0.06, -this.size * this.bodyRatio * 0.28
);
fill(this.r, this.g, this.b, this.alpha * 0.8);
ellipse(0, 0, this.size, this.size * this.bodyRatio);
fill(this.r + 35, this.g + 25, this.b + 18, this.alpha * 0.4);
ellipse(
-this.size * 0.08, -this.size * this.bodyRatio * 0.16,
this.size * 0.55, this.size * this.bodyRatio * 0.42
);
pop();
}
}

class CurtainColumn {
constructor(baseX) {
this.baseX = baseX; this.offsetX = 0; this.velocityX = 0;
this.phrase = random(wordPool);
this.scrollOffset = random(-height * 0.9, height * 0.05);
this.scrollSpeed = 0.18 + random() * 0.35;
this.charSpacing = 24 + random() * 14;
this.fontSize = 14 + random() * 7;
this.opacity = 130 + random() * 90;
this.r = 162 + random() * 22;
this.g = 198 + random() * 22;
this.b = 228 + random() * 24;
this.glowAlpha = 0; this.maxOffset = 45;
this.prevOffsetX = 0; this.trailMemory = 0;
this.shatteredIndices = new Set();
}
applyForce(force) {
this.velocityX += force;
this.glowAlpha = min(1, this.glowAlpha + abs(force) * 4);
this.offsetX = constrain(this.offsetX, -this.maxOffset, this.maxOffset);
}
update() {
this.prevOffsetX = this.offsetX;
const stiffness = 0.08, damping = 0.78;
this.velocityX = (this.velocityX - this.offsetX * stiffness) * damping;
this.offsetX += this.velocityX;
this.offsetX = constrain(this.offsetX, -this.maxOffset, this.maxOffset);
this.glowAlpha *= 0.9;
this.scrollOffset += this.scrollSpeed;
this.trailMemory = abs(this.offsetX) * 0.25 + this.trailMemory * 0.72;
const phraseLen = this.phrase.length * this.charSpacing;
if (this.scrollOffset > phraseLen + 100) {
this.scrollOffset = random(-height * 0.55, -60);
this.phrase = random(wordPool);
this.shatteredIndices.clear();
}
if (-this.scrollOffset > height + 80) {
this.scrollOffset = random(-height * 0.55, -60);
this.phrase = random(wordPool);
this.shatteredIndices.clear();
}
if (abs(this.velocityX) < 0.003 && abs(this.offsetX) < 0.3) {
this.offsetX = 0; this.velocityX = 0;
}
}
checkShatter(mx, my, ms) {
if (ms < 5) return;
const x = this.baseX + this.offsetX;
const chars = this.phrase.split('');
const startY = -this.scrollOffset;
for (let i = 0; i < chars.length; i++) {
if (this.shatteredIndices.has(i)) continue;
const y = startY + i * this.charSpacing;
if (y < -35 || y > height + 35) continue;
const d = dist(mx, my, x, y);
const threshold = this.fontSize * 0.8;
if (d < threshold) {
this.shatteredIndices.add(i);
const count = floor(random(8, 16));
for (let j = 0; j < count; j++) {
shatterParticles.push(new ShatterParticle(x, y, this.r, this.g, this.b));
}
return true;
}
}
return false;
}
draw() {
const x = this.baseX + this.offsetX;
if (x < -50 || x > width + 50) return;
const alpha = this.opacity, glowBoost = this.glowAlpha * 55;
const chars = this.phrase.split('');
const startY = -this.scrollOffset;
noStroke();
for (let i = 0; i < chars.length; i++) {
if (this.shatteredIndices.has(i)) continue;
const y = startY + i * this.charSpacing;
if (y < -35 || y > height + 35) continue;
const gr = min(255, this.r + 25), gg = min(255, this.g + 18), gb = min(255, this.b + 10);
drawingContext.shadowBlur = 7 + glowBoost;
drawingContext.shadowColor = `rgba(${gr},${gg},${gb},${(alpha + glowBoost) / 340})`;
fill(color(gr, gg, gb, alpha * 0.4 + glowBoost * 0.5));
textSize(this.fontSize);
text(chars[i], x, y);
fill(color(this.r, this.g, this.b, alpha + glowBoost));
text(chars[i], x, y);
drawingContext.shadowBlur = 0;
}
if (this.trailMemory > 1.2) {
const ctx = drawingContext;
ctx.save();
const ta = this.trailMemory * 0.25;
const grad = ctx.createLinearGradient(x - 1, 0, x + 1, 0);
grad.addColorStop(0, `rgba(${this.r + 6},${this.g + 4},${this.b + 8},0)`);
grad.addColorStop(0.4, `rgba(${this.r + 6},${this.g + 4},${this.b + 8},${ta * 0.12})`);
grad.addColorStop(0.5, `rgba(${this.r + 14},${this.g + 9},${this.b + 11},${ta * 0.18})`);
grad.addColorStop(0.6, `rgba(${this.r + 6},${this.g + 4},${this.b + 8},${ta * 0.12})`);
grad.addColorStop(1, `rgba(${this.r + 6},${this.g + 4},${this.b + 8},0)`);
ctx.fillStyle = grad;
ctx.fillRect(x - 1.5, 0, 3, height);
ctx.restore();
}
}
}

function setup() {
const canvas = createCanvas(windowWidth, windowHeight);
canvas.parent('p5-container');
canvas.class('p5canvas');
const colSpacing = 24;
for (let i = 0; i < floor(width / colSpacing) + 2; i++) columns.push(new CurtainColumn(i * colSpacing));
for (let i = 0; i < 100; i++) bgStars.push({
x: random(width), y: random(height),
size: random(0.5, 2.2), speed: random(0.08, 0.35),
opacity: random(25, 110), twinkle: random(TWO_PI),
r: 150 + random(40), g: 185 + random(35), b: 215 + random(40),
});
for (let i = 0; i < 32; i++) fishes.push(new Fish());
prevMouseX = mouseX; prevMouseY = mouseY;
textFont('Courier New'); textAlign(CENTER, CENTER);
frameRate(30); initAudio();
hintElement = document.getElementById('hint');
}

function initAudio() {
try {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
masterGain = audioCtx.createGain();
masterGain.gain.value = 0.1;
masterGain.connect(audioCtx.destination);
const unlock = () => {
if (audioCtx.state === 'suspended') audioCtx.resume();
window.removeEventListener('click', unlock);
window.removeEventListener('touchstart', unlock);
};
window.addEventListener('click', unlock);
window.addEventListener('touchstart', unlock);
scheduleNextChime();
} catch (e) {}
}

function playChime(volume = 0.12, freqOverride = null) {
if (!audioCtx || !masterGain) return;
if (audioCtx.state === 'suspended') audioCtx.resume();
const now = audioCtx.currentTime;
const freq = freqOverride || pentatonicScale[floor(random(pentatonicScale.length))];
const vol = volume * (0.7 + random() * 0.3);
const osc = audioCtx.createOscillator();
osc.type = 'triangle'; osc.frequency.value = freq;
const gain = audioCtx.createGain();
gain.gain.setValueAtTime(0, now);
gain.gain.linearRampToValueAtTime(vol, now + 0.04);
gain.gain.exponentialRampToValueAtTime(0.001, now + 1.5 + random() * 1.2);
osc.connect(gain).connect(masterGain);
osc.start(now); osc.stop(now + 2.2);
const osc2 = audioCtx.createOscillator();
osc2.type = 'sine'; osc2.frequency.value = freq * 2.0;
const gain2 = audioCtx.createGain();
gain2.gain.setValueAtTime(0, now);
gain2.gain.linearRampToValueAtTime(vol * 0.3, now + 0.06);
gain2.gain.exponentialRampToValueAtTime(0.001, now + 1.0);
osc2.connect(gain2).connect(masterGain);
osc2.start(now); osc2.stop(now + 1.6);
}

function scheduleNextChime() {
if (!audioCtx) return;
setTimeout(() => {
playChime(0.06 + random() * 0.05);
scheduleNextChime();
}, 2000 + random() * 4000);
}

function spawnRipple(x, y, maxRadius, duration, strength = 1.0) {
if (ripples.length > 40) ripples.shift();
ripples.push(new Ripple(x, y, maxRadius, duration, strength));
}

function playDolphinSound() {
if (!audioCtx || !masterGain) return;
if (audioCtx.state === 'suspended') audioCtx.resume();
const now = audioCtx.currentTime;
const duration = 0.25;
const baseFreq = 750 + Math.random() * 450;
const endFreq = baseFreq * 1.6;
const osc = audioCtx.createOscillator();
osc.type = 'sine';
osc.frequency.setValueAtTime(baseFreq, now);
osc.frequency.linearRampToValueAtTime(endFreq, now + duration);
const gain = audioCtx.createGain();
gain.gain.setValueAtTime(0, now);
gain.gain.linearRampToValueAtTime(0.18, now + 0.02);
gain.gain.exponentialRampToValueAtTime(0.001, now + duration);
osc.connect(gain).connect(masterGain);
osc.start(now); osc.stop(now + duration);
const osc2 = audioCtx.createOscillator();
osc2.type = 'sine';
osc2.frequency.setValueAtTime(baseFreq * 2.1, now);
osc2.frequency.linearRampToValueAtTime(endFreq * 2.1, now + duration);
const gain2 = audioCtx.createGain();
gain2.gain.setValueAtTime(0, now);
gain2.gain.linearRampToValueAtTime(0.08, now + 0.02);
gain2.gain.exponentialRampToValueAtTime(0.001, now + duration);
osc2.connect(gain2).connect(masterGain);
osc2.start(now); osc2.stop(now + duration);
}

function playShatterSound() {
if (!audioCtx || !masterGain) return;
if (audioCtx.state === 'suspended') audioCtx.resume();
const now = audioCtx.currentTime;
const duration = 0.12;
const osc = audioCtx.createOscillator();
osc.type = 'triangle';
osc.frequency.setValueAtTime(1200 + random() * 400, now);
osc.frequency.exponentialRampToValueAtTime(300, now + duration);
const gain = audioCtx.createGain();
gain.gain.setValueAtTime(0, now);
gain.gain.linearRampToValueAtTime(0.06, now + 0.01);
gain.gain.exponentialRampToValueAtTime(0.001, now + duration);
const filter = audioCtx.createBiquadFilter();
filter.type = 'bandpass';
filter.frequency.value = 2000; filter.Q.value = 0.8;
osc.connect(filter).connect(gain).connect(masterGain);
osc.start(now); osc.stop(now + duration);
}

function draw() {
clear();
for (let star of bgStars) {
star.twinkle += 0.015;
noStroke();
fill(star.r, star.g, star.b, star.opacity + sin(star.twinkle) * 22);
circle(star.x, star.y, star.size);
star.y -= star.speed;
if (star.y < -10) { star.y = height + 10; star.x = random(width); }
}
const ctxWater = drawingContext;
ctxWater.save();
for (let y = 0; y < height; y += 4) {
let wv = sin(y * 0.018 + frameCount * 0.022) * 0.45
+ sin(y * 0.027 - frameCount * 0.016 + 1.7) * 0.35;
wv += cos(y * 0.009 + frameCount * 0.011 + 3.1) * 0.28
+ sin(y * 0.035 + frameCount * 0.028 + 5.4) * 0.2;
const a = constrain((wv + 1.28) * 4.5, 0, 13);
if (a > 0.4) {
ctxWater.fillStyle = `rgba(175,210,240,${a / 255})`;
ctxWater.fillRect(0, y, width, 3.5);
}
}
ctxWater.restore();
for (let i = ripples.length - 1; i >= 0; i--) {
ripples[i].update();
if (!ripples[i].isAlive()) ripples.splice(i, 1);
}
for (let r of ripples) r.draw();
for (let fish of fishes) { fish.update(); fish.draw(); }

const dx = mouseX - prevMouseX, dy = mouseY - prevMouseY;
mouseSpeed = sqrt(dx * dx + dy * dy);
prevMouseX = mouseX; prevMouseY = mouseY;

let shatteredThisFrame = false;
if (mouseSpeed > 5 && mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
for (let col of columns) {
if (col.checkShatter(mouseX, mouseY, mouseSpeed)) shatteredThisFrame = true;
}
}
if (shatteredThisFrame && random() < 0.5) playShatterSound();

if (mouseSpeed > 2 && mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
let ci = 0, cd = Infinity;
for (let i = 0; i < columns.length; i++) {
const d = abs(columns[i].baseX - mouseX);
if (d < cd) { cd = d; ci = i; }
}
if (cd < 130) {
const f = (dx / (cd + 12)) * 0.55;
columns[ci].applyForce(f);
for (let j = 1; j <= 8; j++) {
const decay = 1 - j / 9;
if (ci - j >= 0) columns[ci - j].applyForce(f * decay * 0.6);
if (ci + j < columns.length) columns[ci + j].applyForce(f * decay * 0.6);
}
if (mouseSpeed > 8 && random() < 0.35)
spawnRipple(mouseX, mouseY, 35 + random() * 55, floor(35 + random() * 40), 0.7 + random() * 0.3);
if (mouseSpeed > 14 && random() < 0.3) playChime(0.1 + random() * 0.07);
}
if (mouseSpeed > 10 && random() < 0.25 && cd >= 130)
spawnRipple(mouseX, mouseY, 25 + random() * 40, floor(28 + random() * 35), 0.5 + random() * 0.3);
}

breezeTimer++;
if (breezeTimer > breezeInterval) {
breezeTimer = 0;
breezeInterval = 60 + floor(random() * 180);
const rc = floor(random(columns.length));
const bf = (random() - 0.5) * 0.4;
columns[rc].applyForce(bf);
if (rc > 0) columns[rc - 1].applyForce(bf * 0.5);
if (rc < columns.length - 1) columns[rc + 1].applyForce(bf * 0.5);
if (random() < 0.35)
spawnRipple(columns[rc].baseX, height * 0.45 + random() * height * 0.4,
20 + random() * 35, floor(35 + random() * 45), 0.35 + random() * 0.25);
}

for (let col of columns) col.update();
for (let col of columns) col.draw();

for (let i = shatterParticles.length - 1; i >= 0; i--) {
shatterParticles[i].update();
if (!shatterParticles[i].isAlive()) shatterParticles.splice(i, 1);
}
for (let sp of shatterParticles) sp.draw();

const ctxBottom = drawingContext;
ctxBottom.save();
for (let i = 0; i < 5; i++) {
const by = height - 55 + i * 16 + sin(frameCount * 0.012 + i * 1.8) * 14;
const a = 4 + sin(frameCount * 0.008 + i * 1.2) * 3 + i * 1.5;
const grad = ctxBottom.createLinearGradient(0, by - 8, 0, by + 10);
grad.addColorStop(0, `rgba(160,200,230,0)`);
grad.addColorStop(0.4, `rgba(160,200,230,${a / 255})`);
grad.addColorStop(0.6, `rgba(175,210,238,${a / 255})`);
grad.addColorStop(1, `rgba(150,195,225,0)`);
ctxBottom.fillStyle = grad;
ctxBottom.fillRect(0, by - 8, width, 20);
}
ctxBottom.restore();
const ctxTop = drawingContext;
ctxTop.save();
const topGrad = ctxTop.createLinearGradient(0, 0, 0, 65);
topGrad.addColorStop(0, `rgba(140,190,225,0.06)`);
topGrad.addColorStop(1, `rgba(140,190,225,0)`);
ctxTop.fillStyle = topGrad;
ctxTop.fillRect(0, 0, width, 65);
ctxTop.restore();

if (hintElement && hintAlpha > 0.01) {
hintFadeTimer++;
if (hintFadeTimer > 300) {
hintAlpha = max(0, hintAlpha - 0.012);
hintElement.style.opacity = hintAlpha;
}
if (mouseSpeed > 3 && hintFadeTimer > 120) {
hintAlpha = max(0, hintAlpha - 0.03);
hintElement.style.opacity = hintAlpha;
}
}
}

function windowResized() {
resizeCanvas(windowWidth, windowHeight);
columns = [];
const cs = 24;
for (let i = 0; i < floor(width / cs) + 2; i++) columns.push(new CurtainColumn(i * cs));
bgStars = [];
for (let i = 0; i < 100; i++) bgStars.push({
x: random(width), y: random(height),
size: random(0.5, 2.2), speed: random(0.08, 0.35),
opacity: random(25, 110), twinkle: random(TWO_PI),
r: 150 + random(40), g: 185 + random(35), b: 215 + random(40),
});
ripples = []; fishes = []; shatterParticles = [];
for (let i = 0; i < 32; i++) fishes.push(new Fish());
}

function mousePressed() {
if (audioCtx && audioCtx.state === 'suspended') audioCtx.resume();
if (window.orcaScreenX && window.orcaScreenY && window.orcaScale) {
const distToOrca = dist(mouseX, mouseY, window.orcaScreenX, window.orcaScreenY);
const threshold = 55 * (window.orcaScale / 0.28);
if (distToOrca < threshold) { playDolphinSound(); return; }
}
let ci = 0, cd = Infinity;
for (let i = 0; i < columns.length; i++) {
const d = abs(columns[i].baseX - mouseX);
if (d < cd) { cd = d; ci = i; }
}
if (cd < 140) {
columns[ci].applyForce(random() > 0.5 ? 0.8 : -0.8);
for (let j = 1; j <= 6; j++) {
const decay = 1 - j / 7;
if (ci - j >= 0) columns[ci - j].applyForce((random() - 0.5) * 0.7 * decay);
if (ci + j < columns.length) columns[ci + j].applyForce((random() - 0.5) * 0.7 * decay);
}
playChime(0.16);
if (random() < 0.5) setTimeout(() => playChime(0.1), 150 + random() * 200);
spawnRipple(mouseX, mouseY, 55 + random() * 70, floor(50 + random() * 40), 0.85 + random() * 0.15);
if (random() < 0.4) setTimeout(() => spawnRipple(
mouseX + (random() - 0.5) * 20, mouseY + (random() - 0.5) * 20,
35 + random() * 45, floor(35 + random() * 30), 0.5 + random() * 0.3
), 120 + random() * 180);
} else spawnRipple(mouseX, mouseY, 45 + random() * 65, floor(45 + random() * 40), 0.7 + random() * 0.3);
}

function touchStarted() {
if (audioCtx && audioCtx.state === 'suspended') audioCtx.resume();
if (window.orcaScreenX && window.orcaScreenY && window.orcaScale) {
const distToOrca = dist(mouseX, mouseY, window.orcaScreenX, window.orcaScreenY);
const threshold = 55 * (window.orcaScale / 0.28);
if (distToOrca < threshold) { playDolphinSound(); return false; }
}
spawnRipple(mouseX, mouseY, 50 + random() * 60, floor(45 + random() * 38), 0.75 + random() * 0.25);
return false;
}
</script>
<div id="p5-container"></div>
</body>
</html>

写在最后

这个页面没有复杂的业务逻辑,就是视觉和交互。做完之后自己玩了好几分钟,挺治愈的。

如果你也喜欢这种”打开浏览器就能看到一点小惊喜”的东西,可以把源码存下来,改改词库,换成自己喜欢的句子。

Vibe Coding 的意义就在这里——不是为了解决什么技术难题,而是用代码创造一点点美。DeepSeek 帮你把想法变成现实,你只需要告诉它你想要什么感觉。