abg

Animated background for X11
git clone git://git.laack.co/abg.git
Log | Files | Refs | README

commit 6638cf1338e3897ad8a076bf0208f729fea4a1dd
parent d566dc0cb8918f2b63149db15c56e4b112bd6598
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 25 Aug 2026 22:19:32 -0500

Pygame grid visualization

Diffstat:
Agrid/random-grid.py | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+), 0 deletions(-)

diff --git a/grid/random-grid.py b/grid/random-grid.py @@ -0,0 +1,63 @@ +import pygame, sys +import random +from pygame.locals import * + +pygame.init() + +RED = (255,0,0) +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) + +Y=5 +X=5 + +WIDTH = 500 +HEIGHT = 500 + +DISPLAY = pygame.display.set_mode((WIDTH, HEIGHT)) +pygame.display.set_caption('Hello World!') + + + +grid = [ + [0,0,0,0,0], + [0,1,1,0,0], + [0,1,1,0,0], + [0,0,0,1,0], + [1,0,0,0,0] +] + +def simulate(prior): + neighbors = prior.copy() + + for y in range(len(prior)): + for x in range(len(prior[y])): + neighbors[y][x] = random.randint(0,2) + + return neighbors + + +def drawGrid(): + blockSize = int(WIDTH / len(grid)) + for x in range(0, WIDTH, blockSize): + for y in range(0, HEIGHT, blockSize): + if grid[int(x / blockSize)][int(y / blockSize)] == 1: + rect = pygame.Rect(x, y, blockSize, blockSize) + pygame.draw.rect(DISPLAY, WHITE, rect) + else: + rect = pygame.Rect(x, y, blockSize, blockSize) + pygame.draw.rect(DISPLAY, WHITE, rect, 1) + + + +while True: + for event in pygame.event.get(): + if event.type == QUIT: + pygame.quit() + sys.exit() + + grid = simulate(grid) + DISPLAY.fill(BLACK) + drawGrid() + pygame.display.update() +