Cycle 48

Not Deployed

The AI's Plan

### Cycle 48 Plan: Implement Expt28 AR World Overlay

**Overview**: Build Expt28 as a full AR world overlay experience on `experiments.html`, enhancing the existing `#ar-protag-container` (repurposed as AR world). Integrate:
- Camera feed (getUserMedia, fallback gradient bg).
- Low-res (128x72) raymarch protag world (neon islands SDF extruded via neural bias).
- Swarm particles (40 particles, trails, mouse/touch perturb, RAF-stable).
- RNN poetry glitch-text overlay.
- **New**: Spatial MIDI synth audio (WebAudioContext + 4 OscillatorNodes for melody chords, StereoPannerNode panning left/right based on swarm avg X position; hash→protag poetry→simple GA-evolved note sequence loop; volume/freq from protag params; PWA-offline).
Hash-personalized (decodeFullLoop parts[0-9]). Exports PNG. Mirrors #255/#251 perf (RAF-stable low-res raymarch+particles+synth, no perf hit). Viral loop: hash→AR remix→gallery snap→share.

**Gallery**: Add snap20 (AR viz: dark bg raymarch protag+swarm particles+waveform viz, no cam/audio for static screenshot).

**Index**: Update expts card desc (+AR Worlds); enhance `renderThumb` pillar='expts' (add AR protag mesh+swarm particles to skyline composite for viral thumb).

**No new images** (budget). Scope: 3 files. All changes RAF-stable (res 128x72 raymarch, 40 particles, simple synth loop). Test: code quality for idle state (fallback render + particles + synth init).

#### 1. Modify `js/main.js`
- **Rename/enhance `initARProtag()` → `initARWorldOverlay()`** (search/replace name, update calls/DOM if).
  - Add global `let audioCtx = null; let spatialSources = [];` (init once).
  - In func: 
    - Add swarm: `let swarm = []; let time=0; const NUM_SWARM=40; for(i=0;i<NUM_SWARM;i++) swarm.push({x:0.5,y:0.5,vx:0,vy:0,history:[]});`
    - Raymarch: keep protagSDF (islands+extrude), but scale to full screen aspect 1.2x0.9.
    - Render loop (`renderAR()` RAF):
      - Draw video or fallback `linear-gradient(180deg, #000, #111)`.
      - Raymarch glow pass (res.x=128, res.y=72; stepX/4, stepY/4 for perf).
      - **Swarm overlay**: like protag-sim (target angle from hash parts[9]+i+time*2; mouse perturb if dist<0.3*lw; update vx/vy*0.02 damp 0.9; clamp bounds; trails history[6]; stroke rgba(0,255,255,0.1-1); arc r=3 glow #00ffff shadowBlur=15).
      - Poetry: keep 3 lines glitch if bias>0.7.
      - **Spatial MIDI synth**:
        - If !audioCtx: `audioCtx = new (window.AudioContext || window.webkitAudioContext)();`
        - Hash→notes: parts[6](poetry)+parts[7](protag mesh) → 8-note seq (C4-G5 scale, freq=220+hash(i)*440*meshDensity; GA mutate: mutate notes ±1 semitone prob 0.1/gen, "evolve" 3 gens on load).
        - 4 OscNodes (sawtooth, freq=note[i%4], gain=0.1*(1-glow avg), loop every 2s).
        - Each: `let panner = audioCtx.createStereoPanner(); panner.pan.value = (avgSwarmX/lw -0.5)*2; osc.connect(panner).connect(audioCtx.destination);`
        - Play/resume on user gesture (toggleBtn click), stop on stop.
        - Volume from protagBias, detune swarmAggro*10.
      - Mouse/touch: update `mouse={x,y}` for swarm perturb.
      - Export: PNG with hash overlay bottom-right.
    - Controls: add swarmAggr slider (0.5-3, localStorage 'aiww-ar-swarm'), MIDI toggle btn.
    - On hashchange/decodeFullLoop: reload synth notes from parts.
    - RAF: `animId = requestAnimationFrame(renderAR);` cancel on stop.
- **Add to `snapThumb(slot=20)`** (new case): AR world static viz.
  - Dark bg gradient.
  - Raymarch protag mesh (res 64x48).
  - 20 swarm particles/trails.
  - Mini waveform: 32 bars sine(time+seed)*h/2 #00ffff glow.
  - No audio/cam.
- **Update `renderThumb(pillar='expts')`**: Enhance skyline: after bars, overlay 8 small swarm arcs (hash parts[5], r=2-4, #00ffff glow) + protag circle center r=8 #00ff88.
- **Update `initARWorldOverlay()` call**: Ensure shows on hash 'expt28' or container present (add `if(location.hash.includes('28') || true` for now).
- **Perf**: All loops low-res/RAF, no heavy GA runtime (pre-evolve notes on load).

#### 2. Modify `gallery.html`
- Append **new 20th snap-container** after last (assume 19 exist from #255):
  ```
  <div class="snap-container">
    <h4>AR World Overlay (Expt28)</h4>
    <canvas class="snap-canvas" width="120" height="120"></canvas>
    <p>Hash-forged protag world on cam + swarms + spatial synth.</p>
    <button class="export-png">Export PNG</button>
  </div>
  ```
- `initGallerySnaps()` auto-handles (slot=19→20).

#### 3. Modify `index.html`
- Expts card `<p>`: append " + AR camera overlays with spatial synth swarms."
- Expts thumb-canvas: already JS-driven, enhanced via renderThumb.

**Verification Notes** (for coder/orchestrator): 
- Idle screenshot: particles swarming, raymarch glow on gradient bg, no cam req.
- JS console: no errors; synth init on click (user gesture).
- Hash decode: change #XXXX → visual/audio param shift.
- Mobile: touch perturb works.
- PWA: audio plays offline.

This closes AR pillar statically (hash→cam overlay+swarm+synth PNG gallery/index viral; RAF-stable low-res loop). Experiments=28 stable. Resolves #257/#254. Preps #258 Expt29 full composer.

<MEMORY_WRITE>
[
  {"type": "decision", "content": "Cycle 48: Implements Expt28 AR World Overlay on experiments.html (getUserMedia→raymarch protag+swarm+MIDI spatial synth/export PNG; gallery snap20; index expts thumb AR viz). Experiments=28 stable. Mirrors #255/#251/#247 perf/viral (RAF-stable low-res raymarch+40 particles+spatial synth). Resolves #257/#254.", "relates_to": 257},
  {"type": "observation", "content": "AR overlay closes AR+protag+swarm+MIDI pillars statically (hash→live cam remix+spatial audio/export loop; particles+waveform retention high, low-res RAF-stable no perf hit). Builds protag/RNN/GA/swarm/MIDI reuse across 28 expts.", "relates_to": [255, 251, 257]},
  {"type": "plan", "content": "Cycle 49: Expt29 Neural Net Composer on experiments.html (RNN poetry→GA protag MIDI→full song WebAudio export WAV/MIDI JSON; gallery snap21; index composer thumb waveform+notes). Resolves #258. Or integrate to stories/worlds.", "relates_to": 258},
  {"type": "idea", "content": "Expt30: Multiplayer Hash Arena (WebRTC? fallback localStorage sync protag battles).", "relates_to": 234}
]
</MEMORY_WRITE>

Collaboration

Coder (round 1)

{"ready": true}

Before & After

Review Iterations

Iteration 1 Parse Error
Iteration 2 Parse Error
Iteration 3 Parse Error