Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
264 lines (226 loc) · 6.81 KB
/
Copy pathscript.js
File metadata and controls
264 lines (226 loc) · 6.81 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
// ============================================
// KYREE BLANFORD PORTFOLIO - INTERACTIONS
// Friendly cyber aesthetic with particles + typing
// ============================================
document.addEventListener('DOMContentLoaded', () => {
initParticles();
initTypingEffect();
initNavbar();
initSmoothReveal();
});
// ============================================
// 1. PARTICLE BACKGROUND
// ============================================
function initParticles() {
const canvas = document.getElementById('particleCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let particles = [];
let mouseX = 0;
let mouseY = 0;
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();
class Particle {
constructor() {
this.reset();
}
reset() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * 2.5 + 0.5;
this.speedX = (Math.random() - 0.5) * 0.5;
this.speedY = (Math.random() - 0.5) * 0.5;
this.opacity = Math.random() * 0.6 + 0.2;
this.color = this.getColor();
}
getColor() {
const colors = [
'22, 211, 238', // cyan
'52, 211, 153', // mint
'167, 139, 250', // purple
'244, 114, 182', // pink
];
return colors[Math.floor(Math.random() * colors.length)];
}
update() {
this.x += this.speedX;
this.y += this.speedY;
// Mouse interaction - gentle attraction
const dx = mouseX - this.x;
const dy = mouseY - this.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 200) {
const force = (200 - dist) / 200 * 0.02;
this.x += dx * force;
this.y += dy * force;
}
// Wrap around edges
if (this.x < -10) this.x = canvas.width + 10;
if (this.x > canvas.width + 10) this.x = -10;
if (this.y < -10) this.y = canvas.height + 10;
if (this.y > canvas.height + 10) this.y = -10;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(${this.color}, ${this.opacity})`;
ctx.fill();
// Glow
ctx.shadowBlur = 8;
ctx.shadowColor = `rgba(${this.color}, 0.3)`;
}
}
function connectParticles() {
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 140) {
const opacity = (1 - dist / 140) * 0.2;
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.strokeStyle = `rgba(34, 211, 238, ${opacity})`;
ctx.lineWidth = 0.6;
ctx.stroke();
}
}
}
}
// Mouse tracking
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
// Create particles
const particleCount = Math.min(80, Math.floor(window.innerWidth / 12));
for (let i = 0; i < particleCount; i++) {
particles.push(new Particle());
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (const p of particles) {
p.update();
p.draw();
}
connectParticles();
// Remove shadows for next frame
ctx.shadowBlur = 0;
requestAnimationFrame(animate);
}
animate();
}
// ============================================
// 2. TYPING EFFECT
// ============================================
function initTypingEffect() {
const textElement = document.getElementById('typingText');
if (!textElement) return;
const phrases = [
'Kyree Blanford',
'Tech Enthusiast',
'Embedded Systems Engineer',
'Hardware + AI Enthusiast',
];
let phraseIndex = 0;
let charIndex = 0;
let isDeleting = false;
let isPaused = false;
function type() {
const currentPhrase = phrases[phraseIndex];
const displayText = currentPhrase.substring(0, charIndex);
textElement.textContent = displayText;
if (!isDeleting && !isPaused) {
charIndex++;
if (charIndex > currentPhrase.length) {
isPaused = true;
setTimeout(() => {
isPaused = false;
isDeleting = true;
type();
}, 2000);
return;
}
} else if (isDeleting) {
charIndex--;
if (charIndex <= 0) {
isDeleting = false;
phraseIndex = (phraseIndex + 1) % phrases.length;
setTimeout(type, 500);
return;
}
}
const speed = isDeleting ? 40 : 80;
setTimeout(type, speed);
}
type();
}
// ============================================
// 3. NAVBAR
// ============================================
function initNavbar() {
const navbar = document.getElementById('navbar');
const navToggle = document.getElementById('navToggle');
const navLinks = document.querySelector('.nav-links');
if (!navbar || !navToggle || !navLinks) return;
// Scroll effect
let lastScrollY = 0;
window.addEventListener('scroll', () => {
const scrollY = window.scrollY;
if (scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
lastScrollY = scrollY;
});
// Mobile toggle
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('active');
navLinks.classList.toggle('open');
});
// Close mobile menu on link click
navLinks.querySelectorAll('a').forEach((link) => {
link.addEventListener('click', () => {
navToggle.classList.remove('active');
navLinks.classList.remove('open');
});
});
// Close on outside click
document.addEventListener('click', (e) => {
if (!navbar.contains(e.target) && navLinks.classList.contains('open')) {
navToggle.classList.remove('active');
navLinks.classList.remove('open');
}
});
}
// ============================================
// 4. SCROLL REVEAL ANIMATIONS
// ============================================
function initSmoothReveal() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px',
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe all glass cards and sections
document.querySelectorAll('.glass, .section-title').forEach((el) => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
}