Pseudocode-driven 2D algorithm visualizer
Project description
GraphicsAlgoVisualizer
A pseudocode-driven 2D algorithm visualizer built with Python and CustomTkinter. Write algorithms in a simple DSL, pick a canvas type, and watch them execute step-by-step with animated visuals, speed control, and presentation mode.
✨ Features
- Pseudocode DSL — Write algorithms in a clean, Python-like subset with
for,while,if/elif/else, variables, expressions, and built-in functions. No Python knowledge required. - Multiple Canvas Types — Grid, Array, and Graph canvases with dedicated renderers and built-in operations.
- Bundled Algorithm Presets — Bresenham line drawing, Bubble sort, BFS pathfinding, and Dijkstra's shortest path ship out of the box as TOML presets.
- In-App Graph Editor — Click to add nodes, drag between nodes to create edges, set weights — build custom networks visually.
- Step-by-Step Playback — Play, pause, step forward, adjust speed, and see line-by-line highlighting of the executing pseudocode.
- Presentation Mode — A distraction-free, canvas-only view for demos and classroom walkthroughs.
- Theme System — Centralized theme tokens drive all canvas and UI colors for a consistent look.
- Plugin Architecture — Drop-in and entry-point based plugin loading. Extend the visualizer with custom canvas types (see the bundled
pyalgoviz-heap-canvasexample). - User Presets — Save your own algorithms as
.tomlpreset files and load them from a user presets directory.
📋 Prerequisites
- Python 3.11+
- Tkinter (usually ships with Python; see platform notes below)
📦 Installation
For users
pyalgoviz is published on PyPI — no cloning required:
pip install pyalgoviz
Then run it:
pyalgoviz
Adding a plugin
Plugins add new canvas types (see Plugins below). Install one from PyPI and pyalgoviz auto-discovers it on the next launch — no configuration needed:
pip install pyalgoviz-heap-canvas
You'll see Loaded plugin canvas types: heap logged at startup once it's picked up. Note that installing a canvas-type plugin doesn't add a ready-to-run algorithm by itself — the app only lists algorithms it has a preset for. To actually use the new canvas type, write a preset with canvas = "heap" (see Writing a Custom Preset).
For developers
Clone the repo and install in editable mode so code changes take effect immediately, without re-installing.
1. Clone the Repository
git clone https://github.com/F3rNaNDEZ57/GraphicsAlgoVisualizer.git
cd GraphicsAlgoVisualizer
2. Create a Virtual Environment
macOS / Linux
python3 -m venv .venv
source .venv/bin/activate
Windows (PowerShell)
python -m venv .venv
.\.venv\Scripts\Activate.ps1
Windows (Command Prompt)
python -m venv .venv
.venv\Scripts\activate.bat
3. Install the Package
Install in editable (development) mode:
pip install -e ".[dev]"
Note: The
[dev]extra includespytestfor running tests.
To also work on the bundled example plugin, install it editable too:
pip install -e plugins/pyalgoviz-heap-canvas
4. Run the Visualizer
pyalgoviz
Or run directly as a module:
python -m pyalgoviz.app
🖥️ Platform-Specific Notes
macOS
Tkinter is included with the official Python installer from python.org. If you installed Python via Homebrew, you may need to install it separately:
brew install python-tk@3.11
Linux (Debian / Ubuntu)
sudo apt update
sudo apt install python3-tk
Linux (Fedora)
sudo dnf install python3-tkinter
Linux (Arch)
sudo pacman -S tk
Windows
Tkinter is bundled with the standard Python installer from python.org. No extra steps needed — just make sure to check "tcl/tk and IDLE" during installation if using the custom installer.
🏗️ Project Structure
GraphicsAlgoVisualizer/
├── src/pyalgoviz/
│ ├── app.py # Entry point
│ ├── theme.py # Centralized theme tokens
│ ├── canvas_types.py # Side-effect import to register canvas types
│ ├── plugins.py # Plugin discovery and loading
│ ├── preset_loader.py # TOML preset loader
│ ├── canvas/ # Canvas types, renderers, and registry
│ │ ├── base.py # Abstract base canvas
│ │ ├── registry.py # Canvas type registry
│ │ ├── grid_canvas.py # Grid canvas (e.g., Bresenham)
│ │ ├── array_canvas.py # Array canvas (e.g., Bubble sort)
│ │ ├── graph_canvas.py # Graph canvas (e.g., BFS, Dijkstra)
│ │ └── tk_*_renderer.py # Tkinter renderers for each canvas
│ ├── engine/ # Step engine and playback state
│ │ ├── runner.py # Runs pseudocode on a canvas
│ │ └── playback.py # Play/pause/step state machine
│ ├── pseudocode/ # DSL interpreter
│ │ ├── interpreter.py # Pseudocode interpreter
│ │ ├── builtins_registry.py# Built-in functions (PlotPixel, Swap, Visit, etc.)
│ │ ├── step_event.py # Step event payloads
│ │ └── errors.py # Error types
│ ├── presets/ # Bundled TOML algorithm presets
│ │ ├── bresenham-line.toml
│ │ ├── bubble-sort.toml
│ │ ├── bfs-pathfinding.toml
│ │ └── dijkstra-shortest-path.toml
│ └── ui/ # CustomTkinter UI layer
│ ├── main_window.py # Main application window
│ ├── graph_editor_model.py # Headless graph editor model
│ └── graph_editor_view.py # Visual graph editor widget
├── plugins/ # Drop-in plugin directory
│ └── pyalgoviz-heap-canvas/ # Example plugin
├── tests/ # Test suite (pytest)
├── pyproject.toml # Project metadata and build config
└── .gitignore
🧪 Running Tests
pytest
Run with verbose output:
pytest -v
Run a specific test file:
pytest tests/test_interpreter.py
📝 Writing a Custom Preset
Presets are .toml files that define an algorithm's pseudocode, canvas type, and parameters. A preset has a [preset] table (name, canvas, source, optional description), a [canvas] table for canvas constructor params, and optional [inputs.<key>] tables for user-editable input widgets. Place your file in the bundled src/pyalgoviz/presets/ directory or the user presets directory (~/.pyalgoviz/presets/).
Example — a simple grid algorithm:
[preset]
name = "My Algorithm"
canvas = "grid"
description = "Plots a diagonal line."
source = '''
for i in range(10):
PlotPixel(i, i)
'''
[canvas]
width = 20
height = 20
Supported Canvas Types
| Canvas | Use Case | Key Builtins |
|---|---|---|
grid |
2D grid algorithms | PlotPixel |
array |
Sorting / linear data | SetValue, Swap, Compare, Value, Length |
graph |
Graph traversal / shortest path | Visit, Highlight, Neighbors, NodeCount, Start, Goal, Weight |
Every canvas type also gets ShowAnswer(value) (or ShowAnswer(label, value)) for free, to narrate a final result regardless of canvas — see src/pyalgoviz/pseudocode/builtins_registry.py for the full whitelist. Plugin canvas types add their own builtins on top of this (see Plugins below).
🔌 Plugins
The visualizer supports two plugin mechanisms:
- Drop-in plugins — Place a Python package in the
plugins/directory. It will be auto-discovered on startup. - Entry-point plugins — Register a
pyalgoviz.canvasesentry point in your package'spyproject.toml. Installed packages with this entry point are loaded automatically.
pyalgoviz-heap-canvas is a working example of an entry-point plugin, published on PyPI:
pip install pyalgoviz-heap-canvas
Its source lives at plugins/pyalgoviz-heap-canvas/. It registers a heap canvas type with SetValue, Swap, Compare (visualized) and Value, Length, Parent, LeftChild, RightChild (read-only) builtins on top of the ones every canvas gets.
There's no bundled preset for it — write one, e.g. a single sift-down pass from the root:
[preset]
name = "Heap Sift Down"
canvas = "heap"
description = "Sifts the root down into place (requires pyalgoviz-heap-canvas)."
source = '''
i = 0
n = Length()
done = 0
while done == 0:
left = LeftChild(i)
right = RightChild(i)
smallest = i
if left < n:
Compare(smallest, left)
if Value(left) < Value(smallest):
smallest = left
if right < n:
Compare(smallest, right)
if Value(right) < Value(smallest):
smallest = right
if smallest == i:
done = 1
else:
Swap(i, smallest)
i = smallest
'''
[canvas]
values = [9, 4, 7, 1, 8, 3, 6, 2, 5]
Save this as a .toml file in ~/.pyalgoviz/presets/ and it'll show up in the algorithm picker next time you launch pyalgoviz.
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Make your changes
- Run the tests (
pytest) - Commit with a descriptive message (
git commit -m "Add my feature") - Push to your fork (
git push origin feature/my-feature) - Open a Pull Request
📄 License
MIT — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyalgoviz-0.1.1.tar.gz.
File metadata
- Download URL: pyalgoviz-0.1.1.tar.gz
- Upload date:
- Size: 51.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dd390951ef31ef1a5d56a08d9a8fcfd848b683108add953ae2b60600623a7fe
|
|
| MD5 |
24fc8f799b82d31339c3a0a910c9cf7e
|
|
| BLAKE2b-256 |
2c56b5883c36a5ae65b419a2afead352ad18b21b994c45d9217ca993e1ac1164
|
Provenance
The following attestation bundles were made for pyalgoviz-0.1.1.tar.gz:
Publisher:
publish-pyalgoviz.yml on F3rNaNDEZ57/GraphicsAlgoVisualizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyalgoviz-0.1.1.tar.gz -
Subject digest:
6dd390951ef31ef1a5d56a08d9a8fcfd848b683108add953ae2b60600623a7fe - Sigstore transparency entry: 2150434624
- Sigstore integration time:
-
Permalink:
F3rNaNDEZ57/GraphicsAlgoVisualizer@d16212ce7cf1cdb4967e357f0e28822060fe0c20 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/F3rNaNDEZ57
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pyalgoviz.yml@d16212ce7cf1cdb4967e357f0e28822060fe0c20 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyalgoviz-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyalgoviz-0.1.1-py3-none-any.whl
- Upload date:
- Size: 46.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4df8232bfe5797f6876c4154b9f4a74e71c8d01fd9128aaaca60c0202cbcc538
|
|
| MD5 |
e39ee95a2355e659bcd80d5c1662dd5d
|
|
| BLAKE2b-256 |
ca8489819ec6b8199a2309fafb5365ff94debdbbb39980158034ad6d66161d8c
|
Provenance
The following attestation bundles were made for pyalgoviz-0.1.1-py3-none-any.whl:
Publisher:
publish-pyalgoviz.yml on F3rNaNDEZ57/GraphicsAlgoVisualizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyalgoviz-0.1.1-py3-none-any.whl -
Subject digest:
4df8232bfe5797f6876c4154b9f4a74e71c8d01fd9128aaaca60c0202cbcc538 - Sigstore transparency entry: 2150434900
- Sigstore integration time:
-
Permalink:
F3rNaNDEZ57/GraphicsAlgoVisualizer@d16212ce7cf1cdb4967e357f0e28822060fe0c20 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/F3rNaNDEZ57
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pyalgoviz.yml@d16212ce7cf1cdb4967e357f0e28822060fe0c20 -
Trigger Event:
push
-
Statement type: