# evaluate conway's game of life on a canvas
# structured so that step[] and randomize[] can be used
# directly within a decker script.

on randomize do
	r:image[board.size]
	r.pixels:random[(0,0,1) prod r.size]
	board.paste[r]
end

on step do
	new:board.copy[]
	deltas:(3 cross 3)-1
	each pos in board.size[0] cross board.size[1]
		around:sum each delta in deltas board[pos+delta] end
		new[pos]:if board[pos] around in 3,4 else around~3 end
	end
	board.paste[new]
end

deck:readdeck[]
board:deck.card.add["canvas"]
board.size:80,40
randomize[]
steps:20
while steps step[] steps:steps-1 end

each y in range board.size[1]
	print[each x in range board.size[0] ".O"[board[x,y]] end]
end
show[sys.workspace]
