-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
453 lines (432 loc) · 16.4 KB
/
Copy pathapp.js
File metadata and controls
453 lines (432 loc) · 16.4 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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
// --- Music Player Logic ---
document.addEventListener('DOMContentLoaded', function () {
const audioPlayer = document.getElementById('audio-player');
const playPauseBtn = document.getElementById('play-pause-btn');
const songSelect = document.getElementById('song-select');
const volumeBar = document.getElementById('volume-bar');
let isPlaying = false;
const playPauseIcon = document.getElementById('play-pause-icon');
const playIconSrc = 'assets/enable-sound.png';
const pauseIconSrc = 'assets/silent.png';
function setPlayIcon() {
playPauseIcon.src = playIconSrc;
playPauseIcon.alt = 'Play';
playPauseIcon.style.display = 'block';
}
function setPauseIcon() {
playPauseIcon.src = pauseIconSrc;
playPauseIcon.alt = 'Pause';
playPauseIcon.style.display = 'block';
}
playPauseBtn.addEventListener('click', () => {
if (audioPlayer.paused) {
audioPlayer.play();
setPauseIcon();
isPlaying = true;
} else {
audioPlayer.pause();
setPlayIcon();
isPlaying = false;
}
});
songSelect.addEventListener('change', (e) => {
audioPlayer.src = e.target.value;
if (isPlaying) {
audioPlayer.play();
setPauseIcon();
} else {
setPlayIcon();
}
});
audioPlayer.addEventListener('ended', () => {
audioPlayer.currentTime = 0;
audioPlayer.play();
setPauseIcon();
});
volumeBar.addEventListener('input', (e) => {
audioPlayer.volume = e.target.value;
});
audioPlayer.volume = volumeBar.value;
setPlayIcon();
});
function toggleMenu() {
const menu = document.querySelector(".menu-links");
const icon = document.querySelector(".hamburger-icon");
menu.classList.toggle("open");
icon.classList.toggle("open");
}
// --- ABOUT SECTION ANIMATION ---
window.onload = function() {
// ABOUT tree gebruikt nu de universele updateBlockVisibility van de home tree
// Zie code onderaan voor universele Three.js blok
}
// Timeline rendering for upcoming events
function renderTimeline() {
fetch('events.json')
.then(res => res.json())
.then(events => {
const timeline = document.getElementById('timeline-container');
const pagination = document.getElementById('timeline-pagination');
if (!timeline) return;
let page = 0;
const perPage = 4;
function renderPage() {
timeline.innerHTML = '';
const start = page * perPage;
const end = start + perPage;
events.slice(start, end).forEach((ev, i) => {
// Detect mobile
const isMobile = window.innerWidth < 900;
let fbBtnStyle = "background:none;border:none;padding:0;cursor:pointer;position:absolute;right:8px;bottom:8px;display:block;z-index:2;";
const fbEventUrl = "https://www.facebook.com/events/1784862275764186/";
timeline.innerHTML += `
<div class="timeline-event">
<div class="eventBubble" style="position:relative;${isMobile && ev.facebook ? 'cursor:pointer;' : ''}" data-fb="${ev.facebook ? fbEventUrl : ''}">
<div class="eventTime">
<div class="DayDigit">${ev.date.split('-')[2]}</div>
<div class="Day">${ev.day}<div class="MonthYear">${ev.date.split('-')[1]}/${ev.date.split('-')[0]}</div></div>
</div>
<div class="eventTitle">${ev.title}</div>
<div class="eventPlace">${ev.place}</div>
${ev.facebook ? `<button class='fb-event-btn' onclick='window.open("${fbEventUrl}", "_blank")' style='${fbBtnStyle}' onmouseenter='showFbInfo(this)' onmouseleave='hideFbInfo(this)'><img src='assets/facebook.png' alt='Facebook Event' style='width:28px;height:28px;vertical-align:middle;' /></button><div class='fb-info-balloon' style='display:none;position:absolute;right:40px;bottom:8px;background:#222;color:#fff;padding:6px 12px;border-radius:8px;font-size:10px;box-shadow:0 2px 8px #000;'>Event info</div>` : ''}
</div>
<svg class="timeline-dot-svg" height="20" width="20">
<circle cx="10" cy="10" r="5" />
</svg>
</div>
`;
});
// Add hover logic for eventBubble to show/hide fb-event-btn (desktop)
setTimeout(() => {
const isMobile = window.innerWidth < 900;
document.querySelectorAll('.eventBubble').forEach(bubble => {
const fb = bubble.getAttribute('data-fb');
// On mobile: clicking the bubble opens FB event if present
if (isMobile && fb) {
bubble.addEventListener('click', function(e) {
// Only trigger if not clicking the button itself
if (!e.target.classList.contains('fb-event-btn') && !e.target.closest('.fb-event-btn')) {
window.open(fb, '_blank');
}
});
} else {
// Desktop: clicking the bubble does niets extra, knop blijft altijd zichtbaar
// Geen mouseenter/mouseleave logica meer voor display
}
});
}, 0);
// Pagination controls
if (pagination) {
pagination.innerHTML = '';
const prev = document.createElement('button');
prev.textContent = '←';
prev.style.fontSize = '2rem';
prev.style.background = 'none';
prev.style.border = 'none';
prev.style.color = '#fff';
prev.style.cursor = 'pointer';
prev.disabled = page === 0;
prev.onclick = () => { page--; renderPage(); };
const next = document.createElement('button');
next.textContent = '→';
next.style.fontSize = '2rem';
next.style.background = 'none';
next.style.border = 'none';
next.style.color = '#fff';
next.style.cursor = 'pointer';
next.disabled = end >= events.length;
next.onclick = () => { page++; renderPage(); };
pagination.appendChild(prev);
const pageInfo = document.createElement('span');
pageInfo.textContent = ` ${page + 1} / ${Math.ceil(events.length / perPage)} `;
pageInfo.style.fontSize = '1.2rem';
pageInfo.style.color = '#fff';
pagination.appendChild(pageInfo);
pagination.appendChild(next);
}
}
renderPage();
});
}
window.showFbInfo = function(btn) {
const info = btn.parentElement.querySelector('.fb-info-balloon');
if (info) info.style.display = 'block';
};
window.hideFbInfo = function(btn) {
const info = btn.parentElement.querySelector('.fb-info-balloon');
if (info) info.style.display = 'none';
};
window.addEventListener('DOMContentLoaded', renderTimeline);
// --- SCRATCH PAD FOR VINYL EFFECT ---
const scratchPad = document.getElementById('scratch-pad');
const scratchAudio = document.getElementById('scratch-audio');
if (scratchPad && scratchAudio) {
const ctx = scratchPad.getContext('2d');
let activePointerId = null;
let lastAngle = null;
// Sample slider werkt altijd los
const sampleSlider = document.getElementById('scratch-sample-slider');
const scratchSamples = [
{ src: 'assets/080232_scratch-sample-90085.mp3', name: 'Ahh' },
{ src: 'assets/scratch03.mp3', name: 'Fresh' },
{ src: 'assets/scratch10.mp3', name: 'Ah Yeah' }
];
if (sampleSlider) {
sampleSlider.addEventListener('input', function(e) {
const idx = parseInt(e.target.value, 10);
if (scratchSamples[idx]) {
scratchAudio.src = scratchSamples[idx].src;
scratchAudio.currentTime = 0;
}
});
}
function drawVinyl(angle = 0) {
ctx.clearRect(0, 0, scratchPad.width, scratchPad.height);
const img = new Image();
img.src = 'assets/vinyl.png';
img.onload = function() {
ctx.save();
ctx.translate(130, 130);
ctx.rotate(angle);
ctx.drawImage(img, -130, -130, 260, 260);
ctx.restore();
};
}
drawVinyl();
function getAngle(x, y) {
const rect = scratchPad.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
return Math.atan2(y - cy, x - cx);
}
function playScratch() {
scratchAudio.currentTime = 0;
scratchAudio.play();
}
function stopScratch() {
scratchAudio.pause();
scratchAudio.currentTime = 0;
}
// Multitouch: gebruik pointer events
scratchPad.addEventListener('pointerdown', function(e) {
// Alleen starten als er nog geen andere pointer actief is op het canvas
if (activePointerId === null) {
activePointerId = e.pointerId;
lastAngle = getAngle(e.clientX, e.clientY);
scratchPad.setPointerCapture(e.pointerId);
scratchPad.style.cursor = "grabbing";
e.preventDefault();
}
});
scratchPad.addEventListener('pointermove', function(e) {
if (e.pointerId !== activePointerId) return;
const angle = getAngle(e.clientX, e.clientY);
drawVinyl(angle);
if (lastAngle !== null && Math.abs(angle - lastAngle) > 0.1) {
playScratch();
}
lastAngle = angle;
e.preventDefault();
});
scratchPad.addEventListener('pointerup', function(e) {
if (e.pointerId !== activePointerId) return;
activePointerId = null;
lastAngle = null;
drawVinyl();
scratchPad.style.cursor = "grab";
stopScratch();
e.preventDefault();
});
scratchPad.addEventListener('pointercancel', function(e) {
if (e.pointerId !== activePointerId) return;
activePointerId = null;
lastAngle = null;
drawVinyl();
scratchPad.style.cursor = "grab";
stopScratch();
e.preventDefault();
});
}
// --- Scratchpad toggle button ---
document.addEventListener('DOMContentLoaded', function() {
var btn = document.getElementById('show-scratchpad-btn');
var pad = document.getElementById('scratch-pad-container');
var armContainer = document.getElementById('turntable-arm-container');
var armImg = document.getElementById('turntable-arm-img');
if (btn && pad) {
btn.onclick = function() {
pad.style.display = 'flex';
btn.style.display = 'none';
if (armContainer && armImg) {
armContainer.style.display = 'block';
// Start with arm at -20deg
armImg.style.transform = 'rotate(-40deg)';
setTimeout(function() {
armImg.style.transform = 'rotate(-25deg)';
}, 100); // Animate to -5deg after short delay
}
};
}
});
// --- Adjust renderer pixel ratio ---
function createTree3D(containerId, texturePath) {
const container = document.getElementById(containerId);
if (!container) return;
const width = container.offsetWidth;
const height = container.offsetHeight;
const scene = new THREE.Scene();
const logicalHeight = 2.5;
const logicalWidth = logicalHeight * (width / height);
const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.z = 3;
const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2) * 0.5);
container.appendChild(renderer.domElement);
const rows = 12;
const cols = 10;
const blockW = logicalWidth / cols;
const blockH = logicalHeight / rows;
const blocks = [];
const loader = new THREE.TextureLoader();
loader.load(texturePath, function(texture) {
texture.wrapS = THREE.ClampToEdgeWrapping;
texture.wrapT = THREE.ClampToEdgeWrapping;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const yFlipped = rows - 1 - y;
const u0 = x / cols;
const v0 = 1 - (y + 1) / rows;
const u1 = (x + 1) / cols;
const v1 = 1 - y / rows;
const geometry = new THREE.PlaneGeometry(blockW, blockH, 1, 1);
const uvs = geometry.attributes.uv;
uvs.setXY(0, u0, v0);
uvs.setXY(1, u1, v0);
uvs.setXY(2, u0, v1);
uvs.setXY(3, u1, v1);
uvs.needsUpdate = true;
const material = new THREE.MeshBasicMaterial({ map: texture, transparent: true });
const mesh = new THREE.Mesh(geometry, material);
mesh.position.x = -logicalWidth / 2 + blockW / 2 + x * blockW;
mesh.position.y = logicalHeight / 2 - blockH / 2 - yFlipped * blockH;
mesh.position.z = 0;
scene.add(mesh);
blocks.push({ mesh, x, y: yFlipped, visible: true, glitchOffset: 0 });
}
}
let mouse = { x: 0, y: 0 };
window.addEventListener('mousemove', (e) => {
const rect = container.getBoundingClientRect();
mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -(((e.clientY - rect.top) / rect.height) * 2 - 1);
});
function updateBlockVisibility() {
for (let i = 0; i < blocks.length; i++) {
if (Math.random() < 0.10) {
blocks[i].visible = false;
} else {
blocks[i].visible = true;
}
}
}
setInterval(updateBlockVisibility, 400);
function updateGlitch() {
for (let i = 0; i < blocks.length; i++) {
if (Math.random() < 0.07) {
blocks[i].glitchOffset = (Math.random() - 0.5) * 0.25;
} else {
blocks[i].glitchOffset = 0;
}
}
}
setInterval(updateGlitch, 120);
function animate(now) {
requestAnimationFrame(animate);
for (let i = 0; i < blocks.length; i++) {
const { mesh, x, y, visible, glitchOffset } = blocks[i];
mesh.visible = visible;
mesh.position.x = -logicalWidth / 2 + blockW / 2 + x * blockW + glitchOffset;
mesh.position.y = logicalHeight / 2 - blockH / 2 - y * blockH;
const dx = (x / (cols - 1)) * logicalWidth - logicalWidth / 2 - mouse.x * (logicalWidth / 2);
const dy = (y / (rows - 1)) * logicalHeight - logicalHeight / 2 - mouse.y * (logicalHeight / 2);
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 0.4 * logicalWidth) {
const force = (0.4 * logicalWidth - dist) * 0.25;
mesh.position.z = force * 2;
} else {
mesh.position.z = 0;
}
}
renderer.render(scene, camera);
}
animate(performance.now());
});
window.addEventListener('resize', () => {
const width = container.offsetWidth;
const height = container.offsetHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
const newLogicalHeight = 2.5;
const newLogicalWidth = newLogicalHeight * (width / height);
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const i = y * cols + x;
const mesh = blocks[i].mesh;
mesh.geometry.dispose();
const geometry = new THREE.PlaneGeometry(newLogicalWidth / cols, newLogicalHeight / rows, 1, 1);
const u0 = x / cols;
const v0 = 1 - (y + 1) / rows;
const u1 = (x + 1) / cols;
const v1 = 1 - y / rows;
const uvs = geometry.attributes.uv;
uvs.setXY(0, u0, v0);
uvs.setXY(1, u1, v0);
uvs.setXY(2, u0, v1);
uvs.setXY(3, u1, v1);
uvs.needsUpdate = true;
mesh.geometry = geometry;
mesh.position.x = -newLogicalWidth / 2 + (newLogicalWidth / cols) / 2 + x * (newLogicalWidth / cols);
mesh.position.y = newLogicalHeight / 2 - (newLogicalHeight / rows) / 2 - (rows - 1 - y) * (newLogicalHeight / rows);
}
}
});
}
// Start 3D tree for both containers
createTree3D('three-container', './assets/profile-pic2.jpg');
createTree3D('about-three-container', 'assets/about-pic2bis2.jpg');
// --- Lightning Flicker Animation ---
function lightningFlicker(img, minDelay = 800, maxDelay = 3500) {
// Skip animation on mobile/low-end devices
if (window.innerWidth < 900 || navigator.hardwareConcurrency < 4) {
return;
}
function flicker() {
// Randomly choose if lightning is visible (simulate flash)
const flashes = Math.floor(Math.random() * 2) + 1;
let count = 0;
function doFlash() {
img.style.opacity = (Math.random() > 0.5 ? 1 : 0.45);
img.style.filter = 'drop-shadow(0 0 80px #fff) drop-shadow(0 0 160px #fff)';
setTimeout(() => {
img.style.opacity = 0.08;
img.style.filter = '';
count++;
if (count < flashes) {
setTimeout(doFlash, Math.random() * 120 + 60);
} else {
setTimeout(flicker, Math.random() * (maxDelay - minDelay) + minDelay);
}
}, Math.random() * 80 + 40);
}
doFlash();
}
flicker();
}
window.addEventListener('DOMContentLoaded', function() {
const left = document.getElementById('lightning-left');
const right = document.getElementById('lightning-right');
if (left) lightningFlicker(left);
if (right) lightningFlicker(right);
});