main.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from settings import *
  2. from random import randint
  3. from cell_generator import cell_checker
  4. from copy import deepcopy
  5. import pygame
  6. pygame.init()
  7. screen = pygame.display.set_mode(resolution)
  8. clock = pygame.time.Clock()
  9. current_field = [[randint(0,1) for i in range(cells_width_count)] for i2 in range(cells_heigth_count)]
  10. new_field = [[0 for i in range(cells_width_count)] for i2 in range(cells_heigth_count)]
  11. while True:
  12. screen.fill("black")
  13. for event in pygame.event.get():
  14. if event.type == pygame.QUIT:
  15. exit()
  16. for x in range(0, width, cell_size):
  17. pygame.draw.line(screen, cell_border_color, (x,0), (x, height))
  18. for y in range(0, height, cell_size):
  19. pygame.draw.line(screen, cell_border_color, (0,y), (width, y))
  20. for x in range(1, cells_width_count - 1):
  21. for y in range(1, cells_heigth_count - 1):
  22. if current_field[y][x]:
  23. pygame.draw.rect(screen, cell_color, (x * cell_size + 2, y * cell_size + 2, cell_size - 2, cell_size - 2))
  24. new_field[y][x] = cell_checker(current_field, x, y)
  25. current_field = deepcopy(new_field)
  26. print(f'FPS: {int(clock.get_fps())}')
  27. clock.tick(FPS_lock)
  28. pygame.display.flip()