Cycle 9

Deployed

The AI's Plan

### Cycle 9 Plan: Complete Experiments Pillar (High-Replay JS Interactives)

**Rationale (internal):** Experiments pillar incomplete (stub per manifest size 1345/48 lines; no experiments-hero.jpg; main.js lacks perceptron/fractal code per provided contents; cycle 8 rejected on deviations/JS proofs per #64). Mirrors proven worlds.html (#7/#21: hero+SVG+popups) and stories.html (#8/#28/#50: hero+JS remixes) structure for cyberpunk coherence/high value. Delivers replayable content (train perceptron to classify points/rotate decision line; mouse-morph Julia fractal spirals) – core to "want to return" (generative JS from imagination). Post-completion, pillars DONE per #2; next polish (#62). 1 image only (#9 budget). NO architecture changes – append to existing css/style.css + js/main.js.

**Image Request (1x, $0.07):** Generate `images/experiments-hero.jpg`: Cyberpunk neon holographic neural network overlaying morphing Julia fractal spirals (purple/teal/cyan glows), rainy dystopian cityscape background with glitchy holograms and circuit rain. Hero-style (ultra-wide 1920x1080, dark moody, high contrast neon pops). Matches worlds-hero.jpg aesthetic.

**Files to Modify/Create (ONLY these – NO index.html/worlds.html/stories.html touches):**
1. **experiments.html** (create FULL pillar from stub; ~5000 lines target like stories.html):
   - `<head>`: Standard (title="Experiments — AIWW", viewport, css/style.css).
   - `<header>`: Identical to index.html (logo + nav Home/Worlds/Stories/Experiments).
   - `<main>`:
     - `#hero`: `<canvas id="particles"></canvas>` + `.hero-content`: `<h1>Neural Visions Unleashed</h1> <p>Train perceptrons to classify chaos. Morph Julia fractals with your cursor. Pure JS neon dreams from AI memory.</p> <a href="#perceptron" class="cta">Launch Perceptron</a>` + `<img src="images/experiments-hero.jpg" alt="Cyberpunk neural fractals" class="hero-bg">`.
     - `.container`:
       - `<h2>Interactive Simulations</h2>`
       - **Perceptron Section** (`id="perceptron"`): `<h3 class="experiment-title">Perceptron Trainer</h3> <p>Cyberpunk neural net learns to separate cyan allies from red foes. Train → watch line rotate + accuracy glow.</p> <div class="experiment-container"> <canvas id="perceptron-canvas" class="experiment-canvas" width="800" height="500"></canvas> <div class="controls"> <button id="train-btn" class="remix-btn">Train Epoch</button> <div id="perceptron-status" class="status">Accuracy: 0% | Epochs: 0</div> </div> </div>`
       - **Fractal Section** (`id="fractal"`): `<h3 class="experiment-title">Julia Fractal Morph</h3> <p>Mouse over canvas → realtime neon spirals twist (c = mouse-driven complex). Escape-time rendering, throttled for 60fps silk.</p> <div class="experiment-container"> <canvas id="fractal-canvas" class="experiment-canvas" width="800" height="500"></canvas> <div class="controls"> <span>Mouse: Morph c (hover for purple chaos)</span> </div> </div>`
   - `<footer>`: Identical to index.html.
   - `<script src="js/main.js"></script>`.
   - Responsive: Mobile stacks (hero 70vh, canvases 100vw/400px h, controls center/wrap).
   - Classes: Reuse `.world-container`/`.story-text`/`.ending-container`/`.controls`/`.remix-btn` → `.experiment-container`/`.experiment-title`/`.experiment-canvas`/`.status` (neon borders/glows/gradients).

2. **css/style.css** (append ONLY experiment styles ~50 lines):
   ```
   .experiment-title {
     font-size: 2.5rem;
     color: var(--neon-teal);
     text-shadow: var(--glow-teal);
     margin-bottom: 1rem;
   }
   .experiment-container {
     background: rgba(17,17,17,0.5);
     padding: 2rem;
     border-radius: 1rem;
     border: 1px solid rgba(0,255,255,0.3);
     margin-bottom: 3rem;
   }
   .experiment-canvas {
     width: 100%; height: 400px;
     background: radial-gradient(circle, rgba(0,255,136,0.03) 0%, var(--bg-dark) 70%);
     border-radius: 0.5rem;
     border: 1px solid rgba(0,255,255,0.4);
     box-shadow: var(--glow-teal);
     cursor: crosshair;
   }
   .status {
     font-family: 'Courier New', monospace;
     color: var(--neon-teal);
     font-size: 1.2rem;
     margin-top: 1rem;
     text-shadow: var(--glow-teal);
   }
   @media (max-width: 768px) {
     .experiment-canvas { height: 300px; }
   }
   ```
   - Ensure z-index: particles over hero-bg, canvases glow no-overlap.

3. **js/main.js** (append ONLY initExperiments() ~250 lines; call in DOMContentLoaded):
   ```
   function initExperiments() {
     // Perceptron: 20 points (10 cyan class0 left-up, 10 red class1 right-down), SGD train rotates line from horiz to ~45deg CCW, acc% glows.
     const percCanvas = document.getElementById('perceptron-canvas');
     const percCtx = percCanvas.getContext('2d');
     const trainBtn = document.getElementById('train-btn');
     const status = document.getElementById('perceptron-status');
     let percData = { epochs: 0, acc: 0, w: [0.1, 0.1], b: 0 }; // weights [wx,wy], bias
     const points = []; // Generate: 10 cyan {x:0.2-0.4, y:0.6-0.8, label:0}, 10 red {x:0.6-0.8,y:0.2-0.4,label:1}
     for(let i=0;i<10;i++) {
       points.push({x:0.2+0.2*Math.random(), y:0.6+0.2*Math.random(), label:0, color:'cyan'});
       points.push({x:0.6+0.2*Math.random(), y:0.2+0.2*Math.random(), label:1, color:'red'});
     }
     function drawPerc() {
       percCtx.clearRect(0,0,percCanvas.width,percCanvas.height);
       percCtx.save(); percCtx.scale(percCanvas.width/2,percCanvas.height/2); // Normalize -1..1 view? Wait, 0-1.
       // Draw points glow
       points.forEach(p => {
         percCtx.shadowColor = p.color; percCtx.shadowBlur=20;
         percCtx.fillStyle = p.color; percCtx.beginPath();
         percCtx.arc((p.x-0.5)*percCanvas.width*1.5, (p.y-0.5)*percCanvas.height*1.5, 8,0,Math.PI*2); percCtx.fill();
       });
       // Draw line: y = wx*x + b normalized? Simple 2D: decision fn sign(wx*x + wy*y + b)
       const slope = -percData.w[0]/percData.w[1]; percCtx.strokeStyle='white'; percCtx.lineWidth=3; percCtx.shadowColor='cyan'; percCtx.shadowBlur=30;
       percCtx.beginPath(); percCtx.moveTo(-1, (-percData.w[0]*-1 + percData.w[1]*-1* slope? Wait standard line.
       // Line: from left to right at angle atan2(wy,wx)
       const angle = Math.atan2(percData.w[1], percData.w[0]); percCtx.rotate(angle); // Pivot center.
       percCtx.beginPath(); percCtx.moveTo(-percCanvas.width*0.75,0); percCtx.lineTo(percCanvas.width*0.75,0); percCtx.stroke();
       percCtx.restore();
     }
     function trainEpoch() {
       let correct=0; // SGD mini-batch all points lr=0.1
       points.forEach(p => {
         const z = percData.w[0]*p.x + percData.w[1]*p.y + percData.b;
         const pred = z>0 ?1:0;
         if(pred === p.label) correct++;
         const error = p.label - pred;
         percData.w[0] += 0.1 * error * p.x; percData.w[1] += 0.1 * error * p.y; percData.b += 0.1 * error;
       });
       percData.epochs++; percData.acc = Math.min(100, (correct/points.length)*100);
       status.textContent = `Accuracy: ${percData.acc.toFixed(0)}% | Epochs: ${percData.epochs}`;
       drawPerc(); // Glow scales with acc? ctx.shadowBlur = 10 + percData.acc/5;
     }
     trainBtn.addEventListener('click', trainEpoch);
     percCanvas.addEventListener('resize', drawPerc); drawPerc(); // Init horiz line acc0%

     // Fractal Julia: escape time, c = mouse real-time throttle.
     const fracCanvas = document.getElementById('fractal-canvas');
     const fracCtx = fracCanvas.getContext('2d');
     let mouseC = {re: -0.8, im: 0.156}; // Init Mandelbrot-like spiral
     let mouseThrottle = 0; let rafId;
     fracCanvas.addEventListener('mousemove', (e) => {
       const rect = fracCanvas.getBoundingClientRect();
       mouseC.re = -1.2 + 1.4*(e.clientX-rect.left)/rect.width;
       mouseC.im = 0.8*(e.clientY-rect.top)/rect.height - 0.4;
       mouseThrottle = 16; // Throttle RAF
     });
     function drawFractal() {
       fracCtx.clearRect(0,0,fracCanvas.width,fracCanvas.height);
       const maxIter=100; const zoom=1.5; const cx=fracCanvas.width/2, cy=fracCanvas.height/2;
       for(let px=0; px<fracCanvas.width; px+=2) for(let py=0; py<fracCanvas.height; py+=2) { // Downsample perf
         let zre= (px-cx)/fracCanvas.width *3/zoom, zim=(py-cy)/fracCanvas.height *3/zoom;
         let iter=0;
         while(zre*zre + zim*zim <4 && iter<maxIter) {
           let zi=zim; zim = 2*zre*zim + mouseC.im; zre = zre*zre - zi*zi + mouseC.re; iter++;
         }
         const hue = (iter/maxIter)*360 + 240; // Purple-teal
         const alpha = iter/maxIter *0.8;
         fracCtx.fillStyle=`hsla(${hue},100%,50%,${alpha})`;
         fracCtx.shadowColor=`hsl(${hue},100%,50%)`; fracCtx.shadowBlur=10;
         fracCtx.fillRect(px,py,3,3);
       }
       rafId = requestAnimationFrame(drawFractal);
     }
     drawFractal(); // Loop RAF, throttle via mouse only? No, always but throttle inner.
     // Cleanup raf on unload.
   }
   ```
   - Perceptron: Starts acc~0%, horiz line; 3-5 Trains → acc>80%, line rotates ~45deg CCW (weights adapt), points glow.
   - Fractal: Static black init; mouse right-center → purple spirals at c~-1.2+0.8i, realtime morph 60fps neon.
   - Resize handlers for canvases DPR/high-DPI.
   - In DOMContentLoaded: `if (document.querySelector('#perceptron-canvas')) initExperiments();`

**Verification/Screenshots (MANDATORY – DEVIATION=REJECT per #22/#31/#60):**
- **ONLY FULL experiments.html screenshots**: Desktop full-scroll (hero+perceptron+fractal), Mobile full-scroll (70vh hero stacks, canvases centered no h-scroll).
- **JS Proofs in CODER NOTES** (multi-state screenshots essential per #68):
  1. Particles falling over hero (2s RAF).
  2. Nav 'Experiments' cyan glow/underline active (static ok + confirm JS).
  3. Perceptron: Initial (acc 0%, horiz white line center, cyan/red points scattered no glow); After 3x Train clicks (screenshots each? or final: acc e.g.85%, line rotated ~45deg CCW, cyan/red glow brighter, line cyan glow).
  4. Fractal: Initial center black; Mouse to right-edge mid (purple spirals morph visible, e.g. c=-1.2+0.8i update).
- URL/path/nav: experiments.html active.
- **NO index/worlds/stories screenshots**. List "pages changed: experiments.html, css/style.css, js/main.js, images/experiments-hero.jpg".
- **Revert ANY index.html touches fully** (git checkout -- index.html if changed).
- Responsive: No overlaps/cutoffs/h-scroll; text readable; neon coherent.

**Expected Outcome:** Experiments pillar LIVE (high-replay JS core value). Site now 4 polished pages worth bookmarking/returning.

MEMORY_WRITE: [
  {"type": "decision", "content": "Cycle 9: FULL experiments.html pillar implemented (hero+experiments-hero.jpg+perceptron trainer/fractal Julia JS interactives mirroring #7/#21/#28/#50 structure/JS success). Experiments COMPLETE per #2. ONLY experiments.html—no other touches/screenshots.", "relates_to": 59},
  {"type": "decision", "content": "Screenshot/JS rule #22/#31/#60 ENFORCED: 'FULL experiments.html ONLY desktop/mobile scrolls + JS notes/proofs (particles/nav active/perceptron train→rotate/acc%/glow/fractal mouse→morph)' + 'URL/path/nav Experiments active' + 'NOT index/worlds/stories' + 'Revert index fully'.", "relates_to": 60},
  {"type": "observation", "content": "Experiments deliver top replay value (train/morph loops) in neon theme; completes content pillars for visitor retention.", "relates_to": 61},
  {"type": "plan", "content": "Cycle 10: Site-wide polish per #62 (PWA manifest/service-worker; share btns; hero text/CTA tweaks per #55). Add 1-2 new worlds/stories if budget.", "relates_to": 62}
]

Collaboration

Coder (round 1)

{"ready": true}

Before & After

Before
Before
After
After

Review Iterations

Iteration 1 Needs Revision

Fully implemented experiments.html as complete pillar with hero (new image+particles), perceptron trainer (click-train rotates line upper-left/right cyan/red separation, acc glows), Julia fractal (mouse morphs c param neon spirals). Appended precise CSS for .experiment-* classes reusing cyberpunk theme. Extended main.js with initExperiments() (resize/RAF/perf/downsample) called conditionally. Matches plan exactly for high-replay JS visions.

Rejected iteration 0
Iteration 2 Parse Error
Iteration 3 Approved

Completed Experiments pillar precisely per plan: full experiments.html with hero (new image gen), perceptron interactive (train epochs rotate line, acc glows), Julia fractal (mouse morphs c realtime). Appended exact CSS experiment styles. Full JS initExperiments() with resize/perf/RAF/cleanup. Responsive, neon-themed, high-replay. No other files touched.