Line-based geometry toolkit with chained effects and real-time preview.
Project description
Grafix is a lightweight toolkit for building line-based geometries, applying chained effects, and viewing the result in real time.
Shapes and effects are registered through the public API (grafix.api), allowing sketches to be composed by combining G.<shape>() calls with pipelines built from E.<effect>().
Examples
from grafix.api import E, G, run
def draw(t: float):
poly = G.sphere()
effect = E.scale().rotate()
return effect(poly)
if __name__ == "__main__":
run(draw, fps=60.0, canvas_size=(800, 800), render_scale=2.0, parameter_gui=True)
Development
Editable install (recommended):
pip install -e .
Dev tools (optional):
pip install -e ".[dev]"
Run a sketch:
python sketch/perf_sketch.py
Configuration (config.yaml) (optional)
Grafix can read a YAML config file to locate external assets (fonts) and to choose where it writes runtime outputs.
Grafix always starts from the packaged defaults (grafix/resource/default_config.yaml), 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.
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
Example
# ./.grafix/config.yaml
paths:
font_dirs:
- "~/Fonts"
output_dir: "./out"
Keys
paths.font_dirs(list of paths): searched forG.text(font=...)and the Parameter GUI font picker.paths.output_dir(path): base directory for auto-saved outputs (default:data/output).- Parameter GUI state:
{output_dir}/param_store/{script}.json - Interactive saves:
{output_dir}/svg,{output_dir}/png,{output_dir}/video - MIDI snapshots:
{output_dir}/midi
- Parameter GUI state:
ui.window_positions.draw(2 ints): draw window position(x, y)in pixels.ui.window_positions.parameter_gui(2 ints): Parameter GUI window position(x, y)in pixels.ui.parameter_gui.window_size(2 ints): Parameter GUI window size(width, height)in pixels.export.png.scale(float): PNG output scale multiplier relative tocanvas_size.
All runtime outputs are written under paths.output_dir.
Tip: Parameter persistence stores the selected font value. If you move a sketch to another machine and the font is not available, set paths.font_dirs (or reset state by deleting the corresponding {output_dir}/param_store/*.json file).
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.
Features (current)
grafix.api.Glets you generate primitive shapes such assphere,polyhedron,grid, and more.grafix.api.Elets you modulate and transform shapes such asaffine,fill,repeat, and more.grafix.api.Llets you define layers so you can manage colors, stroke widths, and other styling attributes per layer.grafix.api.run()lets you render any shapes, effects, and layers that a user-defineddraw(t)function returns on each frame.Parameter GUIlets you tweak parameters live while the sketch is running.grafix.api.Exportprovides a headless export entrypoint (SVG implemented; image/G-code are stubs).
Not implemented yet
- MIDI/CC input, LFOs, keyboard shortcuts, screenshot/video recording
- PNG/G-code actual file generation (export stubs currently raise
NotImplementedError)
Dependencies
Core (default):
- numpy
- numba
- shapely
- pyclipper
- moderngl
- pyglet
- imgui
- fontPens
- fontTools
- PyYAML
- mido
- python-rtmidi
- psutil
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.2.tar.gz.
File metadata
- Download URL: grafix-0.0.2.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 |
d18648c27921404ff2f1f2fa94801917fa1cbf698a3dfe4e59f29b26e937b03d
|
|
| MD5 |
954f1efdf2353039afd851b9f159dbe5
|
|
| BLAKE2b-256 |
1bef6a380cd6ba15c50d083ff500393933812b8edb7126ad8849b0ce05823beb
|
File details
Details for the file grafix-0.0.2-py3-none-any.whl.
File metadata
- Download URL: grafix-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.4 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 |
f62a94918c27b411d3be012f6ab8f6333cc8313500cec16421b58e03ae93e3c9
|
|
| MD5 |
5cd454f18714e3a8901bbaa0b93a5e2d
|
|
| BLAKE2b-256 |
265b4a6fde464dd33ed37c86066904476ad66f901c28fc73392f247bcd129bdc
|