-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
333 lines (287 loc) · 13 KB
/
Copy pathscript.js
File metadata and controls
333 lines (287 loc) · 13 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
/* ═══════════════════════════════════════════
FUTURISTIC PORTFOLIO — Script
═══════════════════════════════════════════ */
(function () {
'use strict';
// ─── Animated Grid Canvas ─────────────────
const canvas = document.getElementById('grid-canvas');
if (canvas) {
const ctx = canvas.getContext('2d');
let w, h, cols, rows;
const CELL = 50;
let mouse = { x: -1000, y: -1000 };
let animId;
let ticking = false;
let lastWidth = window.innerWidth;
function resize() {
const currentWidth = window.innerWidth;
if (currentWidth === lastWidth && canvas.width > 0) return;
lastWidth = currentWidth;
w = canvas.width = window.innerWidth;
h = canvas.height = window.innerHeight;
cols = Math.ceil(w / CELL) + 1;
rows = Math.ceil(h / CELL) + 1;
requestDraw();
}
window.addEventListener('resize', resize);
document.addEventListener('mousemove', (e) => {
mouse.x = e.clientX;
mouse.y = e.clientY;
requestDraw();
});
function requestDraw() {
if (!ticking) {
ticking = true;
requestAnimationFrame(drawGrid);
}
}
function drawGrid() {
ctx.clearRect(0, 0, w, h);
for (let i = 0; i <= cols; i++) {
for (let j = 0; j <= rows; j++) {
const x = i * CELL;
const y = j * CELL;
const dx = mouse.x - x;
const dy = mouse.y - y;
const dist = Math.sqrt(dx * dx + dy * dy);
const maxDist = 200;
const alpha = dist < maxDist ? 0.08 + (1 - dist / maxDist) * 0.2 : 0.04;
const size = dist < maxDist ? 1.5 + (1 - dist / maxDist) * 2 : 1;
ctx.beginPath();
ctx.arc(x, y, size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(52, 211, 153, ${alpha})`;
ctx.fill();
}
}
// Draw faint grid lines
ctx.strokeStyle = 'rgba(52, 211, 153, 0.025)';
ctx.lineWidth = 0.5;
for (let i = 0; i <= cols; i++) {
ctx.beginPath();
ctx.moveTo(i * CELL, 0);
ctx.lineTo(i * CELL, h);
ctx.stroke();
}
for (let j = 0; j <= rows; j++) {
ctx.beginPath();
ctx.moveTo(0, j * CELL);
ctx.lineTo(w, j * CELL);
ctx.stroke();
}
ticking = false;
}
// Initialize and first draw
resize();
}
// ─── Navigation ─────────────────────────────
const navbar = document.getElementById('navbar');
const navToggle = document.getElementById('nav-toggle');
const mobileMenu = document.getElementById('mobile-menu');
const navLinks = document.querySelectorAll('.nav__link');
const mobileLinks = document.querySelectorAll('.mobile-menu__link');
// Scroll effect
let lastScroll = 0;
window.addEventListener('scroll', () => {
const scrollY = window.scrollY;
if (navbar) {
navbar.classList.toggle('scrolled', scrollY > 50);
}
lastScroll = scrollY;
}, { passive: true });
// Mobile menu toggle
if (navToggle && mobileMenu) {
navToggle.addEventListener('click', () => {
const isOpen = mobileMenu.classList.toggle('open');
navToggle.classList.toggle('active');
navToggle.setAttribute('aria-expanded', isOpen);
document.body.style.overflow = isOpen ? 'hidden' : '';
});
}
// Close mobile menu on link click
mobileLinks.forEach(link => {
link.addEventListener('click', () => {
if (mobileMenu) mobileMenu.classList.remove('open');
if (navToggle) {
navToggle.classList.remove('active');
navToggle.setAttribute('aria-expanded', 'false');
}
document.body.style.overflow = '';
});
});
// Active nav link on scroll via Intersection Observer
function setupActiveNav() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav__link');
const observerOptions = {
root: null,
rootMargin: '-20% 0px -60% 0px',
threshold: 0
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.getAttribute('id');
navLinks.forEach(link => {
link.classList.toggle('active', link.getAttribute('href') === '#' + id);
});
}
});
}, observerOptions);
sections.forEach(section => observer.observe(section));
}
setupActiveNav();
// ─── Terminal Typing Animation ──────────────
const terminalBody = document.getElementById('terminal-body');
if (terminalBody) {
const commands = [
{ cmd: 'whoami', output: 'vinayak-singh // DevSecOps Engineer & Cloud Security Architect', type: 'default' },
{ cmd: 'cat /etc/experience', output: '8+ years · AWS · GCP · Kubernetes · Terraform', type: 'default' },
{ cmd: 'kubectl get nodes', output: 'Ready ✓ (2 nodes: eks-node-01, eks-node-02)', type: 'success' },
{ cmd: 'falcoctl status', output: 'Falco runtime security daemon active ✓', type: 'success' },
{ cmd: 'terraform plan', output: 'Plan: 14 to add, 0 to change, 0 to destroy. Policy: PASSED ✓', type: 'success' },
{ cmd: 'trivy k8s --severity CRITICAL cluster', output: '0 vulnerabilities found — EKS cluster secure ✓', type: 'success' },
{ cmd: 'echo $STATUS', output: '🟢 Available for hire — Let\'s build something secure', type: 'success' },
];
const isLighthouse = navigator.userAgent.includes('Chrome-Lighthouse') || navigator.userAgent.includes('Lighthouse');
function showOutput(text, type) {
const line = document.createElement('div');
line.className = 'terminal__line';
const outputClass = type === 'success' ? 'terminal__output--success'
: type === 'warn' ? 'terminal__output--warn'
: '';
line.innerHTML = `<span class="terminal__output ${outputClass}">${text}</span>`;
terminalBody.appendChild(line);
terminalBody.scrollTop = terminalBody.scrollHeight;
}
if (isLighthouse) {
// Render everything instantly for Lighthouse / Search Crawlers to avoid blocking time
commands.forEach(({ cmd, output, type }) => {
const line = document.createElement('div');
line.className = 'terminal__line';
line.innerHTML = `<span class="terminal__prompt">❯</span> <span class="terminal__cmd">${cmd}</span>`;
terminalBody.appendChild(line);
showOutput(output, type);
});
} else {
let cmdIndex = 0;
function typeCommand(cmd, callback) {
const line = document.createElement('div');
line.className = 'terminal__line';
line.innerHTML = `<span class="terminal__prompt">❯</span> <span class="terminal__cmd"></span><span class="terminal__caret">▌</span>`;
terminalBody.appendChild(line);
terminalBody.scrollTop = terminalBody.scrollHeight;
const cmdSpan = line.querySelector('.terminal__cmd');
const caret = line.querySelector('.terminal__caret');
let i = 0;
function type() {
if (i < cmd.length) {
cmdSpan.textContent += cmd[i];
i++;
setTimeout(type, 30 + Math.random() * 40);
} else {
caret.remove();
setTimeout(callback, 300);
}
}
type();
}
function runNextCommand() {
if (cmdIndex >= commands.length) {
// Done! Do not loop infinitely to avoid continuous CPU usage
return;
}
const { cmd, output, type } = commands[cmdIndex];
cmdIndex++;
typeCommand(cmd, () => {
showOutput(output, type);
setTimeout(runNextCommand, 1200);
});
}
// Start typing with a slight delay
setTimeout(runNextCommand, 800);
}
}
// ─── Scroll Reveal ──────────────────────────
function setupReveal() {
const revealElements = document.querySelectorAll(
'.section__header, .about__text, .about__metrics, .metric-card, ' +
'.strength-card, .skill-group, .timeline__item, .achievement-card, ' +
'.edu-card, .cert-card, .contact-card, .education-col__title'
);
revealElements.forEach(el => el.classList.add('reveal'));
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -40px 0px'
});
revealElements.forEach((el, i) => {
el.style.transitionDelay = `${(i % 6) * 0.08}s`;
observer.observe(el);
});
}
// ─── Metric Ring Animation ──────────────────
function animateRings() {
const rings = document.querySelectorAll('.metric-card__ring-fill');
const circumference = 2 * Math.PI * 42; // r=42
// Create SVG gradient definition
const svgs = document.querySelectorAll('.metric-card__ring svg');
svgs.forEach(svg => {
if (!svg.querySelector('defs')) {
const defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
const gradient = document.createElementNS('http://www.w3.org/2000/svg', 'linearGradient');
gradient.setAttribute('id', 'ring-gradient');
gradient.setAttribute('x1', '0%');
gradient.setAttribute('y1', '0%');
gradient.setAttribute('x2', '100%');
gradient.setAttribute('y2', '100%');
const stop1 = document.createElementNS('http://www.w3.org/2000/svg', 'stop');
stop1.setAttribute('offset', '0%');
stop1.setAttribute('stop-color', '#34d399');
const stop2 = document.createElementNS('http://www.w3.org/2000/svg', 'stop');
stop2.setAttribute('offset', '100%');
stop2.setAttribute('stop-color', '#d4a017');
gradient.appendChild(stop1);
gradient.appendChild(stop2);
defs.appendChild(gradient);
svg.insertBefore(defs, svg.firstChild);
}
});
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const ring = entry.target;
const percent = parseInt(ring.dataset.percent) || 0;
const offset = circumference - (percent / 100) * circumference;
ring.style.strokeDashoffset = offset;
observer.unobserve(ring);
}
});
}, { threshold: 0.3 });
rings.forEach(ring => {
ring.style.strokeDasharray = circumference;
ring.style.strokeDashoffset = circumference;
observer.observe(ring);
});
}
// ─── Footer Year ────────────────────────────
const footerYear = document.getElementById('footer-year');
if (footerYear) {
footerYear.textContent = new Date().getFullYear();
}
// ─── Init ───────────────────────────────────
document.addEventListener('DOMContentLoaded', () => {
setupReveal();
animateRings();
});
// If DOM already loaded
if (document.readyState !== 'loading') {
setupReveal();
animateRings();
}
})();