Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
387 lines (332 loc) · 14.3 KB
/
Copy pathscript.js
File metadata and controls
387 lines (332 loc) · 14.3 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
/* ================================================
Tech-Archive — Main Script
================================================ */
// ─── Three.js Particle Background ─────────────────────────────
(function initHeroCanvas() {
const canvas = document.getElementById('hero-canvas');
if (!canvas || typeof THREE === 'undefined') return;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 30;
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
// Particles
const particleCount = 1800;
const positions = new Float32Array(particleCount * 3);
const colors = new Float32Array(particleCount * 3);
const sizes = new Float32Array(particleCount);
const accentColor = new THREE.Color(0x7c5cff);
const accent2Color = new THREE.Color(0x00d4aa);
for (let i = 0; i < particleCount; i++) {
const i3 = i * 3;
// sphere-ish distribution
const radius = 20 + Math.random() * 25;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions[i3] = radius * Math.sin(phi) * Math.cos(theta);
positions[i3 + 1] = radius * Math.sin(phi) * Math.sin(theta);
positions[i3 + 2] = radius * Math.cos(phi);
const mixRatio = Math.random();
const color = accentColor.clone().lerp(accent2Color, mixRatio);
colors[i3] = color.r;
colors[i3 + 1] = color.g;
colors[i3 + 2] = color.b;
sizes[i] = Math.random() * 2.5 + 0.5;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
geometry.setAttribute('size', new THREE.BufferAttribute(sizes, 1));
const material = new THREE.PointsMaterial({
size: 0.12,
vertexColors: true,
transparent: true,
opacity: 0.7,
blending: THREE.AdditiveBlending,
depthWrite: false,
sizeAttenuation: true,
});
const particles = new THREE.Points(geometry, material);
scene.add(particles);
// Wireframe connections (subset)
const linePositions = [];
const posArr = geometry.attributes.position.array;
const maxDist = 6;
const linesLimit = 500;
let linesCount = 0;
for (let i = 0; i < particleCount && linesCount < linesLimit; i++) {
for (let j = i + 1; j < particleCount && linesCount < linesLimit; j++) {
const dx = posArr[i * 3] - posArr[j * 3];
const dy = posArr[i * 3 + 1] - posArr[j * 3 + 1];
const dz = posArr[i * 3 + 2] - posArr[j * 3 + 2];
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (dist < maxDist) {
linePositions.push(posArr[i * 3], posArr[i * 3 + 1], posArr[i * 3 + 2]);
linePositions.push(posArr[j * 3], posArr[j * 3 + 1], posArr[j * 3 + 2]);
linesCount++;
}
}
}
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute('position', new THREE.Float32BufferAttribute(linePositions, 3));
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x7c5cff,
transparent: true,
opacity: 0.06,
blending: THREE.AdditiveBlending,
depthWrite: false,
});
const lines = new THREE.LineSegments(lineGeometry, lineMaterial);
scene.add(lines);
// Mouse interaction
let mouseX = 0, mouseY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = (e.clientX / window.innerWidth - 0.5) * 2;
mouseY = (e.clientY / window.innerHeight - 0.5) * 2;
});
// Resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Animate
function animate() {
requestAnimationFrame(animate);
const time = Date.now() * 0.0003;
particles.rotation.y = time * 0.3 + mouseX * 0.15;
particles.rotation.x = mouseY * 0.1;
lines.rotation.y = particles.rotation.y;
lines.rotation.x = particles.rotation.x;
renderer.render(scene, camera);
}
animate();
})();
// ─── Data Loading & Rendering ──────────────────────────────────
const GITHUB_ICON_SVG = `<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"/></svg>`;
const LINK_ICON_SVG = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14L21 3"/></svg>`;
const deptIcons = {
'Computer Science': '💻',
'Electronics & Communication': '📡',
'Mechanical Engineering': '⚙️',
'Civil Engineering': '🏗️',
'Electrical Engineering': '⚡',
'Information Technology': '🌐',
'Biotechnology': '🧬',
default: '🔬',
};
function getInitials(name) {
return name.split(' ').map(w => w[0]).join('').toUpperCase().slice(0, 2);
}
function statusLabel(status) {
const clean = status.replace(/-/g, ' ');
return clean.charAt(0).toUpperCase() + clean.slice(1);
}
function statusClass(status) {
return status === 'completed' ? 'completed' : 'in-progress';
}
function createProjectCard(project) {
const card = document.createElement('div');
card.className = 'project-card';
const links = [];
if (project.repoUrl) {
links.push(`<a href="${project.repoUrl}" target="_blank" rel="noopener" class="card-link" title="Repository">${GITHUB_ICON_SVG}</a>`);
}
if (project.demoUrl) {
links.push(`<a href="${project.demoUrl}" target="_blank" rel="noopener" class="card-link" title="Live Demo">${LINK_ICON_SVG}</a>`);
}
const techTags = (project.techStack || []).map(t => `<span class="tech-tag">${t}</span>`).join('');
const avatars = (project.contributors || []).slice(0, 5).map(c =>
`<span class="card-avatar" title="${c.name} — ${c.role}">${getInitials(c.name)}</span>`
).join('');
const extraCount = (project.contributors || []).length - 5;
const extraBadge = extraCount > 0 ? `<span class="card-avatar" title="${extraCount} more">+${extraCount}</span>` : '';
card.innerHTML = `
<div class="card-top">
<span class="card-status ${statusClass(project.status)}">
<span class="card-status-dot"></span>
${statusLabel(project.status)}
</span>
<div class="card-links">${links.join('')}</div>
</div>
<h3 class="card-title">${project.title}</h3>
<p class="card-desc">${project.description}</p>
<div class="card-tech">${techTags}</div>
<div class="card-contributors">
<div class="card-avatars">${avatars}${extraBadge}</div>
<span class="card-contributors-text">${project.contributors.length} contributor${project.contributors.length !== 1 ? 's' : ''}</span>
</div>
`;
// 3D tilt effect
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = ((y - centerY) / centerY) * -6;
const rotateY = ((x - centerX) / centerX) * 6;
card.style.transform = `perspective(800px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale3d(1.02, 1.02, 1.02)`;
card.style.setProperty('--mouse-x', `${x}px`);
card.style.setProperty('--mouse-y', `${y}px`);
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'perspective(800px) rotateX(0) rotateY(0) scale3d(1,1,1)';
});
return card;
}
function groupByDepartment(projects) {
const groups = {};
projects.forEach(p => {
const dept = p.department || 'Other';
if (!groups[dept]) groups[dept] = [];
groups[dept].push(p);
});
return groups;
}
function renderDepartmentTabs(departments, container) {
const tabsEl = document.getElementById('department-tabs');
// "All" tab
const allTab = document.createElement('button');
allTab.className = 'dept-tab active';
allTab.textContent = 'All';
allTab.addEventListener('click', () => {
document.querySelectorAll('.department-group').forEach(g => g.style.display = '');
document.querySelectorAll('.dept-tab').forEach(t => t.classList.remove('active'));
allTab.classList.add('active');
});
tabsEl.appendChild(allTab);
departments.forEach(dept => {
const tab = document.createElement('button');
tab.className = 'dept-tab';
tab.textContent = dept;
tab.addEventListener('click', () => {
document.querySelectorAll('.dept-tab').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
document.querySelectorAll('.department-group').forEach(g => {
g.style.display = g.dataset.department === dept ? '' : 'none';
});
// Scroll to first visible group
const target = document.querySelector(`.department-group[data-department="${dept}"]`);
if (target) target.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
tabsEl.appendChild(tab);
});
}
function renderProjects(groups) {
const container = document.getElementById('projects-container');
const departments = Object.keys(groups);
renderDepartmentTabs(departments, container);
departments.forEach(dept => {
const group = document.createElement('div');
group.className = 'department-group';
group.dataset.department = dept;
const icon = deptIcons[dept] || deptIcons.default;
group.innerHTML = `
<div class="dept-group-header">
<div class="dept-group-icon">${icon}</div>
<div>
<div class="dept-group-name">${dept}</div>
<div class="dept-group-count">${groups[dept].length} project${groups[dept].length !== 1 ? 's' : ''}</div>
</div>
</div>
`;
const grid = document.createElement('div');
grid.className = 'projects-grid';
groups[dept].forEach(project => {
grid.appendChild(createProjectCard(project));
});
group.appendChild(grid);
container.appendChild(group);
});
}
function collectContributors(projects) {
const map = new Map();
projects.forEach(p => {
(p.contributors || []).forEach(c => {
const key = c.name.toLowerCase().trim();
if (!map.has(key)) {
map.set(key, { ...c, roles: new Set([c.role]) });
} else {
map.get(key).roles.add(c.role);
}
});
});
return Array.from(map.values());
}
function renderContributors(contributors) {
const grid = document.getElementById('contributors-grid');
contributors.forEach((c, idx) => {
const card = document.createElement('div');
card.className = 'contributor-card';
card.style.transitionDelay = `${idx * 0.05}s`;
const rolesText = Array.from(c.roles).join(' · ');
const githubLink = c.github
? `<a href="${c.github}" target="_blank" rel="noopener" class="contributor-github" title="GitHub">${GITHUB_ICON_SVG}</a>`
: '';
card.innerHTML = `
<div class="contributor-avatar">${getInitials(c.name)}</div>
<div class="contributor-info">
<div class="contributor-name">${c.name}</div>
<div class="contributor-roles">${rolesText}</div>
</div>
${githubLink}
`;
grid.appendChild(card);
});
}
// ─── Animated Counter ──────────────────────────────────────────
function animateCounter(el, target, duration = 1200) {
let start = null;
const step = (ts) => {
if (!start) start = ts;
const progress = Math.min((ts - start) / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3); // ease-out cubic
el.textContent = Math.floor(eased * target);
if (progress < 1) requestAnimationFrame(step);
};
requestAnimationFrame(step);
}
// ─── Scroll Reveal (Intersection Observer) ─────────────────────
function setupScrollReveal() {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, { threshold: 0.1, rootMargin: '0px 0px -40px 0px' });
document.querySelectorAll('.department-group, .contributor-card').forEach(el => {
observer.observe(el);
});
}
// ─── Init ──────────────────────────────────────────────────────
async function init() {
try {
const response = await fetch('data/projects.json');
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const projects = await response.json();
const groups = groupByDepartment(projects);
const departments = Object.keys(groups);
const contributors = collectContributors(projects);
// Stats
animateCounter(document.getElementById('stat-projects'), projects.length);
animateCounter(document.getElementById('stat-departments'), departments.length);
animateCounter(document.getElementById('stat-contributors'), contributors.length);
// Render
renderProjects(groups);
renderContributors(contributors);
// Scroll reveal
requestAnimationFrame(() => setupScrollReveal());
} catch (err) {
console.error('Failed to load projects:', err);
document.getElementById('projects-container').innerHTML = `
<div style="text-align:center;color:var(--text-muted);padding:60px 20px;">
<p style="font-size:1.2rem;margin-bottom:8px;">Could not load projects</p>
<p style="font-size:0.85rem;">Make sure <code>data/projects.json</code> exists and you're running a local server.</p>
</div>
`;
}
}
document.addEventListener('DOMContentLoaded', init);