An interactive Tower of Hanoi visualizer built with PyQt6, featuring both 2D and 3D animated views, a recursion call tree, and a depth chart.
- 2D Animation: Watch disks move in real time on a QGraphicsView.
- 3D Visualization: Matplotlib 3D bar charts.
- Recursion Call Tree: Expandable tree view of recursive calls and disk moves.
- Depth Chart: Matplotlib chart plotting recursion depth over each move.
- Controls:
- Start: Run full animation automatically.
- Step: Perform one move at a time.
- Speed Slider: Adjust animation interval between moves.
- Move Counter: Track current move number.
- Reset: Clear the board and start over.
- Disk Selector: Choose number of disks (1–10).
- Python 3.10 or higher
- PyQt6 (Qt GUI bindings)
- Matplotlib (for 2D/3D plotting)
Quick start (recommended):
# From the project folder
make venv
make install
make runManual setup:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txtNotes:
- On macOS, run from Terminal/iTerm (not Code Runner) and ensure VS Code uses your venv interpreter.
Developer workflow:
- Use
make venvthenmake installto set up. - Run the app with
make run. - Run tests with
make test(this installs dev deps and setsPYTHONPATHso imports resolve without changing code).
2D View:
3D View:
Recursion Call Tree:
Depth Chart:
Run from the project directory:
# Option 1: Makefile (recommended)
make run
# Option 2: Directly with Python
python main.pyKeyboard shortcuts:
- Space: Start/Pause
- N: Step once
- R: Reset
Layout tips:
- Docks are resizable: drag the borders to make the right “Depth Chart” and bottom “3D View” larger or smaller.
- The app opens with a larger window and increased default sizes for both charts for readability.
Troubleshooting:
- “ModuleNotFoundError: PyQt6” → install deps with
pip install -r requirements.txt. - “Qt platform plugin could not be initialized” on macOS/Linux → run from a real terminal and ensure the venv is active; try
pip install --upgrade PyQt6. - Blank/slow plots on first run → ensure
matplotlibinstalled via the steps above.
Notes for Windows:
- Activate the venv with
.venv\\Scripts\\activate. - Replace
makecommands with the equivalent steps:python -m venv .venv && .venv\\Scripts\\python -m pip install --upgrade pippip install -r requirements.txtpython main.py
Evaluation only all rights reserved.
You may clone and run locally for personal or hiring evaluation.
You may not redistribute, sublicense, or use this work commercially without my written permission.
See the LICENSE file for the exact terms.
Qt note: This app uses PyQt6 (GPLv3). Do not redistribute the app unless you comply with GPLv3 or have a Qt commercial license.