// R00TS - Plant the seeds of artificial intelligence // Main application functionality document.addEventListener('DOMContentLoaded', function() { // Initialize particles initParticles(); // Load words from storage loadWords(); // Set up automatic updates setInterval(loadWords, 5000); }); function initParticles() { particlesJS('particles-js', { particles: { number: { value: 80, density: { enable: true, value_area: 800 } }, color: { value: '#00ff9d' }, shape: { type: 'circle' }, opacity: { value: 0.5, random: true, animation: { enable: true, speed: 1, opacity_min: 0.1, sync: false } }, size: { value: 3, random: true, animation: { enable: true, speed: 2, size_min: 0.1, sync: false } }, line_linked: { enable: true, distance: 150, color: '#00ff9d', opacity: 0.2, width: 1 }, move: { enable: true, speed: 1, direction: 'none', random: true, straight: false, out_mode: 'out', bounce: false } }, interactivity: { detect_on: 'canvas', events: { onhover: { enable: true, mode: 'grab' }, resize: true }, modes: { grab: { distance: 140, line_linked: { opacity: 0.5 } } } }, retina_detect: true }); } async function loadWords() { try { // Use the data manager to get words from API let words = await window.dataManager.getCurrentWords(); // Update the visualization updateWordCloud(words); // Update statistics updateStats(words); } catch (error) { console.error('Error loading words:', error); // Fallback to localStorage if API fails let words = JSON.parse(localStorage.getItem('roots-words')) || {}; updateWordCloud(words); updateStats(words); } } function updateStats(words) { const totalSubmissions = Object.values(words).reduce((a, b) => a + b, 0); const uniqueWords = Object.keys(words).length; document.getElementById('submission-count').textContent = totalSubmissions; document.getElementById('unique-count').textContent = uniqueWords; } async function submitWord(word) { word = word.trim().toLowerCase(); if (!word) return false; // Create a particle burst effect if (typeof createParticleBurst === 'function') { createParticleBurst(); } try { // Use the data manager to add word via API await window.dataManager.addWord(word); // Update UI with animation if GSAP is available if (typeof gsap !== 'undefined') { gsap.to('.stat-box', { scale: 1.1, duration: 0.2, yoyo: true, repeat: 1, ease: 'power2.out' }); } loadWords(); return true; } catch (error) { console.error('Error submitting word:', error); // Fallback to localStorage if API fails let words = JSON.parse(localStorage.getItem('roots-words')) || {}; words[word] = (words[word] || 0) + 1; localStorage.setItem('roots-words', JSON.stringify(words)); loadWords(); return true; } } function createParticleBurst() { const container = document.querySelector('.input-area'); const rect = container.getBoundingClientRect(); const centerX = rect.left + rect.width / 2; const centerY = rect.top + rect.height / 2; for (let i = 0; i < 20; i++) { const particle = document.createElement('div'); particle.style.cssText = ` position: fixed; width: 8px; height: 8px; background: #00ff9d; border-radius: 50%; pointer-events: none; z-index: 1000; `; document.body.appendChild(particle); const angle = (i / 20) * Math.PI * 2; const velocity = 2 + Math.random() * 2; const dx = Math.cos(angle) * velocity; const dy = Math.sin(angle) * velocity; gsap.fromTo(particle, { x: centerX, y: centerY, scale: 1, opacity: 1 }, { duration: 1 + Math.random(), x: centerX + dx * 50, y: centerY + dy * 50, scale: 0, opacity: 0, ease: 'power2.out', onComplete: () => particle.remove() } ); } } function updateWordCloud(words) { const container = document.getElementById('word-cloud-container'); if (!container) return; container.innerHTML = ''; const width = container.offsetWidth; const height = container.offsetHeight; const wordData = Object.entries(words).map(([text, value]) => ({ text, value })); // Sort by frequency wordData.sort((a, b) => b.value - a.value); // Take top 100 words const topWords = wordData.slice(0, 100); if (topWords.length === 0) { <<<<<<< HEAD ======= // Show placeholder if no words >>>>>>> 6fcedc69cfea5193a6809e1f2fb705b42479c5bd container.innerHTML = '
Plant some words to see them grow here!