Line-based geometry toolkit with chained effects and real-time preview.
Project description
Grafix is a Python-based creative coding framework compatible with pen plotter.
Installation
pip install grafix
macOS-first. Tested on macOS (Apple Silicon). Other platforms are not officially supported yet.
Quick start
from grafix import E, G, run
def draw(t: float):
poly = G.polygon()
effect = E.fill().displace()
return effect(poly)
if __name__ == "__main__":
run(draw, canvas_size=(800, 800), render_scale=2.0)
Core API
Glets you generate primitives such assphere,polyhedron,grid, and more.Elets you modulate primitives such asaffine,fill,repeat, and more.runlets you render a user-defineddraw(t)function on each frame.
Optional features
Llets you define layers (stroke color, thickness, etc.).cclets you map MIDI CC messages to any parameter.@primitivelets you register custom primitives (they become available underG).@effectlets you register custom effects (they become available underE).@presetlets you register reusable components (only selected params are exposed to the Parameter GUI).Plets you call registered presets asP.<name>(...).Exportprovides a headless export entrypoint (SVG implemented; PNG/MP4/G-code are stubs).Parameter GUIlets you tweak parameters live while the sketch is running.- Keyboard shortcuts let you export output quickly:
Psaves a.pngimageSsaves a.svgfileVrecords an.mp4videoGsaves a.gcodefile for pen plotters
Extending (custom primitives / effects)
You can register your own primitives and effects via decorators:
from grafix.api import effect, primitive
@primitive
def user_prim(*, r=10.0):
...
@effect
def user_eff(inputs, *, amount=1.0):
...
Notes:
- Built-in primitives/effects must provide
meta=...(enforced). - For user-defined ops,
metais optional. If omitted, parameters are not shown in the Parameter GUI.
Presets (reusable components)
Use @preset to register a component, and call it via P.<name>(...):
from grafix import P, preset
@preset(meta={"scale": {"kind": "float", "ui_min": 0.1, "ui_max": 10.0}})
def logo(*, scale: float = 1.0, name=None, key=None):
...
P.logo(scale=2.0)
For IDE completion of P.<name>(...), regenerate stubs after adding/changing presets:
python -m grafix stub
Configuration
A config.yaml lets you locate external fonts and choose where Grafix writes runtime outputs (.svg, .png, .mp4, .gcode).
Grafix starts from the packaged defaults (grafix/resource/default_config.yaml) and then overlays user configs.
Config overlay order (later wins):
- packaged defaults:
grafix/resource/default_config.yaml ./.grafix/config.yaml(project-local)~/.config/grafix/config.yaml(per-user)run(..., config_path="path/to/config.yaml")
Paths support ~ and environment variables like $HOME.
To create a project-local config (starting from the packaged defaults):
mkdir -p .grafix
python -c "from importlib.resources import files; print(files('grafix').joinpath('resource','default_config.yaml').read_text())" > .grafix/config.yaml
$EDITOR .grafix/config.yaml
To autoload user presets from a directory:
paths:
preset_module_dirs:
- "sketch/presets"
Not implemented yet
- LFOs to modulate any parameters with rhythm
- G-code file generation
Development
Dev tools (optional):
pip install -e ".[dev]"
Run a sketch:
python sketch/readme.py
List built-in ops:
python -m grafix list effects
python -m grafix list primitives
python -m grafix list
Dependencies
Core (default):
- numpy
- numba
- shapely
- pyclipper
- moderngl
- pyglet
- imgui
- fontPens
- fontTools
- PyYAML
- mido
- python-rtmidi
- psutil
External:
- resvg (svg to png)
- ffmpeg (video encoding)
Dev (optional):
- pytest
- ruff
- mypy
Project details
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 grafix-0.0.4.tar.gz.
File metadata
- Download URL: grafix-0.0.4.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef5df06b3467aae48fa55d447383e054c9c97c1d51fac91d2700bd4119110d82
|
|
| MD5 |
cdd1ba1961e1ec67ad98cf736d61a1cc
|
|
| BLAKE2b-256 |
3bf36e143494880d86cb3c1745cc5baf6a722087af2e0cd67b7938213941b7b5
|
File details
Details for the file grafix-0.0.4-py3-none-any.whl.
File metadata
- Download URL: grafix-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
966b678499191104772eba1449bc968ed560f89a415efffa1af20a0d78c0d76a
|
|
| MD5 |
4789a558b5799e296903b2533b04b89b
|
|
| BLAKE2b-256 |
38a1bf57afb8354ce1cbbe8b9c24073cca1be3d09c57e329e34a990eb05269c2
|