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
Install from PyPI:
pip install grafix
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, fps=60.0, canvas_size=(800, 800), render_scale=2.0, parameter_gui=True)
Basic Features
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 returns on each frame.Llets you define layers. You can manage stroke colors, thickness per layer.Exportprovides a headless export entrypoint (SVG implemented; image/G-code are stubs).Parameter GUIlets you tweak parameters live while the sketch is running.
Development
Dev tools (optional):
pip install -e ".[dev]"
Run a sketch:
python sketch/readme.py
Configuration
Grafix can read a YAML config file to locate external assets (fonts) and to choose where it writes runtime outputs, .svg .png, .mp4, .gcode.
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.
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
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.3.tar.gz.
File metadata
- Download URL: grafix-0.0.3.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 |
9826ddf2f5882c803f2874e2047c2cdef11ac3b5f75e686d5cf0d1640b8d81bf
|
|
| MD5 |
b11fbb0e2dc012b0c9d83ce47fa6e3f4
|
|
| BLAKE2b-256 |
06ae6dc0bf8b758be1b20037b7321496daeceae7b989e012ef783ac2c0944692
|
File details
Details for the file grafix-0.0.3-py3-none-any.whl.
File metadata
- Download URL: grafix-0.0.3-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 |
42cbe2b8bc5600f1c303f13113ca9e5b2351dd3c690a00cb21b12552b8e1ea32
|
|
| MD5 |
7609891a66a1e5efea389128f7819b7c
|
|
| BLAKE2b-256 |
f89a88a4cd7755f7bd7c5db80af96fa0aa5e5d93d25cdc894232284cee890023
|