diff --git a/life.py b/life.py index 05329d0..55fdeee 100755 --- a/life.py +++ b/life.py @@ -71,7 +71,7 @@ def show_state(): print s -fixed_cmd_cnt = 1000 +fixed_cmd_cnt = 10000 for i in range(generations): @@ -83,11 +83,12 @@ def show_state(): print cmd sys.stdout.flush() - #busy loop - for b in range(cnt): - print "#", i, ": busy ", (fixed_cmd_cnt - b) - update_cells() + time.sleep(.76) + + # #busy loop + # for b in range(cnt): + # print "#", i, ": busy ", (fixed_cmd_cnt - b) diff --git a/rand.py b/rand.py index 845f729..a3b5907 100755 --- a/rand.py +++ b/rand.py @@ -6,7 +6,7 @@ H = 20 -for i in range(1000): +for i in range(100000): x = random.randint(0, W-1); y = random.randint(0, H-1); cmd = "{} {}".format(x,y) diff --git a/sss.py b/sss.py index a8fd194..cb44f0a 100755 --- a/sss.py +++ b/sss.py @@ -5,6 +5,8 @@ import sys, random, time import math +import threading + W = 120 H = 20 @@ -13,37 +15,21 @@ #COLORS black = [0,0,0] -red = [255,0,0] -green = [0,255,0] -blue = [0,0,255] white = [255,255,255] -yellow = [255,165, 0] -purple = [102, 0, 172] -grey = [120,120,120] - - -# pygame.mixer.pre_init(44100, -16, 2, 2048) # setup mixer to avoid sound lag -# #modified from http://www.freesound.org/people/Koops/sounds/20258/ -# flip_snd = pygame.mixer.Sound("flip.ogg") -# pygame.mixer.set_num_channels(W*H) -# print "ther are ", pygame.mixer.get_num_channels() screen = pygame.display.set_mode((W*cell_size,H*cell_size), pygame.NOFRAME) clock = pygame.time.Clock() screenCenter = screen.get_rect().center +changes = pygame.Surface((W*cell_size,H*cell_size)) def idx(x,y): return W*y + x -def draw_cell(screen, x,y): - +def draw_cell(surface, x,y): r = pygame.Rect((x * cell_size, y*cell_size), (cell_size, cell_size)) - pygame.draw.rect(screen, black, r) + pygame.draw.rect(surface, black, r) width = 0 if cells[idx(x,y)] else 1 - pygame.draw.circle(screen, white, r.center, (cell_size / 2) - 1, width) - # chn = pygame.mixer.find_channel() - # if chn: - # chn.play(flip_snd) + pygame.draw.circle(surface, white, r.center, (cell_size / 2) - 1, width) #init @@ -54,21 +40,33 @@ def draw_cell(screen, x,y): cells.append(False) draw_cell(screen, x, y) +def read_cmds(): + for line in sys.stdin: + # print line + if line.startswith("#"): + continue + coords = line.split() + x = int(coords[0]) + y = int(coords[1]) + cells[idx(x,y)] = not cells[idx(x,y)] + draw_cell(screen, x,y) + time.sleep(.00005); # the flip time aproximation +t = threading.Thread(target=read_cmds) +t.start() + + +done = False +while not done: + clock.tick_busy_loop(1500); + pygame.event.pump() + for event in pygame.event.get(): + if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + done = True -for line in sys.stdin: - clock.tick_busy_loop(1000) -# print line - if line.startswith("#"): - continue - coords = line.split() - x = int(coords[0]) - y = int(coords[1]) - cells[idx(x,y)] = not cells[idx(x,y)] - draw_cell(screen, x,y) pygame.display.update() pygame.display.flip() + -while (pygame.event.wait().type != pygame.KEYDOWN): pass pygame.quit()