Skip to content

Instantly share code, notes, and snippets.

@jscott1989
Created March 16, 2015 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jscott1989/cc874906c0a839473a7d to your computer and use it in GitHub Desktop.
Save jscott1989/cc874906c0a839473a7d to your computer and use it in GitHub Desktop.
Group 2 Maze visualiser
import time
import pygame
import numpy as np
black = (0, 0, 0)
white = (255, 255, 255)
screen_size=(640,640)
offset = (10,10)
def draw_horizontal(window, coords, length):
"""Draw vertical maze wall to the screen"""
end = list(coords)
end[0] += length
pygame.draw.line(window, black, coords, end)
def draw_vertical(window, coords, length):
"""Draw vertical maze wall to the screen"""
end = list(coords)
end[1] += length
pygame.draw.line(window, black, coords, end)
if __name__ == "__main__":
test_data = np.random.randint(0, 2, (51, 26))
test_data[0, :] = 1
test_data[-1, :] = 1
test_data[:, 0] = 1
test_data[:, -1] = 1
print(test_data)
pygame.init()
window = pygame.display.set_mode(screen_size)
pygame.display.set_caption('Boids')
screen = pygame.display.get_surface()
screen.fill(white)
maze_shape = tuple([test_data.shape[1] - 1, (test_data.shape[0] - 1) / 2])
print(maze_shape)
tile_dims = [x / y for x, y in zip(screen_size, maze_shape)]
print(tile_dims)
for y, row in enumerate(test_data):
for x, wallval in enumerate(row):
if y % 2 == 0 and wallval: # Horizontal wall
coordinates = tuple([x * tile_dims[0] + offset[0], y * int(tile_dims[1] / 2) + offset[1]])
draw_horizontal(window, coordinates, tile_dims[0])
elif wallval: # Vertical wall
coordinates = tuple([x * tile_dims[0] + offset[0], (y - 1) * int(tile_dims[1] / 2) + offset[1]])
draw_vertical(window, coordinates, tile_dims[1])
pygame.display.update()
while True:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment