def main(): print("Shake Pi to Restart Life Cycle") print(" or ctrl-c to Quit") #sense.show_message("Shake Restarts") life_cycles = 1 while (True): gl_color = (randint(1, 255), randint(1, 255), randint(1, 255)) msg = str(life_cycles) sense.show_message(msg) game = GameOfLife(8, 8, gl_color) for i in game: sleep(0.5) game.update() if detect_shake(accel_thresh): life_cycles += 1 break c = enterMod.getKey() if c == 1: sense.clear(0, 0, 0) sys.exit()
r -= 1 if (g == 255 and b < 255 and r == 0): b += 1 if (b == 255 and g > 0 and r == 0): g -= 1 if (b == 255 and r < 255 and g == 0): r += 1 if (r == 255 and b > 0 and g == 0): b -= 1 pix[0] = r pix[1] = g pix[2] = b sense.low_light = True while (True): for pix in pixels: next_colour(pix) sense.set_pixels(pixels) #msleep(2) c = enterMod.getKey() if c == 1: sense.clear([0, 0, 0]) sys.exit()
else: new_board[i * height + j] = min(7, lvl + 1) else: if neigh == 3: new_board[i * height + j] = 0 else: new_board[i * height + j] = min(7, lvl + 1) self.board = new_board def all_dead(self): for i in xrange(size): if self.board[i] != 7: return False return True def show_board(self): for i in xrange(width): for j in xrange(height): rgb = self.color[self.value(i, j)] sense.set_pixel(i, j, rgb[0], rgb[1], rgb[2]) life = GameOfLife() while not life.all_dead(): life.next_generation() life.show_board() time.sleep(0.35) if enterMod.getKey() == 1: sense.clear() sys.exit()