class OneHundredRuns(unittest.TestCase): def runTest(self): self.w=World(size_x=100, size_y=100) self.w.randomize() for i in range(2): for j in range(10): self.w.update()
from pyglet import font from pyglet import window from conway import World, add_pattern win = window.Window() w=World(size_x=60, size_y=45) w.randomize() glider="1,1 2,1 3,1 2,3 3,2" blinker="1,1 1,2 1,3" add_pattern(w, glider, (5,35)) ft = font.load('Arial', 20) #run until the user hits exit while not win.has_exit: win.dispatch_events() win.clear() w.update() rows=0 cols=0 # for each position in the world: for pos in w.scope(): cell=w.get(pos) # if the cell is alive? if cell: # put an * on the screen, spaced 10 from the left, with 10 pixels between them. text=font.Text(ft, [" ", "*"][cell], x=10+pos[0]*10, y=pos[1]*10) text.draw()
import curses from conway import World, add_pattern stdscr = curses.initscr() curses.noecho() curses.cbreak() stdscr.keypad(1) x,y=stdscr.getmaxyx() stdscr.addstr(10,10, "python simple conways game of life") stdscr.addstr(12,10, "x: %s, y: %s" % (x,y)) stdscr.addstr(14,10, "Space to update, r to randomize, q to quit.") #w=World(size_x=x, size_y=y) w=World(size_x=x-1, size_y=y-1) # wait for a keypress then go for it. c=stdscr.getch() stdscr.erase() stdscr.nodelay(True) w.randomize() while 1: stdscr.refresh() w.update() c = stdscr.getch() if c == ord('q'): break # Exit the while() elif c == ord('r'): w.randomize() for pos in w.scope(): cell=w.get(pos) try:
def runTest(self): w=World(size_x=10, size_y=10) add_pattern(w, glider, (5,5)) assert list(w.world.values())==[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] w.update() assert list(w.world.values())==[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
def runTest(self): self.w=World(size_x=100, size_y=100) self.w.randomize() for i in range(2): for j in range(10): self.w.update()
from pyglet import font from pyglet import window from conway import World, add_pattern win = window.Window() w = World(size_x=60, size_y=45) w.randomize() glider = "1,1 2,1 3,1 2,3 3,2" blinker = "1,1 1,2 1,3" add_pattern(w, glider, (5, 35)) ft = font.load('Arial', 20) #run until the user hits exit while not win.has_exit: win.dispatch_events() win.clear() w.update() rows = 0 cols = 0 # for each position in the world: for pos in w.scope(): cell = w.get(pos) # if the cell is alive? if cell: # put an * on the screen, spaced 10 from the left, with 10 pixels between them. text = font.Text(ft, [" ", "*"][cell], x=10 + pos[0] * 10, y=pos[1] * 10)