This project is a C++ visualization of the A pathfinding algorithm*, built using the SFML graphics library.
It is inspired by the popular Python + Pygame A* tutorial by Tech With Tim,
available here on YouTube 👉 A* Path Finding Algorithm Tutorial.
This version recreates the same functionality in modern C++17, using SFML for graphics and CMake for building.
Here’s a preview of the A* Pathfinding Visualization:
- Real-time A* pathfinding visualization
- Interactive grid where you can:
- Set a start point (orange)
- Set an end point (turquoise)
- Draw barriers (black) by holding the left mouse button
- Erase spots using the right mouse button
- Run the algorithm with the Space key
- Reset the grid with the C key
- Smooth rendering using SFML
| Element | Color | Description |
|---|---|---|
| Start | 🟧 Orange | Starting node |
| End | 🟦 Turquoise | Goal node |
| Barrier | ⬛ Black | Walls that block the path |
| Open Set | 🟩 Green | Nodes being explored |
| Closed Set | 🟥 Red | Nodes already evaluated |
| Path | 🟪 Purple | Final shortest path |
| Grid Background | ⚪ White | Empty traversable cells |
| Action | Mouse / Key | Description |
|---|---|---|
| Set Start Node | Left-click on an empty cell | The first left-click sets the start node (orange) |
| Set End Node | Left-click on another empty cell | The second left-click sets the end node (turquoise) |
| Draw Barriers | Hold Left Mouse and drag | Adds black barriers continuously |
| Erase Cells | Hold Right Mouse and drag | Removes barriers or nodes |
| Run A* | Press Spacebar | Starts the A* pathfinding algorithm |
| Reset Grid | Press C | Clears the grid and resets everything |
The A* (A-star) algorithm is an informed search algorithm that finds the shortest path between two points.
It uses a heuristic function to estimate the cost from the current node to the goal.
This project uses the Manhattan distance heuristic.
- git clone https://github.com//astar-visualization-cpp.git
- cd astar-visualization-cpp
- mkdir build
- cd build
- cmake ..
- make
- ./astar
