forked from heyabhishekbajpai/SkillIssue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicon-sphere.html
More file actions
445 lines (393 loc) · 13.9 KB
/
Copy pathicon-sphere.html
File metadata and controls
445 lines (393 loc) · 13.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>3D Icon Sphere</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600&display=swap');
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #050505;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
font-family: 'Space Grotesk', sans-serif;
cursor: grab;
user-select: none;
}
body:active { cursor: grabbing; }
.sphere-container {
position: relative;
width: 1100px;
height: 1100px;
perspective: 1400px;
}
.sphere-glow {
position: absolute;
inset: 50%;
width: 340px;
height: 340px;
transform: translate(-50%, -50%);
border-radius: 50%;
background: radial-gradient(circle, rgba(255,255,255,0.03) 0%, transparent 70%);
pointer-events: none;
z-index: 0;
}
.icon-node {
position: absolute;
width: 240px;
height: 240px;
left: 50%;
top: 50%;
transform-origin: center center;
will-change: transform, opacity, filter;
transition: none;
pointer-events: auto;
border-radius: 14px;
overflow: visible;
}
.icon-node svg {
width: 100%;
height: 100%;
display: block;
pointer-events: none;
}
.icon-node:hover {
filter: drop-shadow(0 0 16px rgba(255,255,255,0.5)) !important;
}
/* Hover tooltip */
.icon-tooltip {
position: fixed;
pointer-events: none;
z-index: 10000;
padding: 10px 22px;
background: rgba(255,255,255,0.07);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid rgba(255,255,255,0.12);
border-radius: 12px;
color: #fff;
font-family: 'Space Grotesk', sans-serif;
font-size: 28px;
font-weight: 600;
letter-spacing: 0.6px;
text-transform: capitalize;
white-space: nowrap;
opacity: 0;
transform: translateX(-50%) translateY(4px);
transition: opacity 0.2s ease, transform 0.2s ease;
}
.icon-tooltip.visible {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
.icon-tooltip::before {
content: '';
position: absolute;
top: -5px;
left: 50%;
transform: translateX(-50%) rotate(45deg);
width: 10px;
height: 10px;
background: rgba(255,255,255,0.07);
border-left: 1px solid rgba(255,255,255,0.12);
border-top: 1px solid rgba(255,255,255,0.12);
}
/* Subtle ambient grain overlay */
.grain {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 999;
opacity: 0.035;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
background-size: 128px;
}
.hint {
position: fixed;
bottom: 32px;
left: 50%;
transform: translateX(-50%);
color: rgba(255,255,255,0.2);
font-size: 13px;
letter-spacing: 0.5px;
pointer-events: none;
animation: fadeHint 3s ease-in-out forwards;
}
@keyframes fadeHint {
0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
15% { opacity: 1; transform: translateX(-50%) translateY(0); }
80% { opacity: 1; }
100% { opacity: 0; }
}
</style>
</head>
<body>
<div class="sphere-container" id="sphere"></div>
<div class="icon-tooltip" id="tooltip"></div>
<div class="grain"></div>
<div class="hint">click & drag to spin</div>
<script>
const ICONS = [
'amp.svg', 'antigravity.svg', 'claude-code.svg', 'clawdbot.svg',
'cline.svg', 'codex.svg', 'copilot.svg', 'cursor.svg',
'droid.svg', 'gemini.svg', 'goose.svg', 'kilo.svg',
'kiro-cli.svg', 'opencode.svg', 'roo.svg', 'trae.svg',
'vscode.svg', 'windsurf.svg'
];
const container = document.getElementById('sphere');
const tooltip = document.getElementById('tooltip');
const RADIUS = 420;
const ICON_SIZE = 240;
const FOV = 1400;
const DEPTH_OPACITY_MIN = 0.07;
const DEPTH_OPACITY_MAX = 1.0;
const DEPTH_SCALE_MIN = 0.4;
const DEPTH_SCALE_MAX = 1.1;
const FRICTION = 0.97;
const SENSITIVITY = 0.004;
// Earth-like: strong rightward Y rotation + slight downward X tilt
const AUTO_SPEED_Y = 0.006; // rightward spin (main axis)
const AUTO_SPEED_X = 0.0015; // slight diagonal tilt
// State
let angleX = 0;
let angleY = 0;
let velocityX = 0;
let velocityY = 0;
let isUserDriven = false; // true when momentum from drag is still active
let isDragging = false;
let lastMouseX = 0;
let lastMouseY = 0;
let lastDragTime = 0;
let dragVelX = 0;
let dragVelY = 0;
// Fibonacci sphere distribution
function fibonacciSphere(n) {
const points = [];
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
for (let i = 0; i < n; i++) {
const y = 1 - (i / (n - 1)) * 2;
const radiusAtY = Math.sqrt(1 - y * y);
const theta = goldenAngle * i;
points.push({
x: Math.cos(theta) * radiusAtY,
y: y,
z: Math.sin(theta) * radiusAtY
});
}
return points;
}
const points = fibonacciSphere(ICONS.length);
const nodes = [];
// Process a data-URL image: make near-black pixels transparent
function removeBlackFromImage(dataUrl) {
return new Promise((resolve) => {
const img = new Image();
img.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const d = imageData.data;
for (let i = 0; i < d.length; i += 4) {
const brightness = (d[i] + d[i + 1] + d[i + 2]) / 3;
if (brightness < 35) {
d[i + 3] = 0; // fully transparent
} else if (brightness < 70) {
d[i + 3] = Math.round(((brightness - 35) / 35) * d[i + 3]);
}
}
ctx.putImageData(imageData, 0, 0);
resolve(canvas.toDataURL('image/png'));
};
img.src = dataUrl;
});
}
// Fetch SVGs, strip black background, inline them
async function loadIcons() {
for (let i = 0; i < ICONS.length; i++) {
const icon = ICONS[i];
try {
const resp = await fetch(`public/svgs/${icon}`);
const svgText = await resp.text();
// Parse the SVG and remove the black background rect/path
const parser = new DOMParser();
const doc = parser.parseFromString(svgText, 'image/svg+xml');
const svg = doc.querySelector('svg');
// Remove any path or rect that is the black background fill
svg.querySelectorAll('path, rect').forEach(el => {
const fill = (el.getAttribute('fill') || '').toLowerCase().trim();
const d = el.getAttribute('d') || '';
const isBlackFill = fill === '#000' || fill === '#000000' || fill === 'black';
if (!isBlackFill) return;
// Match <path d="m0 0h100v100h-100z" fill="#000"/>
const isBlackBgPath = /^m0\s*0h\d+v\d+h-?\d+z$/i.test(d.replace(/\s/g, ''));
// Match <rect width="100" height="100" fill="black"/> (with or without x/y)
const isBlackBgRect = el.tagName.toLowerCase() === 'rect' &&
(!el.getAttribute('x') || el.getAttribute('x') === '0') &&
(!el.getAttribute('y') || el.getAttribute('y') === '0');
// Fallback: path with full-size viewport hints
const isBlackFillFullSize = d.includes('h100') && d.includes('v100');
if (isBlackBgPath || isBlackBgRect || isBlackFillFullSize) {
el.remove();
}
});
// Process embedded raster images (e.g. vscode.svg has a base64 PNG)
const embeddedImages = svg.querySelectorAll('image');
for (const img of embeddedImages) {
const href = img.getAttribute('xlink:href') || img.getAttribute('href');
if (href && href.startsWith('data:image')) {
const cleaned = await removeBlackFromImage(href);
if (img.hasAttribute('xlink:href')) {
img.setAttribute('xlink:href', cleaned);
} else {
img.setAttribute('href', cleaned);
}
}
}
const el = document.createElement('div');
el.className = 'icon-node';
el.dataset.name = icon.replace('.svg', '').replace(/-/g, ' ');
el.appendChild(svg);
container.appendChild(el);
nodes.push({ el, point: { ...points[i] } });
// Hover tooltip
el.addEventListener('mouseenter', (e) => {
tooltip.textContent = el.dataset.name;
tooltip.classList.add('visible');
});
el.addEventListener('mousemove', (e) => {
const rect = el.getBoundingClientRect();
tooltip.style.left = (rect.left + rect.width / 2) + 'px';
tooltip.style.top = (rect.bottom - 8) + 'px';
});
el.addEventListener('mouseleave', () => {
tooltip.classList.remove('visible');
});
} catch (err) {
console.warn(`Failed to load ${icon}:`, err);
}
}
}
let nodesReady = loadIcons();
// Rotation matrices
function rotateX(p, angle) {
const cos = Math.cos(angle), sin = Math.sin(angle);
return {
x: p.x,
y: p.y * cos - p.z * sin,
z: p.y * sin + p.z * cos
};
}
function rotateY(p, angle) {
const cos = Math.cos(angle), sin = Math.sin(angle);
return {
x: p.x * cos + p.z * sin,
y: p.y,
z: -p.x * sin + p.z * cos
};
}
function render() {
const items = [];
nodes.forEach(({ el, point }, i) => {
// Apply rotation
let p = rotateX(point, angleX);
p = rotateY(p, angleY);
// Perspective projection
const z = p.z * RADIUS;
const scale3d = FOV / (FOV + z);
const projX = p.x * RADIUS * scale3d;
const projY = p.y * RADIUS * scale3d;
// Depth factor: -1 (back) to 1 (front)
const depthNorm = (p.z + 1) / 2; // 0 = back, 1 = front
const opacity = DEPTH_OPACITY_MIN + depthNorm * (DEPTH_OPACITY_MAX - DEPTH_OPACITY_MIN);
const scale = DEPTH_SCALE_MIN + depthNorm * (DEPTH_SCALE_MAX - DEPTH_SCALE_MIN);
items.push({ el, projX, projY, z: p.z, opacity, scale, scale3d });
});
// Sort by z for proper z-index
items.sort((a, b) => a.z - b.z);
items.forEach(({ el, projX, projY, z, opacity, scale, scale3d }, idx) => {
const tx = projX - ICON_SIZE / 2;
const ty = projY - ICON_SIZE / 2;
el.style.transform = `translate(${tx}px, ${ty}px) scale(${scale * scale3d})`;
el.style.opacity = opacity;
el.style.zIndex = idx + 1;
el.style.filter = `brightness(${0.5 + opacity * 0.6})`;
});
}
function animate() {
if (!isDragging) {
if (isUserDriven) {
// Apply drag momentum with friction
angleY += velocityY;
angleX += velocityX;
velocityX *= FRICTION;
velocityY *= FRICTION;
// Once momentum dies, return to auto-rotation
const speed = Math.abs(velocityX) + Math.abs(velocityY);
if (speed < 0.0005) {
isUserDriven = false;
}
} else {
// Continuous earth-like rotation: diagonal right
angleY += AUTO_SPEED_Y;
angleX += AUTO_SPEED_X;
}
}
render();
requestAnimationFrame(animate);
}
// --- Mouse / Touch interaction ---
function onPointerDown(e) {
isDragging = true;
lastMouseX = e.clientX || e.touches?.[0]?.clientX || 0;
lastMouseY = e.clientY || e.touches?.[0]?.clientY || 0;
lastDragTime = performance.now();
dragVelX = 0;
dragVelY = 0;
}
function onPointerMove(e) {
if (!isDragging) return;
const x = e.clientX || e.touches?.[0]?.clientX || 0;
const y = e.clientY || e.touches?.[0]?.clientY || 0;
const dx = x - lastMouseX;
const dy = y - lastMouseY;
const now = performance.now();
const dt = Math.max(now - lastDragTime, 1);
angleY += dx * SENSITIVITY;
angleX += dy * SENSITIVITY;
// Track velocity for momentum
dragVelY = (dx * SENSITIVITY) / (dt / 16);
dragVelX = (dy * SENSITIVITY) / (dt / 16);
lastMouseX = x;
lastMouseY = y;
lastDragTime = now;
}
function onPointerUp() {
if (!isDragging) return;
isDragging = false;
// Apply momentum from drag
velocityY = dragVelY;
velocityX = dragVelX;
isUserDriven = true;
}
// Mouse events
document.addEventListener('mousedown', onPointerDown);
document.addEventListener('mousemove', onPointerMove);
document.addEventListener('mouseup', onPointerUp);
document.addEventListener('mouseleave', onPointerUp);
// Touch events
document.addEventListener('touchstart', (e) => { e.preventDefault(); onPointerDown(e); }, { passive: false });
document.addEventListener('touchmove', (e) => { e.preventDefault(); onPointerMove(e); }, { passive: false });
document.addEventListener('touchend', onPointerUp);
document.addEventListener('touchcancel', onPointerUp);
// Start after icons are loaded
nodesReady.then(() => animate());
</script>
</body>
</html>