-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsections.js
More file actions
3028 lines (2675 loc) · 93.1 KB
/
sections.js
File metadata and controls
3028 lines (2675 loc) · 93.1 KB
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
// sections.js — Canvas animations and interactivity for Hack X sections
(function () {
"use strict";
// Visibility-aware rAF: pauses canvas animations when their section is off-screen
var _visMap = new Map();
var _visObs = new IntersectionObserver(function(entries) {
entries.forEach(function(e) { _visMap.set(e.target, e.isIntersecting); });
}, { rootMargin: '100px' });
function visibleRAF(sectionEl, drawFn) {
if (!_visMap.has(sectionEl)) {
_visMap.set(sectionEl, false);
_visObs.observe(sectionEl);
}
function loop() {
if (_visMap.get(sectionEl)) {
drawFn();
}
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
}
const RED = "#4fd1d9";
const DARK = "#0a1628";
const RED_RGB = [79, 209, 217];
const CRT_CURVATURE = 4.5; // lower = curvier
const CURSOR_BG = DARK;
const CURSOR_FG = RED;
const CURSOR_STROKE_PX = 3;
const CURSOR_SCALE = 1.2;
const CURSOR_ROT = -Math.PI / 5;
const CURSOR_OFFSET = 10;
function shouldUseCrtCurvature() {
// Reuse the project's canonical detector from `utils.js` when available.
if (typeof window.isTouchScreenDevice === "function") {
return !window.isTouchScreenDevice();
}
// Fallback: avoid disabling on desktops that expose touch APIs.
const coarsePointer =
window.matchMedia && window.matchMedia("(pointer:coarse)").matches;
return !coarsePointer;
}
function shouldUseCustomCursor() {
// Skip on touch/coarse pointer devices.
if (typeof window.isTouchScreenDevice === "function") {
return !window.isTouchScreenDevice();
}
const coarsePointer =
window.matchMedia && window.matchMedia("(pointer:coarse)").matches;
return !coarsePointer;
}
function initGlobalCustomCursor() {
if (!shouldUseCustomCursor()) return;
const cursorCanvas = document.createElement("canvas");
cursorCanvas.id = "global-custom-cursor";
cursorCanvas.style.cssText = `
position: fixed;
top: 0; left: 0;
width: 100vw; height: 100vh;
z-index: 9998;
pointer-events: none;
`;
document.body.appendChild(cursorCanvas);
const ctx = cursorCanvas.getContext("2d");
if (!ctx) {
cursorCanvas.remove();
return;
}
function resize() {
const dpr = window.devicePixelRatio || 1;
cursorCanvas.width = Math.max(1, Math.floor(window.innerWidth * dpr));
cursorCanvas.height = Math.max(1, Math.floor(window.innerHeight * dpr));
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
resize();
window.addEventListener("resize", resize);
let mouseX = -9999;
let mouseY = -9999;
let hide = false;
function isInsideHero(x, y) {
const hero = document.getElementById("hero-section");
if (!hero) return false;
const r = hero.getBoundingClientRect();
return x >= r.left && x <= r.right && y >= r.top && y <= r.bottom;
}
window.addEventListener(
"mousemove",
(e) => {
mouseX = e.clientX;
mouseY = e.clientY;
hide = isInsideHero(mouseX, mouseY);
},
{ passive: true },
);
window.addEventListener(
"mouseleave",
() => {
mouseX = -9999;
mouseY = -9999;
},
{ passive: true },
);
function draw() {
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
if (!hide && mouseX >= 0 && mouseY >= 0) {
ctx.save();
ctx.translate(mouseX + CURSOR_OFFSET, mouseY + CURSOR_OFFSET);
ctx.scale(CURSOR_SCALE, CURSOR_SCALE);
ctx.rotate(CURSOR_ROT);
ctx.fillStyle = CURSOR_BG;
ctx.strokeStyle = CURSOR_FG;
ctx.lineWidth = CURSOR_STROKE_PX;
ctx.beginPath();
ctx.moveTo(0, -10);
ctx.lineTo(7.5, 10);
ctx.lineTo(0, 5);
ctx.lineTo(-7.5, 10);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.restore();
}
requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
}
function initGlobalCrtCurvatureForSectionCanvases() {
if (!shouldUseCrtCurvature()) return;
// Signal to the p5 layer that global CRT is active (so it can skip its own CRT pass).
window.__HACKX_GLOBAL_CRT__ = true;
let sourceCanvases = [];
function collectSourceCanvases() {
// Include the p5 hero canvas too so the curvature feels like one continuous screen.
const all = Array.from(
document.querySelectorAll(".section canvas, #footer-section canvas"),
).filter((c) => !(c instanceof HTMLCanvasElement ? c.classList.contains("crt-global-canvas") : false));
sourceCanvases = all;
sourceCanvases.forEach((c) => {
// Hide all source canvases; the global CRT canvas will draw them instead.
if (!c.classList.contains("crt-global-canvas")) c.style.opacity = "0";
});
}
collectSourceCanvases();
const glCanvas = document.createElement("canvas");
glCanvas.className = "crt-global-canvas";
glCanvas.style.cssText = `
position: fixed;
top: 0; left: 0;
width: 100vw; height: 100vh;
z-index: 0;
pointer-events: none;
`;
document.body.appendChild(glCanvas);
const gl =
glCanvas.getContext("webgl", {
alpha: true,
antialias: false,
premultipliedAlpha: true,
preserveDrawingBuffer: false,
}) || glCanvas.getContext("experimental-webgl");
if (!gl) {
glCanvas.remove();
return;
}
// If canvases are created after DOMContentLoaded (p5 does this), observe and collect.
const observer = new MutationObserver(() => collectSourceCanvases());
observer.observe(document.body, { childList: true, subtree: true });
const composeCanvas = document.createElement("canvas");
const composeCtx = composeCanvas.getContext("2d", { alpha: true });
// Keep UI (game text/boxes) crisp when compositing/scaling.
composeCtx.imageSmoothingEnabled = false;
const vertSrc = `
attribute vec2 a_pos;
varying vec2 v_uv;
void main() {
v_uv = (a_pos + 1.0) * 0.5;
gl_Position = vec4(a_pos, 0.0, 1.0);
}
`;
const fragSrc = `
precision mediump float;
varying vec2 v_uv;
uniform sampler2D u_tex;
uniform vec2 u_curvature;
vec2 curveRemapUV(vec2 uv) {
uv = uv * 2.0 - 1.0;
vec2 offset = abs(uv.yx) / u_curvature;
uv = uv + uv * offset * offset;
uv = uv * 0.5 + 0.5;
return uv;
}
void main() {
vec2 uv = v_uv;
vec2 remappedUV = curveRemapUV(uv);
if (remappedUV.x < 0.0 || remappedUV.y < 0.0 || remappedUV.x > 1.0 || remappedUV.y > 1.0) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
return;
}
gl_FragColor = texture2D(u_tex, remappedUV);
}
`;
function compileShader(type, src) {
const s = gl.createShader(type);
gl.shaderSource(s, src);
gl.compileShader(s);
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {
gl.deleteShader(s);
return null;
}
return s;
}
function createProgram(vsSrc, fsSrc) {
const vs = compileShader(gl.VERTEX_SHADER, vsSrc);
const fs = compileShader(gl.FRAGMENT_SHADER, fsSrc);
if (!vs || !fs) return null;
const p = gl.createProgram();
gl.attachShader(p, vs);
gl.attachShader(p, fs);
gl.linkProgram(p);
gl.deleteShader(vs);
gl.deleteShader(fs);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
gl.deleteProgram(p);
return null;
}
return p;
}
const program = createProgram(vertSrc, fragSrc);
if (!program) {
glCanvas.remove();
sourceCanvases.forEach((c) => (c.style.opacity = ""));
return;
}
const quad = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.bufferData(
gl.ARRAY_BUFFER,
new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]),
gl.STATIC_DRAW,
);
const aPos = gl.getAttribLocation(program, "a_pos");
const uTex = gl.getUniformLocation(program, "u_tex");
const uCurv = gl.getUniformLocation(program, "u_curvature");
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Nearest-neighbor to avoid blurring pixel-ish UI.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
function resize() {
const dpr = window.devicePixelRatio || 1;
const w = Math.max(1, Math.floor(window.innerWidth * dpr));
const h = Math.max(1, Math.floor(window.innerHeight * dpr));
glCanvas.width = w;
glCanvas.height = h;
composeCanvas.width = w;
composeCanvas.height = h;
gl.viewport(0, 0, w, h);
}
resize();
window.addEventListener("resize", resize);
let lastFrame = 0;
const minFrameMs = 1000 / 30; // cap at ~30fps for perf
const FLAT_CURVATURE = 10000.0;
function draw(now) {
if (now - lastFrame < minFrameMs) {
requestAnimationFrame(draw);
return;
}
lastFrame = now;
// Fade curvature to flat as the footer enters the viewport.
// t = 0 -> full curvature, t = 1 -> flat.
let t = 0;
const footer = document.getElementById("footer-section");
if (footer) {
const r = footer.getBoundingClientRect();
const fadeStart = window.innerHeight * 0.65;
const fadeEnd = window.innerHeight * 0.15;
if (r.top < fadeStart) {
t = Math.min(1, Math.max(0, (fadeStart - r.top) / (fadeStart - fadeEnd)));
}
}
const curv = CRT_CURVATURE + (FLAT_CURVATURE - CRT_CURVATURE) * t;
// Composite all section canvases into one viewport-sized canvas in screen space.
composeCtx.clearRect(0, 0, composeCanvas.width, composeCanvas.height);
composeCtx.fillStyle = DARK;
composeCtx.fillRect(0, 0, composeCanvas.width, composeCanvas.height);
const dpr = window.devicePixelRatio || 1;
for (const c of sourceCanvases) {
if (!c || c === glCanvas) continue;
const rect = c.getBoundingClientRect();
if (rect.width <= 1 || rect.height <= 1) continue;
if (rect.bottom < 0 || rect.top > window.innerHeight) continue;
const dx = rect.left * dpr;
const dy = rect.top * dpr;
const dw = rect.width * dpr;
const dh = rect.height * dpr;
try {
composeCtx.drawImage(c, dx, dy, dw, dh);
} catch {
// Ignore transient drawImage failures (e.g., zero-sized during layout).
}
}
// Upload composed viewport to WebGL texture and curve it once.
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
composeCanvas,
);
gl.useProgram(program);
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.enableVertexAttribArray(aPos);
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.uniform1i(uTex, 0);
gl.uniform2f(uCurv, curv, curv);
gl.drawArrays(gl.TRIANGLES, 0, 6);
requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
}
document.addEventListener("DOMContentLoaded", init);
function init() {
// Canvas backgrounds (performant, GPU-accelerated)
initAboutCanvas();
initNexusCanvas();
initSpectraCanvas();
initPrizesCanvas();
initFooterCanvas();
// Core (one-time CSS transitions, no jank)
initScrollFadeIn();
initTimelineLineDraw();
initPrizeCounters();
// initScrollProgressBar(); // removed — was showing blue line at top
initAnnouncements();
// Clean interactions (pure CSS, no rAF loops)
initHoverLineTrace();
initRevealOnScroll();
initFaqAccessibility();
initTeamGrid();
initPerksBgCanvas();
// Easter eggs (hidden, zero perf cost until triggered)
initTripleClick();
initFooterCopyrightHover();
initCodecellMatrix();
initBottomMessage();
initTenFireworks();
initTrackTagFlash();
initIdleMessage();
initMusicDanceExperience();
initGlobalCrtCurvatureForSectionCanvases();
initGlobalCustomCursor();
// Lock model-viewer orbit target so clicks/taps can't shift the origin,
// and add a point light at the top-right of the model.
const mv = document.querySelector("model-viewer.about-model");
if (mv) {
mv.addEventListener("load", () => {
const locked = mv.getCameraTarget();
const lockedStr = `${locked.x}m ${locked.y}m ${locked.z}m`;
mv.addEventListener("camera-change", () => {
const cur = mv.getCameraTarget();
if (cur.x !== locked.x || cur.y !== locked.y || cur.z !== locked.z) {
mv.cameraTarget = lockedStr;
}
});
});
}
}
// ===== LENIS SMOOTH SCROLL =====
function initLenis() {
if (typeof Lenis === "undefined") return;
const lenis = new Lenis({
duration: 2.2,
easing: (t) => 1 - Math.pow(1 - t, 4),
orientation: "vertical",
smoothWheel: true,
wheelMultiplier: 0.7,
touchMultiplier: 1.5,
});
function raf(time) {
lenis.raf(time);
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", (e) => {
e.preventDefault();
const target = document.querySelector(anchor.getAttribute("href"));
if (target) lenis.scrollTo(target);
});
});
}
// ===== ABOUT: FaultyTerminal (CRT scanline squares + flicker) =====
function initAboutCanvas() {
const canvas = document.getElementById("about-canvas");
if (!canvas) return;
const fallback2D = () => {
const ctx = canvas.getContext("2d");
if (!ctx) return;
const chars =
"01アカサタナハマヤラワ{}[]<>/\\|=+-*&^%$#@!HACKXCODECEL";
let drops = [];
let columns = 0;
function resize2D() {
canvas.width = canvas.parentElement.offsetWidth;
canvas.height = canvas.parentElement.offsetHeight;
columns = Math.floor(canvas.width / 14);
drops = new Array(columns).fill(1);
}
function draw2D() {
ctx.fillStyle = "rgba(10, 22, 40, 0.04)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(79, 209, 217, 0.12)";
ctx.font = "12px Courier New";
for (let i = 0; i < drops.length; i++) {
const char = chars[Math.floor(Math.random() * chars.length)];
ctx.fillText(char, i * 14, drops[i] * 14);
if (drops[i] * 14 > canvas.height && Math.random() > 0.985)
drops[i] = 0;
if (Math.random() > 0.3) drops[i]++;
}
}
resize2D();
window.addEventListener("resize", resize2D);
visibleRAF(canvas.closest('.section') || canvas.parentElement, draw2D);
};
// WebGL renderer (no React/ogl dependency): port of FaultyTerminal shaders.
const gl =
canvas.getContext("webgl", {
alpha: true,
antialias: false,
premultipliedAlpha: true,
}) || canvas.getContext("experimental-webgl");
if (!gl) return fallback2D();
const vertexShader = `
attribute vec2 position;
attribute vec2 uv;
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
varying vec2 vUv;
uniform float iTime;
uniform vec3 iResolution;
uniform float uScale;
uniform vec2 uGridMul;
uniform float uDigitSize;
uniform float uScanlineIntensity;
uniform float uGlitchAmount;
uniform float uFlickerAmount;
uniform float uNoiseAmp;
uniform float uChromaticAberration;
uniform float uDither;
uniform float uCurvature;
uniform vec3 uTint;
uniform vec2 uMouse;
uniform float uMouseStrength;
uniform float uUseMouse;
uniform float uPageLoadProgress;
uniform float uUsePageLoadAnimation;
uniform float uBrightness;
float time;
float hash21(vec2 p){
p = fract(p * 234.56);
p += dot(p, p + 34.56);
return fract(p.x * p.y);
}
float noise(vec2 p)
{
return sin(p.x * 10.0) * sin(p.y * (3.0 + sin(time * 0.090909))) + 0.2;
}
mat2 rotate(float angle)
{
float c = cos(angle);
float s = sin(angle);
return mat2(c, -s, s, c);
}
float fbm(vec2 p)
{
p *= 1.1;
float f = 0.0;
float amp = 0.5 * uNoiseAmp;
mat2 modify0 = rotate(time * 0.02);
f += amp * noise(p);
p = modify0 * p * 2.0;
amp *= 0.454545;
mat2 modify1 = rotate(time * 0.02);
f += amp * noise(p);
p = modify1 * p * 2.0;
amp *= 0.454545;
mat2 modify2 = rotate(time * 0.08);
f += amp * noise(p);
return f;
}
float pattern(vec2 p, out vec2 q, out vec2 r) {
vec2 offset1 = vec2(1.0);
vec2 offset0 = vec2(0.0);
mat2 rot01 = rotate(0.1 * time);
mat2 rot1 = rotate(0.1);
q = vec2(fbm(p + offset1), fbm(rot01 * p + offset1));
r = vec2(fbm(rot1 * q + offset0), fbm(q + offset0));
return fbm(p + r);
}
float digit(vec2 p){
vec2 grid = uGridMul * 15.0;
vec2 s = floor(p * grid) / grid;
p = p * grid;
vec2 q, r;
float intensity = pattern(s * 0.1, q, r) * 1.3 - 0.03;
if(uUseMouse > 0.5){
vec2 mouseWorld = uMouse * uScale;
float distToMouse = distance(s, mouseWorld);
float mouseInfluence = exp(-distToMouse * 8.0) * uMouseStrength * 10.0;
intensity += mouseInfluence;
float ripple = sin(distToMouse * 20.0 - iTime * 5.0) * 0.1 * mouseInfluence;
intensity += ripple;
}
if(uUsePageLoadAnimation > 0.5){
float cellRandom = fract(sin(dot(s, vec2(12.9898, 78.233))) * 43758.5453);
float cellDelay = cellRandom * 0.8;
float cellProgress = clamp((uPageLoadProgress - cellDelay) / 0.2, 0.0, 1.0);
float fadeAlpha = smoothstep(0.0, 1.0, cellProgress);
intensity *= fadeAlpha;
}
p = fract(p);
p *= uDigitSize;
float px5 = p.x * 5.0;
float py5 = (1.0 - p.y) * 5.0;
float x = fract(px5);
float y = fract(py5);
float i = floor(py5) - 2.0;
float j = floor(px5) - 2.0;
float n = i * i + j * j;
float f = n * 0.0625;
float isOn = step(0.1, intensity - f);
float brightness = isOn * (0.2 + y * 0.8) * (0.75 + x * 0.25);
return step(0.0, p.x) * step(p.x, 1.0) * step(0.0, p.y) * step(p.y, 1.0) * brightness;
}
float onOff(float a, float b, float c)
{
return step(c, sin(iTime + a * cos(iTime * b))) * uFlickerAmount;
}
float displace(vec2 look)
{
float y = look.y - mod(iTime * 0.25, 1.0);
float window = 1.0 / (1.0 + 50.0 * y * y);
return sin(look.y * 20.0 + iTime) * 0.0125 * onOff(4.0, 2.0, 0.8) * (1.0 + cos(iTime * 60.0)) * window;
}
vec3 getColor(vec2 p){
float bar = step(mod(p.y + time * 20.0, 1.0), 0.2) * 0.4 + 1.0;
bar *= uScanlineIntensity;
float displacement = displace(p);
p.x += displacement;
if (uGlitchAmount != 1.0) {
float extra = displacement * (uGlitchAmount - 1.0);
p.x += extra;
}
float middle = digit(p);
const float off = 0.002;
float sum = digit(p + vec2(-off, -off)) + digit(p + vec2(0.0, -off)) + digit(p + vec2(off, -off)) +
digit(p + vec2(-off, 0.0)) + digit(p + vec2(0.0, 0.0)) + digit(p + vec2(off, 0.0)) +
digit(p + vec2(-off, off)) + digit(p + vec2(0.0, off)) + digit(p + vec2(off, off));
vec3 baseColor = vec3(0.9) * middle + sum * 0.1 * vec3(1.0) * bar;
return baseColor;
}
vec2 barrel(vec2 uv){
vec2 c = uv * 2.0 - 1.0;
float r2 = dot(c, c);
c *= 1.0 + uCurvature * r2;
return c * 0.5 + 0.5;
}
void main() {
time = iTime * 0.333333;
vec2 uv = vUv;
if(uCurvature != 0.0){
uv = barrel(uv);
}
vec2 p = uv * uScale;
vec3 col = getColor(p);
if(uChromaticAberration != 0.0){
vec2 ca = vec2(uChromaticAberration) / iResolution.xy;
col.r = getColor(p + ca).r;
col.b = getColor(p - ca).b;
}
col *= uTint;
col *= uBrightness;
if(uDither > 0.0){
float rnd = hash21(gl_FragCoord.xy);
col += (rnd - 0.5) * (uDither * 0.003922);
}
// Output transparency so this canvas doesn't become an opaque black overlay
// when multiple section canvases overlap during scroll.
float a = clamp(max(col.r, max(col.g, col.b)), 0.0, 1.0);
gl_FragColor = vec4(col, a);
}
`;
function compileShader(type, src) {
const sh = gl.createShader(type);
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) {
const log = gl.getShaderInfoLog(sh);
gl.deleteShader(sh);
throw new Error(log || "Shader compile failed");
}
return sh;
}
function createProgram(vsSrc, fsSrc) {
const vs = compileShader(gl.VERTEX_SHADER, vsSrc);
const fs = compileShader(gl.FRAGMENT_SHADER, fsSrc);
const p = gl.createProgram();
gl.attachShader(p, vs);
gl.attachShader(p, fs);
gl.linkProgram(p);
gl.deleteShader(vs);
gl.deleteShader(fs);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
const log = gl.getProgramInfoLog(p);
gl.deleteProgram(p);
throw new Error(log || "Program link failed");
}
return p;
}
function hexToRgb01(hex) {
let h = String(hex || "").trim().replace("#", "");
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
const num = parseInt(h, 16);
return [(num >> 16 & 255) / 255, (num >> 8 & 255) / 255, (num & 255) / 255];
}
let program;
try {
program = createProgram(vertexShader, fragmentShader);
} catch {
return fallback2D();
}
const quad = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
// Interleaved: position(x,y), uv(u,v)
const data = new Float32Array([
-1, -1, 0, 0,
1, -1, 1, 0,
-1, 1, 0, 1,
-1, 1, 0, 1,
1, -1, 1, 0,
1, 1, 1, 1,
]);
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
const aPos = gl.getAttribLocation(program, "position");
const aUv = gl.getAttribLocation(program, "uv");
const u = {
iTime: gl.getUniformLocation(program, "iTime"),
iResolution: gl.getUniformLocation(program, "iResolution"),
uScale: gl.getUniformLocation(program, "uScale"),
uGridMul: gl.getUniformLocation(program, "uGridMul"),
uDigitSize: gl.getUniformLocation(program, "uDigitSize"),
uScanlineIntensity: gl.getUniformLocation(program, "uScanlineIntensity"),
uGlitchAmount: gl.getUniformLocation(program, "uGlitchAmount"),
uFlickerAmount: gl.getUniformLocation(program, "uFlickerAmount"),
uNoiseAmp: gl.getUniformLocation(program, "uNoiseAmp"),
uChromaticAberration: gl.getUniformLocation(program, "uChromaticAberration"),
uDither: gl.getUniformLocation(program, "uDither"),
uCurvature: gl.getUniformLocation(program, "uCurvature"),
uTint: gl.getUniformLocation(program, "uTint"),
uMouse: gl.getUniformLocation(program, "uMouse"),
uMouseStrength: gl.getUniformLocation(program, "uMouseStrength"),
uUseMouse: gl.getUniformLocation(program, "uUseMouse"),
uPageLoadProgress: gl.getUniformLocation(program, "uPageLoadProgress"),
uUsePageLoadAnimation: gl.getUniformLocation(program, "uUsePageLoadAnimation"),
uBrightness: gl.getUniformLocation(program, "uBrightness"),
};
const dprCap = 2;
let dpr = Math.min(window.devicePixelRatio || 1, dprCap);
// Match the snippet defaults used in your pasted code.
const params = {
scale: 1.5,
gridMul: [2, 1],
digitSize: 1.2,
timeScale: 0.5,
pause: false,
scanlineIntensity: 0.5,
glitchAmount: 1,
flickerAmount: 1,
noiseAmp: 1,
chromaticAberration: 0,
dither: 0,
curvature: 0, // avoid double-curving (global CRT pass handles it)
tint: "#4fd1d9",
mouseReact: false,
mouseStrength: 0.5,
pageLoadAnimation: true,
brightness: 0.15,
};
let mouse = { x: 0.5, y: 0.5 };
let useMouse = 0;
if (typeof window !== "undefined" && typeof window.isTouchScreenDevice === "function") {
useMouse = window.isTouchScreenDevice() ? 0 : 1;
} else {
const coarsePointer =
window.matchMedia && window.matchMedia("(pointer:coarse)").matches;
useMouse = coarsePointer ? 0 : 1;
}
useMouse = useMouse && params.mouseReact ? 1 : 0;
let loadStart = 0;
let timeOffset = Math.random() * 100;
function resize() {
dpr = Math.min(window.devicePixelRatio || 1, dprCap);
canvas.width = Math.max(1, Math.floor(canvas.parentElement.offsetWidth * dpr));
canvas.height = Math.max(1, Math.floor(canvas.parentElement.offsetHeight * dpr));
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 0, 0);
gl.useProgram(program);
gl.uniform3f(u.iResolution, canvas.width, canvas.height, canvas.width / canvas.height);
gl.uniform1f(u.uScale, params.scale);
gl.uniform2f(u.uGridMul, params.gridMul[0], params.gridMul[1]);
gl.uniform1f(u.uDigitSize, params.digitSize);
gl.uniform1f(u.uScanlineIntensity, params.scanlineIntensity);
gl.uniform1f(u.uGlitchAmount, params.glitchAmount);
gl.uniform1f(u.uFlickerAmount, params.flickerAmount);
gl.uniform1f(u.uNoiseAmp, params.noiseAmp);
gl.uniform1f(u.uChromaticAberration, params.chromaticAberration);
gl.uniform1f(u.uDither, params.dither);
gl.uniform1f(u.uCurvature, params.curvature);
const tintRGB = hexToRgb01(params.tint);
gl.uniform3f(u.uTint, tintRGB[0], tintRGB[1], tintRGB[2]);
gl.uniform1f(u.uMouseStrength, params.mouseStrength);
gl.uniform1f(u.uUseMouse, useMouse);
gl.uniform1f(u.uUsePageLoadAnimation, params.pageLoadAnimation ? 1 : 0);
gl.uniform1f(u.uBrightness, params.brightness);
}
function draw(now) {
if (!loadStart && params.pageLoadAnimation) loadStart = now;
const t = (now * 0.001 + timeOffset) * params.timeScale;
gl.useProgram(program);
gl.uniform1f(u.iTime, params.pause ? t : t);
gl.uniform2f(u.uMouse, mouse.x, mouse.y);
if (params.pageLoadAnimation) {
const progress = Math.min((now - loadStart) / 2000, 1);
gl.uniform1f(u.uPageLoadProgress, progress);
} else {
gl.uniform1f(u.uPageLoadProgress, 1);
}
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
const stride = 16; // 4 floats * 4 bytes
gl.enableVertexAttribArray(aPos);
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, stride, 0);
gl.enableVertexAttribArray(aUv);
gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, stride, 8);
gl.drawArrays(gl.TRIANGLES, 0, 6);
}
function onMove(e) {
const rect = canvas.getBoundingClientRect();
const x = (e.clientX - rect.left) / rect.width;
const y = 1 - (e.clientY - rect.top) / rect.height;
mouse.x = x;
mouse.y = y;
}
canvas.addEventListener("mousemove", onMove, { passive: true });
resize();
window.addEventListener("resize", resize);
visibleRAF(canvas.closest('.section') || canvas.parentElement, draw);
}
// ===== NEXUS: Neural Network Nodes =====
function initNexusCanvas() {
const canvas = document.getElementById("nexus-canvas");
if (!canvas) return;
const ctx = canvas.getContext("2d");
let nodes = [];
const NODE_COUNT = 25;
function resize() {
canvas.width = canvas.parentElement.offsetWidth;
canvas.height = canvas.parentElement.offsetHeight;
nodes = [];
for (let i = 0; i < NODE_COUNT; i++) {
nodes.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
radius: Math.random() * 3 + 1,
pulse: Math.random() * Math.PI * 2,
});
}
}
function draw() {
ctx.fillStyle = "rgba(10, 22, 40, 0.15)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < nodes.length; i++) {
for (let j = i + 1; j < nodes.length; j++) {
const dx = nodes[i].x - nodes[j].x;
const dy = nodes[i].y - nodes[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 120) {
const alpha = (1 - dist / 120) * 0.3;
ctx.strokeStyle = `rgba(${RED_RGB.join(",")}, ${alpha})`;
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(nodes[i].x, nodes[i].y);
ctx.lineTo(nodes[j].x, nodes[j].y);
ctx.stroke();
}
}
}
nodes.forEach((n) => {
n.x += n.vx;
n.y += n.vy;
n.pulse += 0.03;
if (n.x < 0 || n.x > canvas.width) n.vx *= -1;
if (n.y < 0 || n.y > canvas.height) n.vy *= -1;
const glow = Math.sin(n.pulse) * 0.3 + 0.4;
ctx.beginPath();
ctx.arc(n.x, n.y, n.radius + Math.sin(n.pulse) * 1, 0, Math.PI * 2);
ctx.fillStyle = `rgba(${RED_RGB.join(",")}, ${glow})`;
ctx.fill();
});
}
resize();
window.addEventListener("resize", resize);
visibleRAF(canvas.closest('.section') || canvas.parentElement, draw);
}
// ===== SPECTRA: Orbiting Blockchain Nodes =====
function initSpectraCanvas() {
const canvas = document.getElementById("spectra-canvas");
if (!canvas) return;
const ctx = canvas.getContext("2d");
let rings = [];
let time = 0;
function resize() {
canvas.width = canvas.parentElement.offsetWidth;
canvas.height = canvas.parentElement.offsetHeight;
const cx = canvas.width / 2;
const cy = canvas.height / 2;
const maxR = Math.min(canvas.width, canvas.height) * 0.4;
rings = [];
for (let i = 0; i < 4; i++) {
const r = maxR * (0.3 + i * 0.2);
const nodeCount = 3 + i * 2;
const ringNodes = [];
for (let j = 0; j < nodeCount; j++) {
ringNodes.push({
angle: (j / nodeCount) * Math.PI * 2,
speed: (0.005 + i * 0.002) * (i % 2 === 0 ? 1 : -1),
});
}
rings.push({ radius: r, nodes: ringNodes, cx, cy });
}
}
function draw() {
ctx.fillStyle = "rgba(10, 22, 40, 0.1)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
time += 0.01;
rings.forEach((ring, ri) => {
ctx.strokeStyle = `rgba(${RED_RGB.join(",")}, 0.08)`;
ctx.lineWidth = 1;
ctx.beginPath();
ctx.arc(ring.cx, ring.cy, ring.radius, 0, Math.PI * 2);
ctx.stroke();