-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
290 lines (249 loc) · 9.01 KB
/
script.js
File metadata and controls
290 lines (249 loc) · 9.01 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
document.addEventListener('DOMContentLoaded', function() {
const roleElement = document.getElementById('role-text');
const roleContainer = document.getElementById('role-container');
const roles = ['Engineer', 'Analyst', 'Scientist', 'Driven Problem Solver', 'Enthusiast', 'Nerd'];
let currentIndex = 0;
roleContainer.style.position = 'relative';
roleContainer.style.height = roleElement.offsetHeight + 'px';
roleContainer.style.overflow = 'hidden';
roleContainer.style.display = 'inline-block';
roleContainer.style.verticalAlign = 'bottom';
roleElement.style.display = 'inline-block';
roleElement.style.transition = 'transform 0.5s ease-in-out, opacity 0.5s ease-in-out';
roleElement.style.willChange = 'transform, opacity';
function verticalSpinTransition(nextIndex) {
roleElement.style.transform = 'translateY(-100%)';
roleElement.style.opacity = '0';
roleElement.addEventListener('transitionend', function handler() {
roleElement.removeEventListener('transitionend', handler);
roleElement.textContent = roles[nextIndex];
roleElement.style.transition = 'none';
roleElement.style.transform = 'translateY(100%)';
roleElement.style.opacity = '0';
roleElement.offsetHeight;
roleElement.style.transition = 'transform 0.5s ease-in-out, opacity 0.5s ease-in-out';
roleElement.style.transform = 'translateY(0)';
roleElement.style.opacity = '1';
}, { once: true });
}
roleElement.style.transform = 'translateY(0)';
roleElement.style.opacity = '1';
let roleRotationInterval = setInterval(() => {
const nextIndex = (currentIndex + 1) % roles.length;
verticalSpinTransition(nextIndex);
currentIndex = nextIndex;
}, 2500);
const djRoleElement = document.getElementById('dj-role-text');
if (djRoleElement) {
djRoleElement.textContent = 'Producer';
}
const profileImage = document.querySelector('.about-image');
const body = document.body;
let isDragging = false;
let startAngle = 0;
let currentRotation = 0;
let lastRotation = 0;
let isTurntableMode = false;
let autoRotationSpeed = 0;
let lastMouseMoveTime = 0;
let lastMouseMoveAngle = 0;
let autoRotationInterval = null;
const MAX_ROTATION_SPEED = 8;
function getAngleFromCenter(event) {
const rect = profileImage.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const angle = Math.atan2(event.clientY - centerY, event.clientX - centerX);
return angle * (180 / Math.PI);
}
function calculateSpinSpeed(currentAngle) {
const now = Date.now();
const timeDiff = now - lastMouseMoveTime;
const angleDiff = currentAngle - lastMouseMoveAngle;
if (timeDiff > 0) {
const speed = angleDiff / timeDiff;
lastMouseMoveTime = now;
lastMouseMoveAngle = currentAngle;
return speed;
}
return 0;
}
// BPM pulse control
const BASE_BPM = 120;
const MAX_BPM = 140;
let currentBPM = BASE_BPM;
function updatePulseBPM(speed) {
// Map rotation speed to BPM (faster spin = higher BPM)
const speedFactor = Math.abs(speed) / MAX_ROTATION_SPEED;
currentBPM = BASE_BPM + (MAX_BPM - BASE_BPM) * speedFactor;
const pulseDuration = 60 / currentBPM; // Convert BPM to seconds per beat
profileImage.style.setProperty('--pulse-duration', pulseDuration + 's');
}
function activateTurntableMode() {
isTurntableMode = true;
body.style.backgroundColor = '#000000';
body.style.transition = 'background-color 0.3s ease';
body.classList.add('turntable-mode');
// Set initial pulse based on spin speed
updatePulseBPM(autoRotationSpeed);
if (roleRotationInterval) {
clearInterval(roleRotationInterval);
roleRotationInterval = null;
}
autoRotationInterval = setInterval(() => {
currentRotation += autoRotationSpeed;
profileImage.style.transform = `rotate(${currentRotation}deg)`;
// Update BPM based on current rotation speed
updatePulseBPM(autoRotationSpeed);
}, 16);
}
function deactivateTurntableMode() {
isTurntableMode = false;
body.style.backgroundColor = '';
body.style.transition = 'background-color 0.3s ease';
body.classList.remove('turntable-mode');
if (!roleRotationInterval) {
roleElement.style.transition = 'none';
roleElement.style.transform = 'translateY(0)';
roleElement.style.opacity = '1';
roleElement.offsetHeight;
roleElement.style.transition = 'transform 0.5s ease-in-out, opacity 0.5s ease-in-out';
roleRotationInterval = setInterval(() => {
const nextIndex = (currentIndex + 1) % roles.length;
verticalSpinTransition(nextIndex);
currentIndex = nextIndex;
}, 2500);
}
if (autoRotationInterval) {
clearInterval(autoRotationInterval);
autoRotationInterval = null;
}
}
function handleMouseDown(event) {
if (isTurntableMode) {
deactivateTurntableMode();
return;
}
isDragging = true;
startAngle = getAngleFromCenter(event) - lastRotation;
profileImage.style.cursor = 'grabbing';
lastMouseMoveTime = Date.now();
lastMouseMoveAngle = getAngleFromCenter(event);
event.preventDefault();
}
function handleMouseMove(event) {
if (!isDragging || isTurntableMode) return;
const currentAngle = getAngleFromCenter(event);
currentRotation = currentAngle - startAngle;
const spinSpeed = calculateSpinSpeed(currentAngle);
if (Math.abs(spinSpeed) > 0.5) {
autoRotationSpeed = Math.max(-MAX_ROTATION_SPEED, Math.min(MAX_ROTATION_SPEED, spinSpeed * 2));
activateTurntableMode();
return;
}
profileImage.style.transform = `rotate(${currentRotation}deg)`;
}
function handleMouseUp() {
if (isDragging && !isTurntableMode) {
isDragging = false;
lastRotation = currentRotation;
profileImage.style.cursor = 'grab';
}
}
profileImage.addEventListener('mousedown', handleMouseDown);
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleMouseUp);
profileImage.addEventListener('touchstart', function(event) {
event.preventDefault();
const touch = event.touches[0];
handleMouseDown(touch);
});
document.addEventListener('touchmove', function(event) {
event.preventDefault();
const touch = event.touches[0];
handleMouseMove(touch);
});
document.addEventListener('touchend', handleMouseUp);
profileImage.style.cursor = 'grab';
profileImage.style.transition = 'none';
const djCanvas = document.getElementById('dj-bg-canvas');
const ctx = djCanvas.getContext('2d');
let particles = [];
let djBgAnimationId = null;
const PARTICLE_COUNT = 30;
const PARTICLE_MIN_RADIUS = 8;
const PARTICLE_MAX_RADIUS = 20;
const PARTICLE_MIN_SPEED = 0.2;
const PARTICLE_MAX_SPEED = 0.7;
function resizeCanvas() {
djCanvas.width = window.innerWidth;
djCanvas.height = window.innerHeight;
}
function randomBetween(a, b) {
return a + Math.random() * (b - a);
}
function createParticles() {
particles = [];
for (let i = 0; i < PARTICLE_COUNT; i++) {
const radius = randomBetween(PARTICLE_MIN_RADIUS, PARTICLE_MAX_RADIUS);
const x = randomBetween(radius, window.innerWidth - radius);
const y = randomBetween(radius, window.innerHeight - radius);
const angle = randomBetween(0, 2 * Math.PI);
const speed = randomBetween(PARTICLE_MIN_SPEED, PARTICLE_MAX_SPEED);
particles.push({
x, y, radius,
dx: Math.cos(angle) * speed,
dy: Math.sin(angle) * speed,
alpha: randomBetween(0.5, 1)
});
}
}
function drawParticles() {
ctx.clearRect(0, 0, djCanvas.width, djCanvas.height);
for (const p of particles) {
ctx.save();
ctx.globalAlpha = p.alpha;
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI);
ctx.shadowColor = '#4ade80';
ctx.shadowBlur = 20;
ctx.fillStyle = '#4ade80';
ctx.fill();
ctx.restore();
}
}
function updateParticles() {
for (const p of particles) {
p.x += p.dx;
p.y += p.dy;
if (p.x - p.radius < 0 || p.x + p.radius > djCanvas.width) p.dx *= -1;
if (p.y - p.radius < 0 || p.y + p.radius > djCanvas.height) p.dy *= -1;
}
}
function animateDjBg() {
updateParticles();
drawParticles();
djBgAnimationId = requestAnimationFrame(animateDjBg);
}
function startDjBg() {
resizeCanvas();
createParticles();
animateDjBg();
window.addEventListener('resize', resizeCanvas);
}
function stopDjBg() {
cancelAnimationFrame(djBgAnimationId);
ctx.clearRect(0, 0, djCanvas.width, djCanvas.height);
window.removeEventListener('resize', resizeCanvas);
}
const originalActivateTurntableMode = activateTurntableMode;
const originalDeactivateTurntableMode = deactivateTurntableMode;
activateTurntableMode = function() {
originalActivateTurntableMode();
startDjBg();
};
deactivateTurntableMode = function() {
originalDeactivateTurntableMode();
stopDjBg();
};
});