Spaces:
Running
Running
| // 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'); | |
| } | |
| }); |