Skip to content

Instantly share code, notes, and snippets.

@jpignata
Created June 11, 2020 12:26
Show Gist options
  • Save jpignata/5f6842a006a65934648832a02c49e6e8 to your computer and use it in GitHub Desktop.
Save jpignata/5f6842a006a65934648832a02c49e6e8 to your computer and use it in GitHub Desktop.
import os
import sys
import time
RULES = {'111': '0', '010': '0', '101': '0', '000': '0',
'100': '1', '011': '1', '110': '1', '001': '1'}
def draw(state):
def window(state, length=3):
for i in range(1, len(state) - length + 2):
yield state[i-1:i+length-1]
while True:
for s in state:
if s == '1':
sys.stdout.write('#')
else:
sys.stdout.write(' ')
print()
time.sleep(0.033)
state = ''.join(RULES[triplet] for triplet in window(state))
state = f'0{state}0'
if __name__ == '__main__':
_, columns = os.popen('stty size', 'r').read().split()
half = int(columns) // 2
state = '0' * half + '1' + '0' * half
draw(state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment