-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
193 lines (168 loc) · 4.9 KB
/
Copy pathscript.js
File metadata and controls
193 lines (168 loc) · 4.9 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
/* ============================================================
Portfolio – script.js
- Copyright year
- Animated star canvas (hero only)
- Typewriter effect (hero only)
- Scroll-reveal (IntersectionObserver)
- Mobile hamburger nav
- Active nav link
============================================================ */
/* ── Copyright year ── */
const yearEl = document.getElementById('year');
if (yearEl) yearEl.textContent = new Date().getFullYear();
/* ── Active nav link (highlight current page) ── */
(function setActiveNav() {
const path = location.pathname.split('/').pop() || 'index.html';
document.querySelectorAll('.nav-links a').forEach(a => {
const href = a.getAttribute('href');
if (href === path || (path === '' && href === 'index.html')) {
a.classList.add('active');
}
});
})();
/* ── Mobile hamburger ── */
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('navLinks');
if (hamburger && navLinks) {
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('open');
});
// Close on link click
navLinks.querySelectorAll('a').forEach(a => {
a.addEventListener('click', () => navLinks.classList.remove('open'));
});
}
/* ── Star canvas (hero page only) ── */
(function initStars() {
const canvas = document.getElementById('star-canvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let w, h, stars;
const STAR_COUNT = 130;
const STAR_COLOR = 'rgba(148, 188, 255, ';
function resize() {
w = canvas.width = canvas.offsetWidth;
h = canvas.height = canvas.offsetHeight;
}
function makeStar() {
return {
x: Math.random() * w,
y: Math.random() * h,
r: Math.random() * 1.4 + 0.2,
vx: (Math.random() - 0.5) * 0.12,
vy: (Math.random() - 0.5) * 0.12,
o: Math.random() * 0.55 + 0.1,
};
}
function init() {
resize();
stars = Array.from({ length: STAR_COUNT }, makeStar);
}
function draw() {
ctx.clearRect(0, 0, w, h);
for (const s of stars) {
s.x += s.vx;
s.y += s.vy;
if (s.x < 0) s.x = w;
if (s.x > w) s.x = 0;
if (s.y < 0) s.y = h;
if (s.y > h) s.y = 0;
ctx.beginPath();
ctx.arc(s.x, s.y, s.r, 0, Math.PI * 2);
ctx.fillStyle = STAR_COLOR + s.o + ')';
ctx.fill();
}
requestAnimationFrame(draw);
}
// Draw subtle connecting lines between close stars
function drawLines() {
ctx.clearRect(0, 0, w, h);
for (let i = 0; i < stars.length; i++) {
const a = stars[i];
a.x += a.vx;
a.y += a.vy;
if (a.x < 0) a.x = w;
if (a.x > w) a.x = 0;
if (a.y < 0) a.y = h;
if (a.y > h) a.y = 0;
// Star dot
ctx.beginPath();
ctx.arc(a.x, a.y, a.r, 0, Math.PI * 2);
ctx.fillStyle = STAR_COLOR + a.o + ')';
ctx.fill();
// Connections to nearby stars
for (let j = i + 1; j < stars.length; j++) {
const b = stars[j];
const dx = a.x - b.x;
const dy = a.y - b.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 110) {
ctx.beginPath();
ctx.moveTo(a.x, a.y);
ctx.lineTo(b.x, b.y);
ctx.strokeStyle = `rgba(79, 158, 255, ${0.06 * (1 - dist / 110)})`;
ctx.lineWidth = 0.6;
ctx.stroke();
}
}
}
requestAnimationFrame(drawLines);
}
init();
drawLines();
window.addEventListener('resize', init);
})();
/* ── Typewriter effect ── */
(function initTypewriter() {
const el = document.getElementById('typed');
if (!el) return;
const phrases = [
'Full-Stack Developer',
'AWS Certified Engineer',
'CS Specialist @ UTM',
'Open to Internships',
'Robot Programmer',
];
let phraseIdx = 0;
let charIdx = 0;
let deleting = false;
const TYPE_SPEED = 75;
const DELETE_SPEED = 40;
const PAUSE_MS = 2200;
function tick() {
const current = phrases[phraseIdx];
if (!deleting) {
el.textContent = current.slice(0, ++charIdx);
if (charIdx === current.length) {
deleting = true;
setTimeout(tick, PAUSE_MS);
return;
}
} else {
el.textContent = current.slice(0, --charIdx);
if (charIdx === 0) {
deleting = false;
phraseIdx = (phraseIdx + 1) % phrases.length;
}
}
setTimeout(tick, deleting ? DELETE_SPEED : TYPE_SPEED);
}
tick();
})();
/* ── Scroll reveal ── */
(function initReveal() {
const items = document.querySelectorAll('.reveal');
if (!items.length) return;
const observer = new IntersectionObserver(
entries => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('visible');
observer.unobserve(e.target);
}
});
},
{ threshold: 0.1, rootMargin: '0px 0px -40px 0px' }
);
items.forEach(el => observer.observe(el));
})();