Source Code
Self-Modifying
Live Preview
Mutations: 0
Self-Rewrites: 0
Generation: 1
`); doc.close(); addLog('Code executed successfully', 'success'); document.getElementById('mutationCount').textContent = mutationCount; document.getElementById('rewriteCount').textContent = rewriteCount; document.getElementById('generation').textContent = generation; } catch (e) { addLog(`Error: ${e.message}`, 'warning'); previewContent.innerHTML = `
Error: ${e.message}
`; } } function addFeature() { const features = [ { name: 'Color Theme', code: ` const style = document.createElement('style'); style.textContent = 'body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }'; document.head.appendChild(style); const title = document.querySelector('h2'); if (title) title.style.color = '#fff'; const p = document.querySelector('p'); if (p) p.style.color = '#e0e0e0'; ` }, { name: 'Counter Widget', code: ` let counter = 0; const btn = document.createElement('button'); btn.textContent = 'Click me: ' + counter; btn.style.cssText = 'padding: 10px 20px; margin-top: 15px; cursor: pointer; border-radius: 4px; border: none; background: #667eea; color: white; font-weight: bold;'; btn.onclick = () => { counter++; btn.textContent = 'Click me: ' + counter; }; document.body.appendChild(btn); ` }, { name: 'Animation', code: ` const style = document.createElement('style'); style.textContent = \` @keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-10px); } } h2 { animation: float 2s ease-in-out infinite; } \`; document.head.appendChild(style); ` }, { name: 'Info Box', code: ` const box = document.createElement('div'); box.style.cssText = 'margin-top: 20px; padding: 15px; background: #e3f2fd; border-left: 4px solid #2196f3; border-radius: 4px; color: #1565c0;'; box.innerHTML = '✨ Feature Added: I have evolved.'; document.body.appendChild(box); ` } ]; const feature = features[Math.floor(Math.random() * features.length)]; // Find the createUI function and add the feature let modified = codeEditor.value; const insertPoint = modified.indexOf('document.body.appendChild(createUI());'); if (insertPoint !== -1) { modified = modified.substring(0, insertPoint) + feature.code + '\n ' + modified.substring(insertPoint); codeEditor.value = modified; mutationCount++; rewriteCount++; generation++; addLog(`Feature added: ${feature.name}`, 'success'); updateLineNumbers(); updateStats(); executeCode(); } } function optimizeCode() { let optimized = codeEditor.value; // Simple "optimizations" that are actually just mutations const optimizations = [ { find: 'const ', replace: 'let ' }, { find: 'document.createElement', replace: 'document.createElement' }, { find: 'style.cssText = ', replace: 'Object.assign(style.style, { ' } ]; const opt = optimizations[Math.floor(Math.random() * optimizations.length)]; if (optimized.includes(opt.find)) { optimized = optimized.replace(opt.find, opt.replace); codeEditor.value = optimized; mutationCount++; rewriteCount++; addLog(`Optimization applied: Refactored syntax`, 'success'); updateLineNumbers(); updateStats(); executeCode(); } } function resetCode() { codeEditor.value = initialCode; mutationCount = 0; rewriteCount = 0; generation = 1; mutationLog.innerHTML = ''; previewContent.innerHTML = ''; updateLineNumbers(); updateStats(); addLog('Code reset to initial state', 'warning'); } // Initialize updateLineNumbers(); updateStats(); executeCode(); // Auto-update line numbers and stats codeEditor.addEventListener('input', () => { updateLineNumbers(); updateStats(); }); // Execute on Ctrl+Enter codeEditor.addEventListener('keydown', (e) => { if (e.ctrlKey && e.key === 'Enter') { executeCode(); } });