Spaces:
Running
Running
File size: 3,252 Bytes
46428fd 7ebc062 46428fd 1fca5b4 46428fd 1fca5b4 46428fd 1fca5b4 46428fd f176733 46428fd f176733 46428fd 1fca5b4 7ebc062 46428fd 7ebc062 46428fd | 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 | // GraphicsLab Main Script
console.log('GraphicsLab loaded');
// Global state for benchmarks
window.graphicsLab = {
currentTest: null,
results: [],
apiBase: 'https://api.publicapis.org/entries?category=graphics&https=true'
};
// Fetch available graphics APIs from public‑apis
async function fetchGraphicsAPIs() {
try {
const res = await fetch('https://api.publicapis.org/entries?category=graphics&https=true');
const data = await res.json();
console.log('Graphics APIs:', data);
return data.entries || [];
} catch (err) {
console.warn('Could not fetch APIs, using fallback', err);
return [
{ API: 'WebGL', Description: 'Web Graphics Library', Link: 'https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API' },
{ API: 'Canvas', Description: '2D Drawing API', Link: 'https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API' },
{ API: 'WebGPU', Description: 'Next‑gen GPU API', Link: 'https://gpuweb.github.io/gpuweb/' }
];
}
}
// Simulate a benchmark
function simulateBenchmark(testName, duration = 3000) {
return new Promise((resolve) => {
console.log(`Starting benchmark: ${testName}`);
const start = performance.now();
// Simulate work
let progress = 0;
const interval = setInterval(() => {
progress += 10;
console.log(`${testName} progress: ${progress}%`);
if (progress >= 100) {
clearInterval(interval);
const end = performance.now();
// Level‑based scoring: if test is "quantum" or "neural", give much higher scores
let score;
if (testName === 'quantum' || testName === 'neural') {
score = Math.floor(Math.random() * 50000) + 50000; // 50k‑100k
} else {
score = Math.floor(Math.random() * 5000) + 1000; // 1k‑6k
}
const result = {
test: testName,
score,
unit: 'points',
duration: end - start,
timestamp: new Date().toISOString(),
level: (testName === 'quantum' || testName === 'neural') ? 100 : 10
};
window.graphicsLab.results.push(result);
console.log(`Benchmark ${testName} completed:`, result);
resolve(result);
}
}, duration / 10);
});
}
// Display notification
function showNotification(message, type = 'info') {
const toast = document.createElement('div');
toast.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-lg text-white font-semibold z-50 ${
type === 'success' ? 'bg-green-500' :
type === 'error' ? 'bg-red-500' :
'bg-blue-500'
}`;
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 4000);
}
// Initialize on page load
document.addEventListener('DOMContentLoaded', () => {
console.log('GraphicsLab initialized');
// Any global initialization
if (typeof Chart !== 'undefined') {
console.log('Chart.js ready');
}
}); |