Skip to content

Instantly share code, notes, and snippets.

@alexdelorenzo
Last active December 24, 2015 07:59
Show Gist options
  • Save alexdelorenzo/6767628 to your computer and use it in GitHub Desktop.
Save alexdelorenzo/6767628 to your computer and use it in GitHub Desktop.
from gol import Universe as U
from random import randint as r
import pygame
from pygame.gfxdraw import pixel as p
from pygame.gfxdraw import rectangle as rect
from pygame import Surface as S
# just shoved everything in this script into main(), hence the subfuncs
def main():
x, y = 100, 100
rect_size = 1
scale = 4
u = U(x, y)
u.fill_random(.4)
white, black = (255, 255, 255), (0, 0, 0)
def conway_frames():
while True:
u.tick()
yield u._live_points(), u._dead_points()
def process_living(living):
for live in living:
if u.val(live):
x1, y1 = live
rect(screen, (x1 * scale, y1 * scale, rect_size, rect_size), white)
#p(screen, x1, y1, white)
def process_dead(dead):
for died in dead:
if not u.val(died):
x1, y1 = died
rect(screen, (x1 * scale, y1 * scale, rect_size, rect_size), black)
#p(screen, x1, y1, black)
pygame.init()
x *= scale
y *= scale
rect_size *= scale
screen = pygame.display.set_mode((x,y))
for living, dead in conway_frames():
process_dead(dead)
process_living(living)
pygame.display.flip()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment