# pygame像素级生命游戏模拟game of life animation

### pygame像素级生命游戏模拟game of life animation

```"""pygame像素级生命游戏模拟.py
Conway's Game of Life），又称康威生命棋，是英国数学家约翰·何顿·康威在1970年发明的细胞自动机。

"""
import pygame
from pygame.locals import *
from random import randint

pygame.init()
life_color = (222,211,0,255)          # 有颜色的代表活的,黑色代表死的
width,height = 200,200
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("生命游戏模拟_风火轮编程李兴球")

lives = {}
life_image = pygame.Surface((width,height))

# 初始化状态
for  x in range(width):
for y in range(height):
if randint(1,10) == 1:
lives[(x,y)] = 1
else:
lives[(x,y)]=0

def get_numbers(pos):
"""得到周围活的数量"""
pass

running = True
while running:
for cell in lives:
pygame.event.poll()
f = lives[cell]            # 生命状态     cell 就是x,y
cell_number = get_numbers(cell)   # 得到周围活的细胞数量

pass

screen.fill((0,0,0))
life_image.fill((0,0,0))
[life_image.set_at(cell,life_color) for cell in lives if lives[cell] ]

screen.blit(life_image,(0,0))  # 把life_image渲染到screen上.
pygame.display.update()        # 更新屏幕显示

"""
1、规则

---------------------
"""

pygame.image.save(life_image,"te.png")

```

(会员专属：能浏览所有文章，下载所有带链接的Python资源。)