flowfields
A generative-art toolkit built around composable vector fields and scalar fields. Fields form trees (similar to syntax trees): leaf nodes are primitives and internal nodes are combinators. It comes in Python and as a p5.js library.
See the demos for a small script and a figure for each feature.
Installation
Python
pip install flowfields
# or
uv add flowfields
The library needs only numpy and Pillow. MatrixField.plot_figure also needs
matplotlib, which comes with the plot extra:
pip install "flowfields[plot]"
To get the latest version from GitHub instead:
pip install git+https://github.com/tiagoft/flowfields.git
p5.js
flowfields.js needs p5.js 2.x. Load it after p5:
<script src="https://cdn.jsdelivr.net/npm/p5@2.4.0/lib/p5.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/tiagoft/flowfields@v0.4.4/js/flowfields.js"></script>
Build fields inside setup() or later. The JS README shows how
the Python API maps to JS, and js/examples/ has drop-in sketches:
single HTML files to save and open in a browser.
Running the demos
git clone https://github.com/tiagoft/flowfields.git
cd flowfields
uv run python demos/16-field_tree.py
Concepts
Scalar fields — flowfields.scalar_fields
A scalar field maps a 2-D point to a single float: f(x) → float. They are used as spatial weights inside composite vector fields.
| Class | Equation |
|---|---|
GaussianField(center, sigma, scale) |
f(x) = scale · exp(−‖x − center‖² / 2σ²) |
ConstantField(value) |
f(x) = value |
BoxField(min_corner, max_corner, inside_value, outside_value) |
inside_value if x is inside the box, else outside_value |
MatrixField(min_corner, max_corner, data, normalize) |
data, a 2-D array such as a grayscale image, stretched over the box with bilinear interpolation; 0 outside the box |
KernelProbabilisticMatrixField(min_corner, max_corner, data, normalize, sigma) |
exp(−‖x − c‖² / 2σ²) · m(x), where m is the MatrixField and c is the center of the box |
Vector fields — flowfields.vector_fields
A vector field maps a 2-D point to a 2-D vector: F(x) → np.ndarray. Most fields accept normalize=True (default) to return a unit vector.
Primitive fields
| Class | Equation |
|---|---|
RotationField(center, direction) |
v(x) = direction · [−rᵧ, rₓ] where r = x − center |
ExpansionField(center, direction) |
v(x) = direction · (x − center) |
NoiseField(distribution) |
v ~ Normal(0, 1)ⁿ by default, or v ~ Uniform(−1, 1)ⁿ with distribution="uniform" (fresh sample every call) |
Composite fields — combine other fields into a tree
| Class | Behaviour |
|---|---|
FieldSum(fields, weights) |
v(x) = Σᵢ wᵢ(x) · Fᵢ(x) — weighted linear blend |
FieldMax(fields, weights) |
v(x) = F_{argmax wᵢ(x)}(x) — hard winner-take-all |
FieldSelect(fields, weights, ...) |
probabilistic selection; switches fields over time with optional linear interpolation |
Weights can be a plain float, a ScalarField instance (position-dependent), or None (equal weights).
Color fields — flowfields.color_fields
A color field maps a 2-D point to an RGB color: C(x) → np.ndarray.
| Class | Behaviour |
|---|---|
MatrixColorField(min_corner, max_corner, data, n_colors, kernel_size, temperature, ...) |
reduces an image to a palette of n_colors, then draws color k with probability p_k(x) ∝ exp(z_k(x) / temperature), where z_k(x) is the fraction of color k in a window around x |
In the fields that read a matrix, the first row is at the top of the box (the highest y), so (0, 0) is at the bottom left of an image over a box from (0, 0). flowfields.utils.open_image loads an image file as a matrix.
Basic usage
import numpy as np
import flowfields.scalar_fields as sf
import flowfields.vector_fields as vf
field = vf.FieldSum(
fields=[
vf.RotationField(np.array([2.0, 0.0])),
vf.RotationField(np.array([-5.0, 0.0]), direction=-1),
vf.ExpansionField(np.array([2.0, -6.0])),
],
weights=[
sf.GaussianField(np.array([1.0, 0.0]), sigma=3.0),
sf.ConstantField(0.2),
sf.ConstantField(0.5),
],
)
x = np.array([1.0, 0.5])
v = field(x) # unit vector at point x
Swapping fields
Fields accept keyword arguments they do not use, so one field type can
replace another with a slightly different API. Each unused argument gives an
UnusedArgumentWarning, which also catches typos:
vf.RotationField(center, normalise=False)
# UnusedArgumentWarning: RotationField ignores the argument 'normalise' (did you mean 'normalize'?)
To swap fields on purpose without the warning:
import warnings
import flowfields
warnings.simplefilter("ignore", flowfields.UnusedArgumentWarning)
Gallery
Live on OpenProcessing
Moving Vortices Number 1 runs
flowfields.js in the browser: click the image to open it. Its code is
js/examples/vortices.html.
Genuary 2026
Pieces made with flowfields for Genuary 2026. Click an image to see its code.
All pieces are in artwork/genuary2026.
About
The library was built when I was studying art with flow fields using Python and NumPy. I eventually got annoyed by "guessing" functions for the vector fields, so I thought that having primitive fields (like expansions around a point, or rotations around a point) and ways to combine them (by adding them, applying spatial fades, and so on) would give me greater control of all of that.
I had been thinking about porting the library to p5.js for a while - and this is where agentic AI came in. The JS version is generated from the Python code (which I wrote by hand) by an AI agent, and tests check that both give the same numbers. It also helped me set up CI/CD, PyPi and npm packages, and organize my library of examples.
If you are doing creative coding or generative arts with flow fields, I hope this library is useful for you - if not by its code, maybe by its rationale. Enjoy!
License
flowfields is free software, released under the GNU Affero General Public License v3.0 or later. Images and other works you make with it are yours; programs that use or modify the library, including sketches served on the web, must be shared under the same license.
Metadata
Release files for flowfields 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flowfields-0.4.4.tar.gz | 43.2 kB | With provenance | Details for flowfields-0.4.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flowfields-0.4.4-py3-none-any.whl | Python 3 | none | any | Details for flowfields-0.4.4-py3-none-any.whl |
Total release size: 82.6 kB
Release files / flowfields-0.4.4.tar.gz
| Download URL | flowfields-0.4.4.tar.gz |
|---|---|
| Size | 43.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96a9ff5a17398da466b3b7ccebc85a16a0afc8333d1d560825db31e99f1ef87a
|
|
BLAKE2b-256 checksum How to use checksums |
3c778c67af99de08dda2847b82b66ae9169a2985abca19e8da519c78f65a4384
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / flowfields-0.4.4-py3-none-any.whl
| Download URL | flowfields-0.4.4-py3-none-any.whl |
|---|---|
| Size | 39.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fec23db9ef43bcd9a24dc80f9b21737162f3254a0ea1265784f446fb55b950b2
|
|
BLAKE2b-256 checksum How to use checksums |
1142bda478a370c4d16e3eac8a8e2fbfea68ebeb3fae4ed0f7c25f5c529ff51d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for flowfields 0.4.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for flowfields-0.4.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.