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).
|
||||
|
||||
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
|
||||
|
||||
- [Mazes](./mazes/README.md)
|
||||
|
||||
@@ -80,6 +80,7 @@ def cellExists(coordinate):
|
||||
x, y = coordinate
|
||||
return not (x < 0 or x >= columns or y < 0 or y >= rows)
|
||||
|
||||
|
||||
def setup():
|
||||
size(750, 750)
|
||||
colorMode(HSB, 360)
|
||||
@@ -91,8 +92,13 @@ def setup():
|
||||
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)]
|
||||
frameRate(99999)
|
||||
|
||||
import time
|
||||
s = False
|
||||
def draw():
|
||||
global grid, movers
|
||||
global grid, movers, s
|
||||
if not s:
|
||||
return
|
||||
background(204)
|
||||
for _ in range(50):
|
||||
for mover in movers:
|
||||
@@ -100,3 +106,12 @@ def draw():
|
||||
for row in grid:
|
||||
for cell in row:
|
||||
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
|
||||
if current[1] < 0:
|
||||
noLoop()
|
||||
return
|
||||
return True
|
||||
|
||||
x = (current[0] + moveSet[0][0], current[1] + moveSet[0][1]) # North
|
||||
y = (current[0] + moveSet[1][0], current[1] + moveSet[1][1]) # West
|
||||
@@ -144,13 +144,18 @@ def tick():
|
||||
|
||||
# Move the current cell.
|
||||
current = current[0] + moveConst[0], current[1]
|
||||
return False
|
||||
|
||||
s = False
|
||||
def draw():
|
||||
for _ in range(columns):
|
||||
tick()
|
||||
time.sleep(0.1)
|
||||
render()
|
||||
if s:
|
||||
for _ in range(columns):
|
||||
tick()
|
||||
time.sleep(2.5 // rows)
|
||||
render()
|
||||
|
||||
def mouseClicked():
|
||||
global s
|
||||
s = True
|
||||
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)
|
||||
strokeWeight(2.5)
|
||||
if showNumbers:
|
||||
textSize(50)
|
||||
textSize(24)
|
||||
textAlign(CENTER, CENTER)
|
||||
text(symbolize(self.identity), divX / 2.0, divY / 2.0)
|
||||
if not self.visited:
|
||||
@@ -90,7 +90,7 @@ def generate():
|
||||
global columns, rows, grid, divX, divY, offsets
|
||||
# Bottom, Right, Left, Top
|
||||
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)
|
||||
grid = [[Cell(x, y) for y in range(rows)] for x in range(columns)]
|
||||
|
||||
@@ -135,6 +135,7 @@ def setup():
|
||||
noLoop()
|
||||
generate()
|
||||
frameRate(10)
|
||||
redraw()
|
||||
|
||||
def checkMaze():
|
||||
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]:
|
||||
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
|
||||
def valid(coordinate):
|
||||
global columns, rows
|
||||
@@ -99,16 +103,16 @@ def tick():
|
||||
global current, runSet, runSetActive
|
||||
if runSetActive:
|
||||
if len(runSet) > 0:
|
||||
print('a')
|
||||
# print('a')
|
||||
get = runSet[0]
|
||||
if get == []:
|
||||
return
|
||||
print('b')
|
||||
print(runSet, get)
|
||||
# print('b')
|
||||
# print(runSet, get)
|
||||
choice = random.choice(get)
|
||||
print('c')
|
||||
# print('c')
|
||||
openWalls(choice[0], choice[1], choice[0], choice[1] - 1)
|
||||
print('d')
|
||||
# print('d')
|
||||
del runSet[0]
|
||||
return
|
||||
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)
|
||||
frameRate(10000)
|
||||
generate()
|
||||
|
||||
noLoop()
|
||||
def mazeGenTick(loops=500):
|
||||
global current, next, i
|
||||
for _ in range(loops):
|
||||
@@ -140,7 +140,11 @@ def draw():
|
||||
time.sleep(2.0)
|
||||
generate()
|
||||
if complete > 1:
|
||||
mazeGenTick()
|
||||
for _ in range(300):
|
||||
mazeGenTick()
|
||||
render()
|
||||
else:
|
||||
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.
|
||||
|
||||

|
||||
|
||||
- **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.
|
||||
|
||||

|
||||