# -*- coding: utf-8 -*- # ========================================================== # HOW TO USE EXAMPLE 1 # ========================================================== import os, sys # for execute from examples directory without package instalation sys.path.append(os.path.abspath(os.pardir)) from gol.gameoflife import gol, IncorrectArg gol_settings = { # 'preset': 'flasher', "first_generation": set([(0, 0), (1, 0), (2, 0), (0, 1), (1, 2)]), "board_size": (100, 100), "out_format": "set", "max_generation": 150, } try: life = gol(**gol_settings) except IncorrectArg as err: print (err) for i in life: print i
from gol.gameoflife import gol, IncorrectArg def cur(screen, life): curses.init_pair(1, 4, curses.COLOR_CYAN) curses.resize_term(life.max_y + 1, life.max_x * 2 + 1) curses.curs_set(0) screen.addstr(1,1,"*************************************", curses.color_pair(1)) screen.addstr(2,1,"* use Ctrl+C for ending the game *", curses.color_pair(1)) screen.addstr(3,1,"* press any key to start *", curses.color_pair(1)) screen.addstr(4,1,"*************************************", curses.color_pair(1)) screen.getch() for bord in life: screen.clear() screen.border(0) screen.timeout(500) for cell in bord: x = cell[0] * 2 y = life.max_y - cell[1] screen.addstr(y,x," ", curses.color_pair(1)) screen.refresh() screen.getch() if __name__ == '__main__': try: life = gol(preset = 'glider') except IncorrectArg as err: print(err) sys.exit() curses.wrapper(cur, life)