Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from random import randint
- from copy import deepcopy
- #Переменные
- RES = WIDTH, HEIGHT = 1500, 900
- TILE = 10
- W, H = WIDTH // TILE, HEIGHT // TILE
- FPS = 20
- #Создание окна и его разрешения.
- pygame.init()
- surface = pygame.display.set_mode(RES)
- clock = pygame.time.Clock()
- #настройка поля
- next_field = [[0 for i in range(W)] for j in range(H)]
- current_field = [[1 if not i % 7 else randint(0, 1) for i in range(W)] for j in range(H)]
- #проверка клеток
- def check_cell(current_field, x, y):
- count = 0
- for j in range(y - 1, y + 2):
- for i in range(x - 1, x + 2):
- if current_field[j][i]:
- count += 1
- if current_field[y][x]:
- count -= 1
- if count == 2 or count == 3:
- return 1
- return 0
- else:
- if count == 3:
- return 1
- return 0
- #ограничение фпс
- print(clock.get_fps())
- pygame.display.flip()
- clock.tick(FPS)
- #цвета поля
- while True:
- surface.fill(pygame.Color('gray'))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- exit()
- if event.type == pygame.key.get_pressed(KMOD_SPACE)
- if event.mod == pygame.KMOD_NONE:
- clock.tick(FPS)
- else:
- if event.mod & pygame.KMOD_SPACE:
- clock.tick(1)
- #цвета поля
- [pygame.draw.line(surface, pygame.Color('black'), (x, 0), (x, HEIGHT)) for x in range(0, WIDTH, TILE)]
- [pygame.draw.line(surface, pygame.Color('black'), (0, y), (WIDTH, y)) for y in range(0, HEIGHT, TILE)]
- #прорисовка линий
- for x in range(1, W - 1):
- for y in range(1, H - 1):
- if current_field[y][x]:
- pygame.draw.rect(surface, pygame.Color('black'), (x * TILE + 2, y * TILE + 2, TILE - 2, TILE - 2))
- next_field[y][x] = check_cell(current_field, x, y)
- current_field = deepcopy(next_field)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement