Skip to content

Commit 51fa531

Browse files
random updates
1 parent b783f54 commit 51fa531

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

main.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import pygame
2+
import time
3+
import random
4+
from datetime import datetime
25

36
white = (255, 255, 255)
47
black = (0, 0, 0)
58
(width, height) = (300, 300) # Dimension of the window
69
screen = pygame.display.set_mode((width, height)) # Making of the screen
710

811
gridSize = 10
9-
12+
updateTime = 0.5
13+
1014
def drawGrid():
1115
for y in range(1, gridSize):
1216
pygame.draw.line(screen, white, (0, (height / gridSize) * y), (width, (height / gridSize) * y), 1)
@@ -33,7 +37,10 @@ def fillCell(x, y):
3337
[0,0,0,0,0,0,0,0,1,1]
3438
]
3539
running = True
40+
41+
prev = datetime.now()
3642
while running:
43+
time = datetime.now()
3744
screen.fill(black)
3845

3946
drawGrid()
@@ -42,8 +49,17 @@ def fillCell(x, y):
4249
for x in range(len(board[y])):
4350
if board[y][x] == 1:
4451
fillCell(x, y)
52+
53+
if (time - prev).total_seconds() > updateTime and random.randint(1,10) == 5: # just to add some changes
54+
x = random.randint(0,gridSize-1);
55+
y = random.randint(0,gridSize-1);
4556

57+
board[y][x] = 0 if board[y][x] else 1
58+
prev = time
59+
4660
pygame.display.flip()
61+
#time.sleep(1)
62+
4763
for event in pygame.event.get():
4864
if event.type == pygame.QUIT:
4965
running = False

0 commit comments

Comments
 (0)