-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
310 lines (278 loc) · 12.8 KB
/
Copy pathscript.js
File metadata and controls
310 lines (278 loc) · 12.8 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
/* ══════════════════════════════════════════
CUSTOM CURSOR
══════════════════════════════════════════ */
const cursor = document.getElementById('cursor');
const cursorRing = document.getElementById('cursor-ring');
let cx = 0, cy = 0, rx = 0, ry = 0;
document.addEventListener('mousemove', e => {
cx = e.clientX; cy = e.clientY;
cursor.style.left = cx + 'px';
cursor.style.top = cy + 'px';
});
(function ringLoop() {
requestAnimationFrame(ringLoop);
rx += (cx - rx) * 0.14;
ry += (cy - ry) * 0.14;
cursorRing.style.left = rx + 'px';
cursorRing.style.top = ry + 'px';
})();
document.querySelectorAll('a,button,.skill-block,.proj-card,.cert-card,.split-card').forEach(el => {
el.addEventListener('mouseenter', () => {
cursor.style.width = '20px'; cursor.style.height = '20px';
cursor.style.background = 'var(--c2)';
cursorRing.style.width = '56px'; cursorRing.style.height = '56px';
});
el.addEventListener('mouseleave', () => {
cursor.style.width = '12px'; cursor.style.height = '12px';
cursor.style.background = 'var(--c1)';
cursorRing.style.width = '36px'; cursorRing.style.height = '36px';
});
});
/* ══════════════════════════════════════════
THREE.JS — DATA-NETWORK BACKGROUND
Nodes, floating edges, packets, binary rain
Hexgrid, constellation stars, orbit rings
══════════════════════════════════════════ */
(function() {
const canvas = document.getElementById('bgCanvas');
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 300);
camera.position.set(0, 0, 16);
/* — deep star field — */
const sg = new THREE.BufferGeometry();
const sp = new Float32Array(5000 * 3);
const sc = new Float32Array(5000 * 3);
const pal = [[0,0.9,1],[0.48,0.23,0.93],[0.96,0.62,0.04],[0.06,0.73,0.51],[0.96,0.25,0.37]];
for (let i = 0; i < 5000; i++) {
sp[i*3] = (Math.random()-0.5)*120;
sp[i*3+1] = (Math.random()-0.5)*80;
sp[i*3+2] = -30 - Math.random()*100;
const c = pal[i % pal.length];
sc[i*3]=c[0]; sc[i*3+1]=c[1]; sc[i*3+2]=c[2];
}
sg.setAttribute('position', new THREE.BufferAttribute(sp, 3));
sg.setAttribute('color', new THREE.BufferAttribute(sc, 3));
scene.add(new THREE.Points(sg, new THREE.PointsMaterial({ size: 0.06, vertexColors: true, transparent: true, opacity: 0.5 })));
/* — hex grid — */
for (let hx = -6; hx <= 6; hx++) {
for (let hy = -5; hy <= 5; hy++) {
const cx = hx*3.46+(hy%2)*1.73, cy = hy*3.0, cz = -14;
const pts = [];
for (let a = 0; a < 7; a++) pts.push(new THREE.Vector3(cx+1.1*Math.cos(a*Math.PI/3), cy+1.1*Math.sin(a*Math.PI/3), cz));
scene.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints(pts),
new THREE.LineBasicMaterial({ color: 0x001833, opacity: 0.15, transparent: true })));
}
}
/* — grid lines — */
const gm = new THREE.LineBasicMaterial({ color: 0x001122, opacity: 0.12, transparent: true });
for (let x = -20; x <= 20; x += 2.5) {
const g = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(x,-15,-12), new THREE.Vector3(x,15,-12)]);
scene.add(new THREE.Line(g, gm));
}
for (let y = -15; y <= 15; y += 2.5) {
const g = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(-20,y,-12), new THREE.Vector3(20,y,-12)]);
scene.add(new THREE.Line(g, gm));
}
/* — data nodes — */
const NCOLS = [0x00e5ff,0x7c3aed,0xf59e0b,0x10b981,0xf43f5e,0x54a0ff,0xff6b9d,0x20e3b2];
const nodes = [];
for (let i = 0; i < 32; i++) {
const r = 0.06 + Math.random()*0.13;
const col = NCOLS[i % NCOLS.length];
const m = new THREE.Mesh(
new THREE.SphereGeometry(r, 8, 8),
new THREE.MeshBasicMaterial({ color: col, transparent: true, opacity: 0.8 }));
m.position.set((Math.random()-0.5)*28, (Math.random()-0.5)*18, (Math.random()-0.5)*4 - 7);
scene.add(m);
nodes.push({ m, col, ox: m.position.x, oy: m.position.y,
phase: Math.random()*Math.PI*2, freq: 0.25+Math.random()*0.35, amp: 0.3+Math.random()*0.5 });
}
/* — pulse rings on nodes — */
const rings = [];
nodes.slice(0, 16).forEach((n, i) => {
const rm = new THREE.Mesh(
new THREE.RingGeometry(0.17, 0.22, 24),
new THREE.MeshBasicMaterial({ color: NCOLS[i%NCOLS.length], transparent: true, opacity: 0.3, side: THREE.DoubleSide }));
rm.position.copy(n.m.position);
scene.add(rm);
rings.push({ m: rm, node: n, phase: Math.random()*Math.PI*2 });
});
/* — edges — */
const edges = [];
for (let a = 0; a < nodes.length; a++) {
for (let b = a+1; b < nodes.length; b++) {
if (nodes[a].m.position.distanceTo(nodes[b].m.position) < 6.5) {
const pts = [nodes[a].m.position.clone(), nodes[b].m.position.clone()];
const l = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(pts),
new THREE.LineBasicMaterial({ color: 0x002244, opacity: 0.22, transparent: true }));
scene.add(l);
edges.push({ l, a, b });
}
}
}
/* — data packets — */
const pkts = [];
edges.slice(0, 24).forEach((e, i) => {
const m = new THREE.Mesh(
new THREE.SphereGeometry(0.048, 6, 6),
new THREE.MeshBasicMaterial({ color: NCOLS[i%NCOLS.length], transparent: true, opacity: 0.95 }));
scene.add(m);
pkts.push({ m, e, t: Math.random(), spd: 0.003+Math.random()*0.005 });
});
/* — binary rain — */
const RAIN = 800;
const rainGeo = new THREE.BufferGeometry();
const rp = new Float32Array(RAIN*3);
const rv = new Float32Array(RAIN);
for (let i = 0; i < RAIN; i++) {
rp[i*3] = (Math.random()-0.5)*36;
rp[i*3+1] = (Math.random()-0.5)*24;
rp[i*3+2] = -8 - Math.random()*5;
rv[i] = 0.016 + Math.random()*0.032;
}
rainGeo.setAttribute('position', new THREE.BufferAttribute(rp, 3));
scene.add(new THREE.Points(rainGeo, new THREE.PointsMaterial({ color: 0x003344, size: 0.05, transparent: true, opacity: 0.5 })));
/* — orbit rings — */
const orbitData = [];
[[0,0,-12,9,0.018],[4,-2,-13,6,0.022],[-5,3,-13,7,0.015]].forEach(([x,y,z,r,spd]) => {
const pts = [];
for (let a = 0; a <= 64; a++) pts.push(new THREE.Vector3(x+r*Math.cos(a/64*Math.PI*2), y+r*Math.sin(a/64*Math.PI*2), z));
const l = new THREE.Line(new THREE.BufferGeometry().setFromPoints(pts),
new THREE.LineBasicMaterial({ color: 0x001a33, opacity: 0.18, transparent: true }));
scene.add(l);
const dot = new THREE.Mesh(new THREE.SphereGeometry(0.09, 6, 6),
new THREE.MeshBasicMaterial({ color: 0x00e5ff, transparent: true, opacity: 0.65 }));
scene.add(dot);
orbitData.push({ dot, cx: x, cy: y, cz: z, r, spd, phase: Math.random()*Math.PI*2 });
});
let mx = 0, my = 0;
document.addEventListener('mousemove', e => {
mx = (e.clientX/window.innerWidth - 0.5) * 2;
my = (e.clientY/window.innerHeight - 0.5) * 2;
});
let t = 0;
(function loop() {
requestAnimationFrame(loop);
t += 0.007;
camera.position.x += (mx*0.9 - camera.position.x) * 0.04;
camera.position.y += (-my*0.6 - camera.position.y) * 0.04;
camera.lookAt(0, 0, 0);
nodes.forEach(n => {
n.m.position.x = n.ox + Math.sin(t*n.freq + n.phase) * n.amp;
n.m.position.y = n.oy + Math.cos(t*n.freq*0.8 + n.phase) * n.amp * 0.7;
n.m.material.opacity = 0.4 + 0.6 * Math.abs(Math.sin(t*0.45 + n.phase));
});
rings.forEach(r => {
r.m.position.copy(r.node.m.position);
const s = 1 + 0.6*Math.abs(Math.sin(t*0.5 + r.phase));
r.m.scale.setScalar(s);
r.m.material.opacity = 0.35 * (1 - Math.abs(Math.sin(t*0.5 + r.phase))*0.8);
r.m.rotation.z = t*0.3 + r.phase;
});
edges.forEach(({ l, a, b }) => {
const pa = nodes[a].m.position, pb = nodes[b].m.position;
const arr = l.geometry.attributes.position.array;
arr[0]=pa.x; arr[1]=pa.y; arr[2]=pa.z;
arr[3]=pb.x; arr[4]=pb.y; arr[5]=pb.z;
l.geometry.attributes.position.needsUpdate = true;
l.material.opacity = pa.distanceTo(pb) < 4 ? 0.26 : 0.09;
});
pkts.forEach(p => {
p.t += p.spd;
if (p.t > 1) p.t = 0;
const pa = nodes[p.e.a].m.position, pb = nodes[p.e.b].m.position;
p.m.position.lerpVectors(pa, pb, p.t);
p.m.material.opacity = 0.5 + 0.5 * Math.sin(p.t * Math.PI);
});
const ra = rainGeo.attributes.position.array;
for (let i = 0; i < RAIN; i++) {
ra[i*3+1] -= rv[i];
if (ra[i*3+1] < -12) { ra[i*3+1] = 12; ra[i*3] = (Math.random()-0.5)*36; }
}
rainGeo.attributes.position.needsUpdate = true;
orbitData.forEach(o => {
const a = t*o.spd*60 + o.phase;
o.dot.position.set(o.cx + o.r*Math.cos(a), o.cy + o.r*Math.sin(a), o.cz + 0.3);
});
renderer.render(scene, camera);
})();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
})();
/* ══════════════════════════════════════════
SCROLL REVEAL — IntersectionObserver
══════════════════════════════════════════ */
const io = new IntersectionObserver(entries => {
entries.forEach(e => {
if (!e.isIntersecting) return;
e.target.classList.add('visible');
// trigger skill bars
e.target.querySelectorAll('.comp-fill').forEach(bar => {
setTimeout(() => { bar.style.width = bar.dataset.w + '%'; }, 200);
});
io.unobserve(e.target);
});
}, { threshold: 0.12 });
document.querySelectorAll('.reveal,.split-left,.split-right').forEach(el => io.observe(el));
// also trigger bars if the .comp-section is inside a .reveal
const compSec = document.querySelector('.comp-section');
if (compSec) {
const compObs = new IntersectionObserver(entries => {
entries.forEach(e => {
if (!e.isIntersecting) return;
e.target.querySelectorAll('.comp-fill').forEach(bar => {
setTimeout(() => { bar.style.width = bar.dataset.w + '%'; }, 200);
});
compObs.unobserve(e.target);
});
}, { threshold: 0.2 });
compObs.observe(compSec);
}
/* ══════════════════════════════════════════
ANIMATED STAT COUNTERS
══════════════════════════════════════════ */
function animCount(el, target, suffix, duration, decimal) {
let start = 0;
const step = target / (duration / 16);
const timer = setInterval(() => {
start += step;
if (start >= target) { start = target; clearInterval(timer); }
el.textContent = (decimal ? start.toFixed(2) : Math.floor(start)) + suffix;
}, 16);
}
window.addEventListener('load', () => {
setTimeout(() => {
animCount(document.getElementById('s1'), 1, '+', 1200, false);
animCount(document.getElementById('s2'), 4, '+', 1200, false);
animCount(document.getElementById('s3'), 0.85, '+', 1600, true);
animCount(document.getElementById('s4'), 3, '', 1200, false);
}, 800);
});
/* ══════════════════════════════════════════
NAV ACTIVE STATE ON SCROLL
══════════════════════════════════════════ */
const secs = document.querySelectorAll('section[id]');
const navAs = document.querySelectorAll('.nav-links a');
window.addEventListener('scroll', () => {
let cur = '';
secs.forEach(s => { if (window.scrollY >= s.offsetTop - 140) cur = s.id; });
navAs.forEach(a => { a.style.color = a.getAttribute('href') === '#'+cur ? 'var(--c1)' : ''; });
}, { passive: true });
/* ══════════════════════════════════════════
PARALLAX HERO ON SCROLL
══════════════════════════════════════════ */
const heroLeft = document.querySelector('.hero-left');
const heroRight = document.querySelector('.hero-right');
window.addEventListener('scroll', () => {
const y = window.scrollY;
if (heroLeft) heroLeft.style.transform = `translateY(${y * 0.15}px)`;
if (heroRight) heroRight.style.transform = `translateY(${y * 0.08}px)`;
}, { passive: true });