Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2018 17:22
Show Gist options
  • Save anonymous/b1400bbe5c82459b6984c0f1dd7cd30c to your computer and use it in GitHub Desktop.
Save anonymous/b1400bbe5c82459b6984c0f1dd7cd30c to your computer and use it in GitHub Desktop.
import drawille, strutils, random, terminal
let
width = terminalWidth() * 2
height = terminalHeight() * 4
var
c1 = newCanvas(width div 2, height div 4)
c2 = newCanvas(width div 2, height div 4)
for x in 0 .. <(width*height div 10):
c1.set(random(width-1), random(height-1))
while true:
stdout.write(c1); stdout.flushFile()
for x in 1 ..< width-1:
for y in 1 ..< height-1:
var alive = if c1.get(x, y): -1 else: 0
for nx in (x - 1) .. (x + 1):
for ny in (y - 1) .. (y + 1):
if c1.get(nx + width, ny + height):
inc alive
if alive == 3 or (alive == 2 and c1.get(x, y)): c2.set(x, y)
else: c2.unset(x, y)
swap(c1, c2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment