// ============================================ // TEMPLE AIA — Main JavaScript // ============================================ // Navigation entre vues const navButtons = document.querySelectorAll('.nav-btn'); const viewSections = document.querySelectorAll('.view-section'); navButtons.forEach(btn => { btn.addEventListener('click', () => { const targetView = btn.dataset.view; // Update navigation navButtons.forEach(b => b.classList.remove('active')); btn.classList.add('active'); // Update views viewSections.forEach(section => { section.classList.remove('active'); }); document.getElementById(`view-${targetView}`).classList.add('active'); // Redraw canvases when switching to canvas views if (targetView === 'circle') drawCircle(); if (targetView === 'triangle') drawTriangle(); if (targetView === 'tree') drawTree(); if (targetView === 'matrix') { calculateRatios(); initLightPoints(); drawMathematicalRatios(); } }); }); // ============================================ // SEQUENCE GENERATOR // ============================================ const depthSlider = document.getElementById('depth-slider'); const depthDisplay = document.getElementById('depth-display'); const generateBtn = document.getElementById('generate-btn'); const infiniteBtn = document.getElementById('infinite-btn'); const exportPdfBtn = document.getElementById('export-pdf-btn'); const sequenceOutput = document.getElementById('sequence-output'); let currentSequence = ['أ', 'ل', 'ف']; let infiniteMode = false; let infiniteInterval = null; let currentDepth = 0; let sequenceHistory = []; let letterCounts = {}; depthSlider.addEventListener('input', () => { depthDisplay.textContent = depthSlider.value; }); generateBtn.addEventListener('click', () => { stopInfiniteGeneration(); const depth = parseInt(depthSlider.value); currentSequence = deriveSequence(depth); currentDepth = depth; displaySequence(currentSequence); updateStats(); trackSequenceHistory(); }); infiniteBtn.addEventListener('click', () => { if (!infiniteMode) { startInfiniteGeneration(); } else { stopInfiniteGeneration(); } }); exportPdfBtn.addEventListener('click', () => { exportToPDF(); }); function startInfiniteGeneration() { infiniteMode = true; infiniteBtn.innerHTML = '⏸ Arrêter'; infiniteBtn.style.background = 'linear-gradient(135deg, #ef4444, #dc2626)'; currentDepth = 0; let speed = 1000; // ms entre chaque itération infiniteInterval = setInterval(() => { currentDepth++; currentSequence = deriveSequence(currentDepth); displaySequence(currentSequence); updateStats(); trackSequenceHistory(); // Ralentir progressivement if (currentDepth > 5) { speed = 2000; } if (currentDepth > 8) { stopInfiniteGeneration(); } }, speed); } function stopInfiniteGeneration() { infiniteMode = false; if (infiniteInterval) { clearInterval(infiniteInterval); infiniteInterval = null; } infiniteBtn.innerHTML = '∞ Générer à l\'infini'; infiniteBtn.style.background = 'linear-gradient(135deg, #3b82f6, #1e40af)'; } function updateStats() { document.getElementById('stat-length').textContent = currentSequence.length; document.getElementById('stat-depth').textContent = currentDepth; if (sequenceHistory.length > 1) { const lastLength = sequenceHistory[sequenceHistory.length - 2].length; const growth = ((currentSequence.length / lastLength) * 100 - 100).toFixed(1); document.getElementById('stat-speed').textContent = `+${growth}%`; } } function trackSequenceHistory() { sequenceHistory.push({ depth: currentDepth, length: currentSequence.length, sequence: [...currentSequence] }); // Limiter l'historique if (sequenceHistory.length > 20) { sequenceHistory.shift(); } // Compter les lettres letterCounts = {}; currentSequence.forEach(letter => { letterCounts[letter] = (letterCounts[letter] || 0) + 1; }); // Mettre à jour les ratios calculateRatios(); // Mettre à jour les visualisations mathématiques si vue Matrix active const activeView = document.querySelector('.view-section.active'); if (activeView && activeView.id === 'view-matrix') { drawMathematicalRatios(); } } function deriveSequence(iterations) { let seq = ['أ', 'ل', 'ف']; // Chaque lettre génère son propre nom en arabe const rules = { 'أ': ['ا', 'ل', 'ف'], // Alif → alif 'ا': ['ا', 'ل', 'ف'], // Alif (sans hamza) → alif 'ل': ['ل', 'ا', 'م'], // Lam → lam 'ف': ['ف', 'ا'], // Fa → fa 'م': ['م', 'ي', 'م'], // Mim → mim 'ي': ['ي', 'ا'] // Ya → ya }; for (let i = 0; i < iterations; i++) { const next = []; for (const letter of seq) { next.push(...(rules[letter] || [letter])); } seq = next; } return seq; } function displaySequence(seq) { sequenceOutput.innerHTML = ''; sequenceOutput.className = 'sequence-output sequence-grid'; seq.forEach((letter, index) => { const cell = document.createElement('div'); cell.className = 'letter-cell'; cell.textContent = letter; cell.dataset.letter = letter; cell.dataset.index = index + 1; cell.style.color = getLetterColor(letter); cell.style.borderColor = getLetterColor(letter) + '40'; cell.addEventListener('click', () => { // Retirer la sélection précédente document.querySelectorAll('.letter-cell').forEach(c => c.classList.remove('selected')); cell.classList.add('selected'); openDashboard(letter); }); cell.addEventListener('mouseenter', () => { cell.style.borderColor = getLetterColor(letter); cell.style.backgroundColor = getLetterColor(letter) + '20'; }); cell.addEventListener('mouseleave', () => { if (!cell.classList.contains('selected')) { cell.style.borderColor = getLetterColor(letter) + '40'; cell.style.backgroundColor = 'var(--bg-elevated)'; } }); sequenceOutput.appendChild(cell); }); } function getLetterColor(letter) { const colors = { 'أ': '#22c55e', 'ا': '#22c55e', 'ل': '#38bdf8', 'ف': '#f97316', 'م': '#a855f7', 'ي': '#eab308' }; return colors[letter] || '#6b7280'; } // ============================================ // MATRIX VIEW // ============================================ const matrixCanvas = document.getElementById('matrix-canvas'); const matrixCtx = matrixCanvas ? matrixCanvas.getContext('2d') : null; const matrixStartBtn = document.getElementById('matrix-start'); const matrixStopBtn = document.getElementById('matrix-stop'); const matrixNumbersCheck = document.getElementById('matrix-numbers'); const matrixGlowCheck = document.getElementById('matrix-glow'); let matrixRunning = false; let matrixColumns = []; let matrixAnimationId = null; const letterToNumber = { 'أ': '1', 'ا': '1', 'ل': '30', 'ف': '80', 'م': '40', 'ي': '10' }; const letterValues = { 'أ': 1, 'ا': 1, 'ل': 30, 'ف': 80, 'م': 40, 'ي': 10 }; if (matrixStartBtn) { matrixStartBtn.addEventListener('click', startMatrix); } if (matrixStopBtn) { matrixStopBtn.addEventListener('click', stopMatrix); } function startMatrix() { if (matrixRunning) return; matrixRunning = true; matrixStartBtn.style.display = 'none'; matrixStopBtn.style.display = 'inline-flex'; setupMatrixCanvas(); animateMatrix(); } function stopMatrix() { matrixRunning = false; matrixStartBtn.style.display = 'inline-flex'; matrixStopBtn.style.display = 'none'; if (matrixAnimationId) { cancelAnimationFrame(matrixAnimationId); matrixAnimationId = null; } } function setupMatrixCanvas() { if (!matrixCanvas || !matrixCtx) return; const rect = matrixCanvas.getBoundingClientRect(); matrixCanvas.width = rect.width; matrixCanvas.height = rect.height; const fontSize = 16; const columns = Math.floor(matrixCanvas.width / fontSize); matrixColumns = Array(columns).fill(1); } function animateMatrix() { if (!matrixRunning || !matrixCanvas || !matrixCtx) return; // Effet de traînée matrixCtx.fillStyle = 'rgba(0, 0, 0, 0.05)'; matrixCtx.fillRect(0, 0, matrixCanvas.width, matrixCanvas.height); const fontSize = 16; const useNumbers = matrixNumbersCheck && matrixNumbersCheck.checked; const useGlow = matrixGlowCheck && matrixGlowCheck.checked; matrixCtx.font = `${fontSize}px monospace`; for (let i = 0; i < matrixColumns.length; i++) { // Choisir une lettre ou son code const letters = currentSequence.length > 0 ? currentSequence : ['أ', 'ل', 'ف']; const letter = letters[Math.floor(Math.random() * letters.length)]; const text = useNumbers ? letterToNumber[letter] || letter : letter; // Couleur verte Matrix avec variations const brightness = Math.random() * 0.5 + 0.5; const green = Math.floor(255 * brightness); matrixCtx.fillStyle = `rgb(0, ${green}, 0)`; // Effet glow if (useGlow) { matrixCtx.shadowColor = `rgb(0, ${green}, 0)`; matrixCtx.shadowBlur = 10; } else { matrixCtx.shadowBlur = 0; } const x = i * fontSize; const y = matrixColumns[i] * fontSize; matrixCtx.fillText(text, x, y); // Réinitialiser aléatoirement if (y > matrixCanvas.height && Math.random() > 0.975) { matrixColumns[i] = 0; } matrixColumns[i]++; } matrixAnimationId = requestAnimationFrame(animateMatrix); } // ============================================ // RATIOS CALCULATION // ============================================ function calculateRatios() { if (!currentSequence || currentSequence.length === 0) return; const total = currentSequence.length; const ratios = {}; Object.keys(letterCounts).forEach(letter => { const count = letterCounts[letter]; ratios[letter] = { count: count, percentage: (count / total * 100).toFixed(2), ratio: (count / total).toFixed(4) }; }); updateRatioDisplay(ratios, total); calculateTotalValue(); } function updateRatioDisplay(ratios, total) { const ratioGrid = document.getElementById('ratio-grid'); if (!ratioGrid) return; ratioGrid.innerHTML = ''; const ratioSum = document.getElementById('ratio-sum'); if (ratioSum) ratioSum.textContent = total; Object.entries(ratios).forEach(([letter, data]) => { const card = document.createElement('div'); card.className = 'ratio-card'; const color = getLetterColor(letter); const percentage = parseFloat(data.percentage); card.innerHTML = `
${letter}
${data.count} occurrences
${data.percentage}%
`; ratioGrid.appendChild(card); }); } function calculateTotalValue() { if (!currentSequence || currentSequence.length === 0) return; let total = 0; currentSequence.forEach(letter => { total += letterValues[letter] || 0; }); const totalValueSpan = document.getElementById('total-value'); if (totalValueSpan) { totalValueSpan.textContent = total.toLocaleString(); } } // ============================================ // LIGHT POINTS ANIMATION // ============================================ const lightCanvas = document.getElementById('light-canvas'); const lightCtx = lightCanvas ? lightCanvas.getContext('2d') : null; let lightParticles = []; function initLightPoints() { if (!lightCanvas || !lightCtx) return; const rect = lightCanvas.getBoundingClientRect(); lightCanvas.width = rect.width; lightCanvas.height = rect.height; // Créer des particules pour أ ل ف const letters = ['أ', 'ل', 'ف']; const colors = letters.map(l => getLetterColor(l)); lightParticles = []; for (let i = 0; i < 50; i++) { const letterIndex = i % letters.length; lightParticles.push({ x: Math.random() * lightCanvas.width, y: Math.random() * lightCanvas.height, vx: (Math.random() - 0.5) * 2, vy: (Math.random() - 0.5) * 2, size: Math.random() * 3 + 2, color: colors[letterIndex], letter: letters[letterIndex], alpha: Math.random() }); } animateLightPoints(); } function animateLightPoints() { if (!lightCanvas || !lightCtx) return; lightCtx.fillStyle = 'rgba(0, 0, 0, 0.1)'; lightCtx.fillRect(0, 0, lightCanvas.width, lightCanvas.height); lightParticles.forEach(p => { // Update position p.x += p.vx; p.y += p.vy; // Bounce if (p.x < 0 || p.x > lightCanvas.width) p.vx *= -1; if (p.y < 0 || p.y > lightCanvas.height) p.vy *= -1; // Draw glow const gradient = lightCtx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 3); gradient.addColorStop(0, p.color); gradient.addColorStop(1, 'transparent'); lightCtx.fillStyle = gradient; lightCtx.beginPath(); lightCtx.arc(p.x, p.y, p.size * 3, 0, Math.PI * 2); lightCtx.fill(); // Draw core lightCtx.fillStyle = p.color; lightCtx.shadowColor = p.color; lightCtx.shadowBlur = 15; lightCtx.beginPath(); lightCtx.arc(p.x, p.y, p.size, 0, Math.PI * 2); lightCtx.fill(); lightCtx.shadowBlur = 0; }); requestAnimationFrame(animateLightPoints); } // ============================================ // MATHEMATICAL RATIOS VISUALIZATION // ============================================ const PHI = 1.618033988749895; function drawMathematicalRatios() { if (!currentSequence || currentSequence.length === 0) return; drawPhiRatio(); drawLetterRatios(); drawFractalTriangles(); drawGeometricDistribution(); } function drawPhiRatio() { const canvas = document.getElementById('phi-canvas'); if (!canvas) return; const ctx = canvas.getContext('2d'); const rect = canvas.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; const w = canvas.width; const h = canvas.height; ctx.fillStyle = '#020617'; ctx.fillRect(0, 0, w, h); const cx = w / 2; const cy = h / 2; const maxRadius = Math.min(w, h) * 0.4; // Spirale d'or ctx.strokeStyle = '#22c55e'; ctx.lineWidth = 2; ctx.beginPath(); let angle = 0; const turns = 4; const steps = 200; for (let i = 0; i <= steps; i++) { const t = i / steps; angle = t * turns * Math.PI * 2; const radius = maxRadius * Math.pow(PHI, t * 2 - 2); const x = cx + radius * Math.cos(angle); const y = cy + radius * Math.sin(angle); if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); } ctx.stroke(); // Rectangles dorés let size = maxRadius / 2; let x = cx - size / 2; let y = cy - size / 2; ctx.strokeStyle = '#22c55e40'; ctx.lineWidth = 1; for (let i = 0; i < 5; i++) { ctx.strokeRect(x, y, size, size / PHI); y += size / PHI; size = size / PHI; } const phiValue = document.getElementById('phi-value'); if (phiValue) phiValue.textContent = `φ = ${PHI.toFixed(6)}... (Nombre d'or)`; } function drawLetterRatios() { const canvas = document.getElementById('letter-ratio-canvas'); if (!canvas) return; const ctx = canvas.getContext('2d'); const rect = canvas.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; const w = canvas.width; const h = canvas.height; ctx.fillStyle = '#020617'; ctx.fillRect(0, 0, w, h); const letters = Object.keys(letterCounts).sort((a, b) => letterCounts[b] - letterCounts[a]); if (letters.length < 2) return; const ratiosList = document.getElementById('letter-ratios'); if (ratiosList) { ratiosList.innerHTML = ''; for (let i = 0; i < letters.length - 1; i++) { const letter1 = letters[i]; const letter2 = letters[i + 1]; const count1 = letterCounts[letter1]; const count2 = letterCounts[letter2]; const ratio = (count1 / count2).toFixed(3); const item = document.createElement('div'); item.className = 'ratio-item'; item.innerHTML = ` ${letter1} / ${letter2} ${ratio} `; ratiosList.appendChild(item); } } const cx = w / 2; const cy = h / 2; const radius = Math.min(w, h) * 0.35; const total = Object.values(letterCounts).reduce((a, b) => a + b, 0); let currentAngle = -Math.PI / 2; letters.forEach(letter => { const count = letterCounts[letter]; const proportion = count / total; const angleSpan = proportion * Math.PI * 2; const color = getLetterColor(letter); ctx.beginPath(); ctx.arc(cx, cy, radius, currentAngle, currentAngle + angleSpan); ctx.lineTo(cx, cy); ctx.closePath(); ctx.fillStyle = color + '40'; ctx.fill(); ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.stroke(); const midAngle = currentAngle + angleSpan / 2; const labelRadius = radius * 0.7; const lx = cx + labelRadius * Math.cos(midAngle); const ly = cy + labelRadius * Math.sin(midAngle); ctx.fillStyle = color; ctx.font = 'bold 20px Arial'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(letter, lx, ly); currentAngle += angleSpan; }); } function drawFractalTriangles() { const canvas = document.getElementById('fractal-triangle-canvas'); if (!canvas) return; const ctx = canvas.getContext('2d'); const rect = canvas.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; const w = canvas.width; const h = canvas.height; ctx.fillStyle = '#020617'; ctx.fillRect(0, 0, w, h); const values = currentSequence.slice(0, 100).map(l => letterValues[l] || 1); const cx = w / 2; const cy = h / 2; const maxRadius = Math.min(w, h) * 0.4; let index = 0; function drawTriangleLevel(centerX, centerY, radius, depth) { if (depth >= 4 || index >= values.length) return; const value = values[index]; const color = getLetterColor(currentSequence[index]); index++; const points = []; for (let i = 0; i < 3; i++) { const angle = (i * 2 * Math.PI / 3) - Math.PI / 2; const r = radius * (value / 80); points.push({ x: centerX + r * Math.cos(angle), y: centerY + r * Math.sin(angle) }); } ctx.beginPath(); ctx.moveTo(points[0].x, points[0].y); ctx.lineTo(points[1].x, points[1].y); ctx.lineTo(points[2].x, points[2].y); ctx.closePath(); ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.stroke(); ctx.fillStyle = color + '20'; ctx.fill(); points.forEach(p => { drawTriangleLevel(p.x, p.y, radius * 0.4, depth + 1); }); } drawTriangleLevel(cx, cy, maxRadius, 0); const info = document.getElementById('triangle-info'); if (info) info.textContent = `${values.length} valeurs • 4 niveaux`; } function drawGeometricDistribution() { const canvas = document.getElementById('geometric-dist-canvas'); if (!canvas) return; const ctx = canvas.getContext('2d'); const rect = canvas.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; const w = canvas.width; const h = canvas.height; ctx.fillStyle = '#020617'; ctx.fillRect(0, 0, w, h); const letters = Object.keys(letterCounts); const cx = w / 2; const cy = h / 2; const maxRadius = Math.min(w, h) * 0.35; letters.forEach((letter, i) => { const count = letterCounts[letter]; const sides = Math.min(3 + Math.floor(count / 20), 12); const color = getLetterColor(letter); const radius = maxRadius * (0.3 + (count / currentSequence.length) * 0.7); const rotation = (i * Math.PI * 2 / letters.length); ctx.beginPath(); for (let j = 0; j <= sides; j++) { const angle = (j * 2 * Math.PI / sides) + rotation; const x = cx + radius * Math.cos(angle); const y = cy + radius * Math.sin(angle); if (j === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); } ctx.closePath(); ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.stroke(); ctx.fillStyle = color + '15'; ctx.fill(); const labelAngle = rotation + Math.PI / sides; const labelRadius = radius * 0.6; const lx = cx + labelRadius * Math.cos(labelAngle); const ly = cy + labelRadius * Math.sin(labelAngle); ctx.fillStyle = color; ctx.font = 'bold 16px Arial'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(`${letter} (${sides})`, lx, ly); }); const info = document.getElementById('geometric-info'); if (info) info.textContent = `Polygones 3-12 côtés selon fréquence`; } // ============================================ // CIRCLE VIEW // ============================================ const circleCanvas = document.getElementById('circle-canvas'); // ============================================ // DASHBOARD SYSTEM // ============================================ const dashboardModal = document.getElementById('letter-dashboard'); const closeDashboardBtn = document.getElementById('close-dashboard'); let progressionChart = null; let distributionChart = null; closeDashboardBtn.addEventListener('click', () => { closeDashboard(); }); // Fermer avec Escape document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && dashboardModal.style.display === 'block') { closeDashboard(); } }); function openDashboard(letter) { dashboardModal.style.display = 'block'; document.getElementById('dashboard-letter').textContent = letter; document.getElementById('chart-letter').textContent = letter; // Calculer les statistiques pour cette lettre const letterStats = calculateLetterStats(letter); // Afficher les stats displayLetterStats(letterStats); // Créer les graphiques createProgressionChart(letter); createDistributionChart(); // Animer la fenêtre de couleur animateColorWindow(letter); } function closeDashboard() { dashboardModal.style.display = 'none'; if (progressionChart) { progressionChart.destroy(); progressionChart = null; } if (distributionChart) { distributionChart.destroy(); distributionChart = null; } } function calculateLetterStats(letter) { const count = letterCounts[letter] || 0; const percentage = ((count / currentSequence.length) * 100).toFixed(2); const firstAppearance = currentSequence.indexOf(letter) + 1; const lastAppearance = currentSequence.lastIndexOf(letter) + 1; return { count, percentage, firstAppearance, lastAppearance, totalLength: currentSequence.length }; } function displayLetterStats(stats) { const statsContainer = document.getElementById('visual-stats'); if (!statsContainer) return; const letter = document.getElementById('dashboard-letter').textContent; const color = getLetterColor(letter); const percentage = parseFloat(stats.percentage); statsContainer.innerHTML = `
${stats.count}
Occurrences totales
${stats.percentage}%
${stats.percentage}% de la séquence
${stats.firstAppearance}
Première apparition
Position ${stats.firstAppearance}
${stats.lastAppearance}
Dernière apparition
Position ${stats.lastAppearance}
Total: ${stats.totalLength} lettres
`; // Créer aussi le panneau de ratios createRatioPanel(letter); } function createProgressionChart(letter) { const ctx = document.getElementById('progression-chart'); if (!ctx) return; // Calculer la progression du nombre d'occurrences const data = sequenceHistory.map((entry, index) => { const count = entry.sequence.filter(l => l === letter).length; return { x: entry.depth, y: count }; }); if (progressionChart) { progressionChart.destroy(); } progressionChart = new Chart(ctx, { type: 'line', data: { datasets: [{ label: `Occurrences de ${letter}`, data: data, borderColor: getLetterColor(letter), backgroundColor: getLetterColor(letter) + '20', borderWidth: 3, tension: 0.4, fill: true }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { labels: { color: '#e6edf3' } } }, scales: { x: { type: 'linear', title: { display: true, text: 'Profondeur', color: '#8b949e' }, ticks: { color: '#8b949e' }, grid: { color: '#1f2933' } }, y: { title: { display: true, text: 'Nombre d\'occurrences', color: '#8b949e' }, ticks: { color: '#8b949e' }, grid: { color: '#1f2933' } } } } }); } function createDistributionChart() { const ctx = document.getElementById('distribution-chart'); if (!ctx) return; const letters = Object.keys(letterCounts); const counts = Object.values(letterCounts); const colors = letters.map(l => getLetterColor(l)); if (distributionChart) { distributionChart.destroy(); } distributionChart = new Chart(ctx, { type: 'doughnut', data: { labels: letters, datasets: [{ data: counts, backgroundColor: colors, borderColor: '#0a0e14', borderWidth: 2 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom', labels: { color: '#e6edf3', font: { size: 14 } } } } } }); } function animateColorWindow(letter) { const canvas = document.getElementById('fractal-visual'); if (!canvas) return; const ctx = canvas.getContext('2d'); const rect = canvas.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; const color = getLetterColor(letter); const centerX = canvas.width / 2; const centerY = canvas.height / 2; let frame = 0; function animate() { // Background noir ctx.fillStyle = '#000'; ctx.fillRect(0, 0, canvas.width, canvas.height); // Cercles concentriques pulsants for (let i = 5; i > 0; i--) { const radius = 20 * i + Math.sin(frame / 20 + i) * 10; const alpha = 0.3 - i * 0.05; // Glow externe const gradient = ctx.createRadialGradient( centerX, centerY, radius * 0.8, centerX, centerY, radius ); gradient.addColorStop(0, color + '00'); gradient.addColorStop(1, color + Math.floor(alpha * 255).toString(16).padStart(2, '0')); ctx.fillStyle = gradient; ctx.beginPath(); ctx.arc(centerX, centerY, radius, 0, Math.PI * 2); ctx.fill(); // Cercle de contour ctx.strokeStyle = color + Math.floor(alpha * 128).toString(16).padStart(2, '0'); ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(centerX, centerY, radius, 0, Math.PI * 2); ctx.stroke(); } // Centre lumineux ctx.fillStyle = color; ctx.shadowColor = color; ctx.shadowBlur = 30; ctx.beginPath(); ctx.arc(centerX, centerY, 15, 0, Math.PI * 2); ctx.fill(); ctx.shadowBlur = 0; // Lettre au centre ctx.fillStyle = '#000'; ctx.font = 'bold 24px Arial'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(letter, centerX, centerY); frame++; requestAnimationFrame(animate); } animate(); } function createRatioPanel(letter) { const ratioPanel = document.querySelector('.ratio-panel'); if (!ratioPanel) return; const ratioBars = document.getElementById('ratio-bars'); if (!ratioBars) return; ratioBars.innerHTML = ''; // Calculer le ratio de cette lettre par rapport aux autres const total = currentSequence.length; const sortedLetters = Object.entries(letterCounts).sort((a, b) => b[1] - a[1]); sortedLetters.forEach(([l, count]) => { const percentage = (count / total * 100).toFixed(2); const color = getLetterColor(l); const isSelected = l === letter; const barItem = document.createElement('div'); barItem.className = 'ratio-bar-item'; barItem.style.opacity = isSelected ? '1' : '0.6'; barItem.innerHTML = `
${l}
${count} (${percentage}%)
`; ratioBars.appendChild(barItem); }); } // ============================================ // PDF EXPORT // ============================================ function exportToPDF() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Titre doc.setFontSize(20); doc.text('Temple AIA - Séquence Fractale', 20, 20); // Info doc.setFontSize(12); doc.text(`Profondeur: ${currentDepth}`, 20, 35); doc.text(`Longueur: ${currentSequence.length} lettres`, 20, 45); doc.text(`Date: ${new Date().toLocaleDateString('fr-FR')}`, 20, 55); // Séquence doc.setFontSize(10); doc.text('Séquence générée:', 20, 70); const sequenceText = currentSequence.join(' '); const lines = doc.splitTextToSize(sequenceText, 170); doc.text(lines, 20, 80); // Statistiques let yPos = 80 + (lines.length * 5) + 10; doc.setFontSize(14); doc.text('Statistiques:', 20, yPos); yPos += 10; doc.setFontSize(10); Object.entries(letterCounts).forEach(([letter, count]) => { const percentage = ((count / currentSequence.length) * 100).toFixed(2); doc.text(`${letter}: ${count} occurrences (${percentage}%)`, 30, yPos); yPos += 7; }); // Règles fractales yPos += 10; doc.setFontSize(12); doc.text('Règles fractales:', 20, yPos); yPos += 8; doc.setFontSize(9); doc.text('أ → ا ل ف (alif)', 30, yPos); yPos += 6; doc.text('ل → ل ا م (lam)', 30, yPos); yPos += 6; doc.text('ف → ف ا (fa)', 30, yPos); yPos += 6; doc.text('م → م ي م (mim)', 30, yPos); yPos += 6; doc.text('ي → ي ا (ya)', 30, yPos); // Footer doc.setFontSize(8); doc.text('Temple AIA - Système d\'information fractale', 20, 280); // Sauvegarder doc.save(`temple-aia-sequence-depth${currentDepth}.pdf`); } // ============================================ // CIRCLE VIEW // ============================================ const circleCtx = circleCanvas ? circleCanvas.getContext('2d') : null; const rotationSlider = document.getElementById('rotation-slider'); const rotationDisplay = document.getElementById('rotation-display'); let rotationAngle = 0; if (rotationSlider) { rotationSlider.addEventListener('input', () => { rotationAngle = parseInt(rotationSlider.value); rotationDisplay.textContent = `${rotationAngle}°`; drawCircle(); }); } function setupCanvas(canvas) { if (!canvas) return; const rect = canvas.getBoundingClientRect(); canvas.width = rect.width * window.devicePixelRatio; canvas.height = rect.height * window.devicePixelRatio; const ctx = canvas.getContext('2d'); ctx.scale(window.devicePixelRatio, window.devicePixelRatio); return { width: rect.width, height: rect.height }; } function drawCircle() { if (!circleCanvas || !circleCtx) return; const dims = setupCanvas(circleCanvas); const { width, height } = dims; circleCtx.clearRect(0, 0, width, height); // Background gradient const grad = circleCtx.createRadialGradient(width/2, height/2, 0, width/2, height/2, width/2); grad.addColorStop(0, '#0f1419'); grad.addColorStop(1, '#0a0e14'); circleCtx.fillStyle = grad; circleCtx.fillRect(0, 0, width, height); const cx = width / 2; const cy = height / 2; const baseRadius = Math.min(width, height) * 0.15; const maxRadius = Math.min(width, height) * 0.4; const colors = { 'أ': '#22c55e', 'ا': '#22c55e', // Alif sans hamza 'ل': '#38bdf8', 'ف': '#f97316', 'م': '#a855f7', 'ي': '#eab308' }; const radiusFactors = { 'أ': 0.2, 'ا': 0.2, // Alif sans hamza 'ل': 0.4, 'م': 0.6, 'ي': 0.8, 'ف': 1.0 }; // Draw center circle circleCtx.beginPath(); circleCtx.arc(cx, cy, baseRadius * 0.5, 0, Math.PI * 2); circleCtx.strokeStyle = 'rgba(34, 197, 94, 0.3)'; circleCtx.lineWidth = 2; circleCtx.stroke(); // Draw center point circleCtx.beginPath(); circleCtx.arc(cx, cy, 4, 0, Math.PI * 2); circleCtx.fillStyle = '#22c55e'; circleCtx.fill(); // Draw sequence points const count = currentSequence.length; const angleOffset = (rotationAngle * Math.PI) / 180; for (let i = 0; i < count; i++) { const letter = currentSequence[i]; const angle = (i / count) * Math.PI * 2 - Math.PI / 2 + angleOffset; const rFactor = radiusFactors[letter] || 0.5; const radius = baseRadius + rFactor * (maxRadius - baseRadius); const x = cx + radius * Math.cos(angle); const y = cy + radius * Math.sin(angle); // Draw line from center circleCtx.beginPath(); circleCtx.moveTo(cx, cy); circleCtx.lineTo(x, y); circleCtx.strokeStyle = 'rgba(139, 148, 158, 0.1)'; circleCtx.lineWidth = 1; circleCtx.stroke(); // Draw point circleCtx.beginPath(); circleCtx.arc(x, y, 5, 0, Math.PI * 2); circleCtx.fillStyle = colors[letter] || '#6b7280'; circleCtx.shadowColor = colors[letter] || '#6b7280'; circleCtx.shadowBlur = 10; circleCtx.fill(); circleCtx.shadowBlur = 0; } } // ============================================ // TRIANGLE VIEW // ============================================ const triangleCanvas = document.getElementById('triangle-canvas'); const triangleCtx = triangleCanvas ? triangleCanvas.getContext('2d') : null; const triangleFillCheck = document.getElementById('triangle-fill'); const triangleLinesCheck = document.getElementById('triangle-lines'); const triangleAnimateBtn = document.getElementById('triangle-animate'); let triangleAnimationFrame = 0; let isAnimating = false; if (triangleAnimateBtn) { triangleAnimateBtn.addEventListener('click', () => { isAnimating = !isAnimating; if (isAnimating) { triangleAnimateBtn.innerHTML = '⏸ Pause'; animateTriangle(); } else { triangleAnimateBtn.innerHTML = '▶ Animer'; } }); } if (triangleFillCheck) triangleFillCheck.addEventListener('change', drawTriangle); if (triangleLinesCheck) triangleLinesCheck.addEventListener('change', drawTriangle); function drawTriangle() { if (!triangleCanvas || !triangleCtx) return; const dims = setupCanvas(triangleCanvas); const { width, height } = dims; triangleCtx.clearRect(0, 0, width, height); // Background triangleCtx.fillStyle = '#0f1419'; triangleCtx.fillRect(0, 0, width, height); const cx = width / 2; const cy = height / 2; const size = Math.min(width, height) * 0.35; const showFill = triangleFillCheck && triangleFillCheck.checked; const showLines = triangleLinesCheck && triangleLinesCheck.checked; // Draw main triangle const points = [ { x: cx, y: cy - size }, { x: cx - size * Math.cos(Math.PI / 6), y: cy + size * Math.sin(Math.PI / 6) }, { x: cx + size * Math.cos(Math.PI / 6), y: cy + size * Math.sin(Math.PI / 6) } ]; if (showFill) { triangleCtx.beginPath(); triangleCtx.moveTo(points[0].x, points[0].y); triangleCtx.lineTo(points[1].x, points[1].y); triangleCtx.lineTo(points[2].x, points[2].y); triangleCtx.closePath(); triangleCtx.fillStyle = 'rgba(34, 197, 94, 0.1)'; triangleCtx.fill(); } if (showLines) { triangleCtx.beginPath(); triangleCtx.moveTo(points[0].x, points[0].y); triangleCtx.lineTo(points[1].x, points[1].y); triangleCtx.lineTo(points[2].x, points[2].y); triangleCtx.closePath(); triangleCtx.strokeStyle = '#22c55e'; triangleCtx.lineWidth = 2; triangleCtx.stroke(); } // Draw fractals drawSierpinskiLevel(triangleCtx, points[0], points[1], points[2], 3, showLines, showFill); // Draw vertices points.forEach(p => { triangleCtx.beginPath(); triangleCtx.arc(p.x, p.y, 6, 0, Math.PI * 2); triangleCtx.fillStyle = '#22c55e'; triangleCtx.shadowColor = '#22c55e'; triangleCtx.shadowBlur = 10; triangleCtx.fill(); triangleCtx.shadowBlur = 0; }); } function drawSierpinskiLevel(ctx, p1, p2, p3, depth, lines, fill) { if (depth === 0) return; const mid1 = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 }; const mid2 = { x: (p2.x + p3.x) / 2, y: (p2.y + p3.y) / 2 }; const mid3 = { x: (p3.x + p1.x) / 2, y: (p3.y + p1.y) / 2 }; if (fill) { ctx.beginPath(); ctx.moveTo(mid1.x, mid1.y); ctx.lineTo(mid2.x, mid2.y); ctx.lineTo(mid3.x, mid3.y); ctx.closePath(); ctx.fillStyle = `rgba(34, 197, 94, ${0.05 * depth})`; ctx.fill(); } if (lines) { ctx.beginPath(); ctx.moveTo(mid1.x, mid1.y); ctx.lineTo(mid2.x, mid2.y); ctx.lineTo(mid3.x, mid3.y); ctx.closePath(); ctx.strokeStyle = `rgba(34, 197, 94, ${0.3 + depth * 0.1})`; ctx.lineWidth = 1; ctx.stroke(); } drawSierpinskiLevel(ctx, p1, mid1, mid3, depth - 1, lines, fill); drawSierpinskiLevel(ctx, mid1, p2, mid2, depth - 1, lines, fill); drawSierpinskiLevel(ctx, mid3, mid2, p3, depth - 1, lines, fill); } function animateTriangle() { if (!isAnimating) return; triangleAnimationFrame++; rotationAngle = (rotationAngle + 1) % 360; drawTriangle(); requestAnimationFrame(animateTriangle); } // ============================================ // TREE VIEW // ============================================ const treeCanvas = document.getElementById('tree-canvas'); const treeCtx = treeCanvas ? treeCanvas.getContext('2d') : null; const treeDepthSlider = document.getElementById('tree-depth-slider'); const treeDepthDisplay = document.getElementById('tree-depth-display'); let treeDepth = 3; if (treeDepthSlider) { treeDepthSlider.addEventListener('input', () => { treeDepth = parseInt(treeDepthSlider.value); treeDepthDisplay.textContent = treeDepth; drawTree(); }); } function drawTree() { if (!treeCanvas || !treeCtx) return; const dims = setupCanvas(treeCanvas); const { width, height } = dims; treeCtx.clearRect(0, 0, width, height); // Background treeCtx.fillStyle = '#0f1419'; treeCtx.fillRect(0, 0, width, height); const startX = width / 2; const startY = height - 50; const colors = { 'أ': '#22c55e', 'ا': '#22c55e', // Alif sans hamza 'ل': '#38bdf8', 'ف': '#f97316', 'م': '#a855f7', 'ي': '#eab308' }; // Draw root treeCtx.beginPath(); treeCtx.arc(startX, startY, 8, 0, Math.PI * 2); treeCtx.fillStyle = colors['أ']; treeCtx.shadowColor = colors['أ']; treeCtx.shadowBlur = 15; treeCtx.fill(); treeCtx.shadowBlur = 0; // Draw tree structure drawTreeBranch(treeCtx, startX, startY, -90, 80, treeDepth, 'أ', colors); } function drawTreeBranch(ctx, x, y, angle, length, depth, letter, colors) { if (depth === 0 || length < 10) return; const rad = (angle * Math.PI) / 180; const newX = x + length * Math.cos(rad); const newY = y + length * Math.sin(rad); // Draw line ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(newX, newY); ctx.strokeStyle = `rgba(139, 148, 158, ${0.3 + depth * 0.1})`; ctx.lineWidth = depth; ctx.stroke(); // Draw node const nodeSize = 4 + depth; ctx.beginPath(); ctx.arc(newX, newY, nodeSize, 0, Math.PI * 2); ctx.fillStyle = colors[letter] || '#6b7280'; ctx.shadowColor = colors[letter] || '#6b7280'; ctx.shadowBlur = 8; ctx.fill(); ctx.shadowBlur = 0; // Define branches based on letter name rules const branches = { 'أ': [ { letter: 'ا', angle: -45, length: 0.7 }, { letter: 'ل', angle: -15, length: 0.7 }, { letter: 'ف', angle: 15, length: 0.7 } ], 'ا': [ { letter: 'ا', angle: -45, length: 0.7 }, { letter: 'ل', angle: -15, length: 0.7 }, { letter: 'ف', angle: 15, length: 0.7 } ], 'ل': [ { letter: 'ل', angle: -30, length: 0.65 }, { letter: 'ا', angle: 0, length: 0.65 }, { letter: 'م', angle: 30, length: 0.65 } ], 'ف': [ { letter: 'ف', angle: -20, length: 0.6 }, { letter: 'ا', angle: 20, length: 0.6 } ], 'م': [ { letter: 'م', angle: -30, length: 0.6 }, { letter: 'ي', angle: 0, length: 0.6 }, { letter: 'م', angle: 30, length: 0.6 } ], 'ي': [ { letter: 'ي', angle: -20, length: 0.6 }, { letter: 'ا', angle: 20, length: 0.6 } ] }; const nextBranches = branches[letter] || []; nextBranches.forEach(branch => { drawTreeBranch( ctx, newX, newY, angle + branch.angle, length * branch.length, depth - 1, branch.letter, colors ); }); } // ============================================ // INITIALIZATION // ============================================ window.addEventListener('resize', () => { drawCircle(); drawTriangle(); drawTree(); }); // Initial draw setTimeout(() => { drawCircle(); drawTriangle(); drawTree(); // Initialiser les statistiques trackSequenceHistory(); updateStats(); displaySequence(currentSequence); }, 100);