{deck}
version:1
card:0
size:[512,342]
name:"The Game of Life"
author:"John Earnest"

{card:home}
image:"%%[encoded data, 6308 characters]"
script:"home.0"
{widgets}
field1:{"type":"field","size":[164,20],"pos":[147,44],"locked":1,"font":"menu","show":"invert","border":0,"align":"center","value":"Conway's Game of Life"}
board:{"type":"canvas","size":[204,195],"pos":[126,106],"script":"home.1","show":"invert","image":"%%IMG0ABoAGWBSCAAATGDABgAFQIcAAAAYgAAAIjY4gIh/AADCfyeACD4wQCIcN0CiCChAEIEhAKyBCYCQYIGAMACcwKAAUIAsdYEATBQpgAoWLQCkQDAApQ+/AMEREYDgKBKAgIAbACZgAEA=","pattern":0,"scale":8}
button1:{"type":"button","size":[87,24],"pos":[381,119],"script":"home.2","text":"Clear"}
button2:{"type":"button","size":[87,24],"pos":[381,150],"script":"home.3","text":"Randomize"}
button3:{"type":"button","size":[87,24],"pos":[381,203],"script":"home.4","text":"1"}
field2:{"type":"field","size":[44,14],"pos":[401,184],"locked":1,"border":0,"align":"center","value":"step"}
button4:{"type":"button","size":[87,24],"pos":[381,235],"script":"home.4","text":"10"}
button5:{"type":"button","size":[87,24],"pos":[381,267],"script":"home.4","text":"100"}

{script:home.0}
on step do
 counts:image[board.size]
 each delta in (3 cross 3)-1
  counts.merge["+" board.copy[].translate[delta]]
 end
 stay:counts.copy[].map[((3,4) dict 1,1) 0].merge["&" board.copy[]]
 born:counts       .map[(3     dict 1  ) 0]
 board.paste[born.merge["|" stay]]
 sleep[5]
end

on steps x do
 step @ range floor x
end
{end}

{script:home.1}
on click pos do
 me.pattern:!me[pos] 
end

on release pos do
 drag[pos]
end
{end}

{script:home.2}
on click do
 board.clear[]
end
{end}

{script:home.3}
on click do
 b:image[board.lsize]
 b.pixels:random[(0,0,1) prod board.lsize]
 board.paste[b]
end
{end}

{script:home.4}
on click do
 steps[me.text]
end
{end}

