complete mazes gif update
@@ -8,6 +8,10 @@ These projects were created mostly for myself, but after amassing so many, I've
|
|||||||
|
|
||||||
Once I have a moment, I intend to add GIFs showing them in action (as currently this repository is very boring).
|
Once I have a moment, I intend to add GIFs showing them in action (as currently this repository is very boring).
|
||||||
|
|
||||||
|
A small reminder about everything in this repository: these are all rendering real-time and built using Python to take a peek through the keyhole of visual algorithms. They aren't really intended to be a perfect reflection of Python nor my abilities.
|
||||||
|
|
||||||
|
Regardless, I hope you enjoy viewing them, I certainly enjoyed creating and learning about them during school and after hours.
|
||||||
|
|
||||||
## Current Projects
|
## Current Projects
|
||||||
|
|
||||||
- [Mazes](./mazes/README.md)
|
- [Mazes](./mazes/README.md)
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ def cellExists(coordinate):
|
|||||||
x, y = coordinate
|
x, y = coordinate
|
||||||
return not (x < 0 or x >= columns or y < 0 or y >= rows)
|
return not (x < 0 or x >= columns or y < 0 or y >= rows)
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
size(750, 750)
|
size(750, 750)
|
||||||
colorMode(HSB, 360)
|
colorMode(HSB, 360)
|
||||||
@@ -91,8 +92,13 @@ def setup():
|
|||||||
offsets = [(0, 1), (1, 0), (-1, 0), (0, -1)]
|
offsets = [(0, 1), (1, 0), (-1, 0), (0, -1)]
|
||||||
movers = [Mover(random.randint(0, columns-1), random.randint(0, rows-1)) for _ in range(columns * rows / 1000)]
|
movers = [Mover(random.randint(0, columns-1), random.randint(0, rows-1)) for _ in range(columns * rows / 1000)]
|
||||||
frameRate(99999)
|
frameRate(99999)
|
||||||
|
|
||||||
|
import time
|
||||||
|
s = False
|
||||||
def draw():
|
def draw():
|
||||||
global grid, movers
|
global grid, movers, s
|
||||||
|
if not s:
|
||||||
|
return
|
||||||
background(204)
|
background(204)
|
||||||
for _ in range(50):
|
for _ in range(50):
|
||||||
for mover in movers:
|
for mover in movers:
|
||||||
@@ -100,3 +106,12 @@ def draw():
|
|||||||
for row in grid:
|
for row in grid:
|
||||||
for cell in row:
|
for cell in row:
|
||||||
cell.render()
|
cell.render()
|
||||||
|
|
||||||
|
def keyPressed():
|
||||||
|
global s
|
||||||
|
s = not s
|
||||||
|
if s:
|
||||||
|
frameRate(60)
|
||||||
|
else:
|
||||||
|
frameRate(10)
|
||||||
|
print('Paused' if s else 'Resumed')
|
||||||
|
|||||||
BIN
mazes/MazeClustersCreator_1.gif
Normal file
|
After Width: | Height: | Size: 1.9 MiB |
@@ -114,7 +114,7 @@ def tick():
|
|||||||
# Check if we're done
|
# Check if we're done
|
||||||
if current[1] < 0:
|
if current[1] < 0:
|
||||||
noLoop()
|
noLoop()
|
||||||
return
|
return True
|
||||||
|
|
||||||
x = (current[0] + moveSet[0][0], current[1] + moveSet[0][1]) # North
|
x = (current[0] + moveSet[0][0], current[1] + moveSet[0][1]) # North
|
||||||
y = (current[0] + moveSet[1][0], current[1] + moveSet[1][1]) # West
|
y = (current[0] + moveSet[1][0], current[1] + moveSet[1][1]) # West
|
||||||
@@ -144,13 +144,18 @@ def tick():
|
|||||||
|
|
||||||
# Move the current cell.
|
# Move the current cell.
|
||||||
current = current[0] + moveConst[0], current[1]
|
current = current[0] + moveConst[0], current[1]
|
||||||
|
return False
|
||||||
|
|
||||||
|
s = False
|
||||||
def draw():
|
def draw():
|
||||||
|
if s:
|
||||||
for _ in range(columns):
|
for _ in range(columns):
|
||||||
tick()
|
tick()
|
||||||
time.sleep(0.1)
|
time.sleep(2.5 // rows)
|
||||||
render()
|
render()
|
||||||
|
|
||||||
def mouseClicked():
|
def mouseClicked():
|
||||||
|
global s
|
||||||
|
s = True
|
||||||
loop()
|
loop()
|
||||||
generate(mouseX, mouseY)
|
generate(*[min(mouseX, mouseY)] * 2)
|
||||||
|
|||||||
BIN
mazes/MazeGenBinaryTree_1.gif
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
mazes/MazeGenGrowingTree_1.gif
Normal file
|
After Width: | Height: | Size: 8.8 MiB |
@@ -49,7 +49,7 @@ class Cell:
|
|||||||
fill(255)
|
fill(255)
|
||||||
strokeWeight(2.5)
|
strokeWeight(2.5)
|
||||||
if showNumbers:
|
if showNumbers:
|
||||||
textSize(50)
|
textSize(24)
|
||||||
textAlign(CENTER, CENTER)
|
textAlign(CENTER, CENTER)
|
||||||
text(symbolize(self.identity), divX / 2.0, divY / 2.0)
|
text(symbolize(self.identity), divX / 2.0, divY / 2.0)
|
||||||
if not self.visited:
|
if not self.visited:
|
||||||
@@ -90,7 +90,7 @@ def generate():
|
|||||||
global columns, rows, grid, divX, divY, offsets
|
global columns, rows, grid, divX, divY, offsets
|
||||||
# Bottom, Right, Left, Top
|
# Bottom, Right, Left, Top
|
||||||
offsets = [(0, 1), (1, 0), (-1, 0), (0, -1)]
|
offsets = [(0, 1), (1, 0), (-1, 0), (0, -1)]
|
||||||
columns, rows = 10, 10
|
columns, rows = 25, 25
|
||||||
divX, divY = width / float(columns), height / float(rows)
|
divX, divY = width / float(columns), height / float(rows)
|
||||||
grid = [[Cell(x, y) for y in range(rows)] for x in range(columns)]
|
grid = [[Cell(x, y) for y in range(rows)] for x in range(columns)]
|
||||||
|
|
||||||
@@ -135,6 +135,7 @@ def setup():
|
|||||||
noLoop()
|
noLoop()
|
||||||
generate()
|
generate()
|
||||||
frameRate(10)
|
frameRate(10)
|
||||||
|
redraw()
|
||||||
|
|
||||||
def checkMaze():
|
def checkMaze():
|
||||||
for row in grid:
|
for row in grid:
|
||||||
|
|||||||
BIN
mazes/MazeGenKruskal_1.gif
Normal file
|
After Width: | Height: | Size: 24 MiB |
@@ -58,6 +58,10 @@ def openWalls(x1, y1, x2, y2):
|
|||||||
if offset == offsets[3]:
|
if offset == offsets[3]:
|
||||||
grid[x2][y2].bottom = False
|
grid[x2][y2].bottom = False
|
||||||
|
|
||||||
|
global columns, rows
|
||||||
|
grid[x1][y1].visited = True
|
||||||
|
if x2 < columns and y2 < rows:
|
||||||
|
grid[x2][y2].visited = True
|
||||||
# Validates whether a coordinate is valid with the curret columns and rows set
|
# Validates whether a coordinate is valid with the curret columns and rows set
|
||||||
def valid(coordinate):
|
def valid(coordinate):
|
||||||
global columns, rows
|
global columns, rows
|
||||||
@@ -99,16 +103,16 @@ def tick():
|
|||||||
global current, runSet, runSetActive
|
global current, runSet, runSetActive
|
||||||
if runSetActive:
|
if runSetActive:
|
||||||
if len(runSet) > 0:
|
if len(runSet) > 0:
|
||||||
print('a')
|
# print('a')
|
||||||
get = runSet[0]
|
get = runSet[0]
|
||||||
if get == []:
|
if get == []:
|
||||||
return
|
return
|
||||||
print('b')
|
# print('b')
|
||||||
print(runSet, get)
|
# print(runSet, get)
|
||||||
choice = random.choice(get)
|
choice = random.choice(get)
|
||||||
print('c')
|
# print('c')
|
||||||
openWalls(choice[0], choice[1], choice[0], choice[1] - 1)
|
openWalls(choice[0], choice[1], choice[0], choice[1] - 1)
|
||||||
print('d')
|
# print('d')
|
||||||
del runSet[0]
|
del runSet[0]
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|||||||
BIN
mazes/MazeGenSidewinder_1.gif
Normal file
|
After Width: | Height: | Size: 1.8 MiB |
BIN
mazes/MazeGenSolve_1.gif
Normal file
|
After Width: | Height: | Size: 5.6 MiB |
@@ -104,7 +104,7 @@ def setup():
|
|||||||
size(750, 750)
|
size(750, 750)
|
||||||
frameRate(10000)
|
frameRate(10000)
|
||||||
generate()
|
generate()
|
||||||
|
noLoop()
|
||||||
def mazeGenTick(loops=500):
|
def mazeGenTick(loops=500):
|
||||||
global current, next, i
|
global current, next, i
|
||||||
for _ in range(loops):
|
for _ in range(loops):
|
||||||
@@ -140,7 +140,11 @@ def draw():
|
|||||||
time.sleep(2.0)
|
time.sleep(2.0)
|
||||||
generate()
|
generate()
|
||||||
if complete > 1:
|
if complete > 1:
|
||||||
|
for _ in range(300):
|
||||||
mazeGenTick()
|
mazeGenTick()
|
||||||
render()
|
render()
|
||||||
else:
|
else:
|
||||||
mazeGenTick(1)
|
mazeGenTick(1)
|
||||||
|
|
||||||
|
def mouseClicked():
|
||||||
|
loop()
|
||||||
|
|||||||
BIN
mazes/MazeGenV2_1.gif
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
@@ -8,14 +8,28 @@ Projects that generate mazes using various algorithms. Developed primarily in 20
|
|||||||
|
|
||||||
- **MazeGenV2** Second maze generation attempt. First *working* maze implementation. Recursive Backtracker algorithm.
|
- **MazeGenV2** Second maze generation attempt. First *working* maze implementation. Recursive Backtracker algorithm.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
- **MazeGenSolve** - Maze gen with a completed path shown after. Recursive Backtracker algorithm for Generation, A* algorithm for pathfinding (very similar in theory).
|
- **MazeGenSolve** - Maze gen with a completed path shown after. Recursive Backtracker algorithm for Generation, A* algorithm for pathfinding (very similar in theory).
|
||||||
|
|
||||||
- **MazeGenBinaryTree** - Binary Tree algorithm
|

|
||||||
|
|
||||||
- **MazeGenGrowingTree** - Growing Tree algorithm
|
- **MazeGenBinaryTree** - Binary Tree algorithm. Creates a grid equal to the minimum of the mouse coordinates (increasing from the top-left). Requires some editing to make sure it doesn't automatically crash if you click near the center to bottom-right.
|
||||||
|
|
||||||
- **MazeGenKruskalTree** - Kruskal Tree algorithm
|

|
||||||
|
|
||||||
- **MazeGenSidewinder** - Sidewinder algorithm. A little bit buggy at the end, but properly implemented none the less.
|
- **MazeGenGrowingTree** - Growing Tree algorithm. Grows centered on where your mouse clicks (originally from a randomized position).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- **MazeGenKruskal** - Kruskal Tree algorithm
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- **MazeGenSidewinder** - Sidewinder algorithm. A little bit buggy at the end, but properly implemented none the less. I had difficulty implementing this, and thus never got around to figuring out how to remove those boxes. Before recording, I modified it to properly show the erroring boxes, otherwise they would never be visible.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
- **MazeClustersCreator** - Not so much a maze as a interesting side-project when developing my maze generators. Somewhat buggy.
|
- **MazeClustersCreator** - Not so much a maze as a interesting side-project when developing my maze generators. Somewhat buggy.
|
||||||
|
|
||||||
|

|
||||||