// QuantumCortex Main JavaScript document.addEventListener('DOMContentLoaded', function() { // Initialize Feather Icons if (typeof feather !== 'undefined') { feather.replace(); } // Initialize Neural Network Visualization initNeuralVisualization(); // Initialize Energy Consumption Chart initEnergyChart(); // Initialize Particle Interactions initParticleInteractions(); // Initialize Quantum Animations initQuantumAnimations(); // Initialize Mobile Menu initMobileMenu(); }); function initNeuralVisualization() { const canvas = document.getElementById('neuralCanvas'); if (!canvas) return; const ctx = canvas.getContext('2d'); canvas.width = canvas.offsetWidth; canvas.height = canvas.offsetHeight; const nodes = []; const connections = []; const numNodes = 15; // Create nodes for (let i = 0; i < numNodes; i++) { nodes.push({ x: Math.random() * canvas.width, y: Math.random() * canvas.height, radius: 4 + Math.random() * 6, speedX: (Math.random() - 0.5) * 0.5, speedY: (Math.random() - 0.5) * 0.5, color: i % 2 === 0 ? '#0ea5e9' : '#a855f7', pulse: Math.random() * Math.PI * 2 }); } // Create connections for (let i = 0; i < nodes.length; i++) { for (let j = i + 1; j < nodes.length; j++) { if (Math.random() > 0.7) { connections.push({ from: i, to: j, strength: Math.random() }); } } } function animate() { ctx.clearRect(0, 0, canvas.width, canvas.height); // Update and draw connections connections.forEach(conn => { const from = nodes[conn.from]; const to = nodes[conn.to]; const distance = Math.sqrt(Math.pow(to.x - from.x, 2) + Math.pow(to.y - from.y, 2)); if (distance < 150) { ctx.beginPath(); ctx.moveTo(from.x, from.y); ctx.lineTo(to.x, to.y); ctx.strokeStyle = `rgba(${conn.from % 2 === 0 ? '14, 165, 233' : '168, 85, 247'}, ${0.3 * conn.strength})`; ctx.lineWidth = 1; ctx.stroke(); } }); // Update and draw nodes nodes.forEach(node => { // Update position with boundary check node.x += node.speedX; node.y += node.speedY; if (node.x < 0 || node.x > canvas.width) node.speedX *= -1; if (node.y < 0 || node.y > canvas.height) node.speedY *= -1; // Keep within bounds node.x = Math.max(0, Math.min(canvas.width, node.x)); node.y = Math.max(0, Math.min(canvas.height, node.y)); // Update pulse node.pulse += 0.05; // Draw node ctx.beginPath(); ctx.arc(node.x, node.y, node.radius + Math.sin(node.pulse) * 2, 0, Math.PI * 2); ctx.fillStyle = node.color; ctx.fill(); // Draw glow ctx.beginPath(); ctx.arc(node.x, node.y, node.radius + 5, 0, Math.PI * 2); ctx.fillStyle = node.color + '20'; ctx.fill(); }); requestAnimationFrame(animate); } animate(); // Handle window resize window.addEventListener('resize', () => { canvas.width = canvas.offsetWidth; canvas.height = canvas.offsetHeight; }); } function initEnergyChart() { const canvas = document.getElementById('energyCanvas'); if (!canvas) return; const ctx = canvas.getContext('2d'); canvas.width = canvas.offsetWidth; canvas.height = canvas.offsetHeight; const data = []; const dataPoints = 50; let time = 0; // Generate initial data for (let i = 0; i < dataPoints; i++) { data.push({ x: i, y: 20 + Math.sin(i * 0.3) * 15 + Math.random() * 5 }); } function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); // Draw grid ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)'; ctx.lineWidth = 1; // Horizontal lines for (let i = 0; i <= 5; i++) { const y = (canvas.height / 5) * i; ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(canvas.width, y); ctx.stroke(); } // Update data time += 0.1; data.shift(); data.push({ x: dataPoints - 1, y: 20 + Math.sin(time) * 15 + Math.cos(time * 0.7) * 10 + Math.random() * 3 }); // Update x positions data.forEach((point, i) => { point.x = i; }); // Draw area ctx.beginPath(); ctx.moveTo(0, canvas.height); data.forEach(point => { const x = (point.x / dataPoints) * canvas.width; const y = canvas.height - (point.y / 50) * canvas.height; ctx.lineTo(x, y); }); ctx.lineTo(canvas.width, canvas.height); ctx.closePath(); const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height); gradient.addColorStop(0, 'rgba(168, 85, 247, 0.3)'); gradient.addColorStop(1, 'rgba(168, 85, 247, 0)'); ctx.fillStyle = gradient; ctx.fill(); // Draw line ctx.beginPath(); ctx.moveTo(0, canvas.height - (data[0].y / 50) * canvas.height); data.forEach(point => { const x = (point.x / dataPoints) * canvas.width; const y = canvas.height - (point.y / 50) * canvas.height; ctx.lineTo(x, y); }); ctx.strokeStyle = '#a855f7'; ctx.lineWidth = 2; ctx.stroke(); requestAnimationFrame(draw); } draw(); // Handle window resize window.addEventListener('resize', () => { canvas.width = canvas.offsetWidth; canvas.height = canvas.offsetHeight; }); } function initParticleInteractions() { const particles = document.querySelectorAll('.particle'); particles.forEach(particle => { particle.addEventListener('mouseenter', () => { particle.style.transform = 'scale(1.5)'; particle.style.transition = 'transform 0.3s ease'; }); particle.addEventListener('mouseleave', () => { particle.style.transform = 'scale(1)'; }); }); } function initQuantumAnimations() { // Add floating animation to quantum elements const quantumElements = document.querySelectorAll('.quantum-float'); quantumElements.forEach((el, index) => { el.style.animationDelay = `${index * 0.2}s`; }); // Initialize intersection observer for scroll animations const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-in'); } }); }, { threshold: 0.1 }); // Observe elements with quantum-animate class document.querySelectorAll('.quantum-animate').forEach(el => { observer.observe(el); }); } function initMobileMenu() { const menuButton = document.querySelector('[data-menu-button]'); const mobileMenu = document.querySelector('[data-mobile-menu]'); if (menuButton && mobileMenu) { menuButton.addEventListener('click', () => { mobileMenu.classList.toggle('hidden'); menuButton.querySelector('i').setAttribute('data-feather', mobileMenu.classList.contains('hidden') ? 'menu' : 'x' ); feather.replace(); }); } } // Quantum API Integration class QuantumCortexAPI { constructor() { this.baseURL = 'https://api.quantumcortex.dev/v1'; } async getThoughtProcess() { try { // Simulate API call return await this.simulateThought(); } catch (error) { console.error('Quantum thought error:', error); return null; } } async simulateThought() { return new Promise(resolve => { setTimeout(() => { resolve({ thought: "The universe computes itself through quantum entanglement", energy: Math.random() * 100, coherence: 0.85 + Math.random() * 0.15 }); }, 1000); }); } async getDeviceCompatibility(deviceType) { const compatibilities = { smartphone: 0.95, quantum: 1.0, wearable: 0.85, cloud: 0.98, iot: 0.75 }; return compatibilities[deviceType] || 0.8; } // New Vector Physics API async getVectorField(zeroPoint = Math.PI) { return new Promise(resolve => { setTimeout(() => { const vectors = []; for (let i = 0; i < 360; i++) { vectors.push({ angle: (i * Math.PI * 2) / 360, magnitude: 1 + Math.random() * 0.5, charge: i < 180 ? 1 : -1, zeroPoint: zeroPoint }); } resolve({ zeroPoint, vectors, gyroscopicConstant: Math.PI, stability: 0.85 + Math.random() * 0.15 }); }, 800); }); } async solveThreeBody(pulsarCount = 2) { return new Promise(resolve => { setTimeout(() => { resolve({ solution: "Stable orbit achieved via π‑gyroscopic damping", pulsars: pulsarCount, convergenceTime: (3 + Math.random() * 5).toFixed(2) + "s", energyEfficiency: (0.7 + Math.random() * 0.25).toFixed(3) }); }, 1200); }); } } // Export for use in other modules window.QuantumCortex = { API: new QuantumCortexAPI(), utils: { formatEnergy: (energy) => `${energy.toFixed(2)} qubits`, formatCoherence: (coherence) => `${(coherence * 100).toFixed(1)}%`, vectorToCartesian: (angle, magnitude) => ({ x: magnitude * Math.cos(angle), y: magnitude * Math.sin(angle) }), calculateGyroscopicForce: (mass, angularVelocity) => { return mass * angularVelocity * Math.PI; } } }; // Initialize Quantum API const quantumAPI = new QuantumCortexAPI(); // Example usage quantumAPI.getThoughtProcess().then(thought => { if (thought) { console.log('Quantum thought received:', thought); } });