A high-performance algorithm visualization tool that goes beyond basic grids to simulate real-world navigation challenges like terrain costs and robotic path smoothing.
The Problem: Standard algorithm visualizations are often too abstract, treating every movement as equal cost and every path as a jagged grid-walk, which fails to represent real-world navigation or CNC machining requirements.
The Solution: An interactive "Sandbox" that introduces industry-relevant concepts—weighted "Mud" nodes, diagonal Euclidean costs, and post-processing optimization—to demonstrate how algorithms like A* actually "think" in complex environments.
- Algorithm Face-Off: Run Dijkstra (the careful explorer) and A* (the guided missile) side-by-side in real-time to compare efficiency and node visitation.
-
Terrain Physics (Mud): Hold
Shiftto draw "Mud" nodes (Cost: 10). Watch algorithms dynamically decide whether to plow through the swamp or take the long way around. - Procedural Mazes: Uses the Recursive Division algorithm to instantly generate complex, non-trivial maze structures with a single click.
- Path Smoothing: Includes a post-processing pass using Bresenham's Line Algorithm to "string pull" the jagged grid path into a smooth, realistic trajectory suitable for robotic motion.
-
Dynamic Physics: Supports 8-directional movement with calculated Euclidean costs (
$\sqrt{2}$ for diagonals), creating natural, organic paths.
| Component | Technology | Description |
|---|---|---|
| Core | Python 3.11+ | Main application logic |
| Engine | Pygame | Accelerated 2D rendering & Event handling |
| Data Structures | Priority Queues | Min-Heap implementation for O(log n) retrieval |
| Algorithms | A*, Dijkstra | Weighted graph traversal |
| Math | Bresenham's | Line-of-sight checks for path smoothing |
| UI | Custom | Responsive, resize-aware grid layout |
# 1. Clone the repo
git clone [https://github.com/maxykoin/pathfinding-visualizer.git](https://github.com/maxykoin/pathfinding-visualizer.git)
cd pathfinding-visualizer
# 2. Install dependencies
pip install -r requirements.txt
# 3. Launch the Visualizer
# Note: We run as a module to handle imports correctly
python -m mainThe application is built on a modular "Generator-Based" architecture:
- Grid State Management: The grid is dynamic and responsive. When the window resizes, the
Grid Managerrecalculates the optimal node size (pixels) to fit the screen while preserving the map topology. - Generator Logic (
yield): Algorithms are implemented as Python Generators. Instead of blocking the thread, theyyieldcontrol back to the UI loop after every node visit, allowing for smooth, adjustable animations without freezing the window. - The Optimization Pipeline:
- Step 1 (Search): The algorithm finds the optimal path on the weighted graph.
- Step 2 (Reconstruct): We backtrack from End to Start to build the raw path.
- Step 3 (Smooth): The
get_smooth_pathfunction iterates through the raw path, checking line-of-sight between non-adjacent nodes to eliminate unnecessary waypoints (String Pulling).