Skip to main content

flowfields

tests coverage

An image of the Eiffel tower drawn with colored lines that follow a tree of fields

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.2.0/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

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).


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)

Live on OpenProcessing

Moving Vortices Number 1: particles glowing through four moving vortices

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.

Genuary 03 Genuary 08 Genuary 12
Genuary 16 Genuary 19 Genuary 25

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.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flowfields 0.3.0
File Size Uploaded Provenance Actions
flowfields-0.3.0.tar.gz 39.7 kB With provenance Details for flowfields-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flowfields 0.3.0
File Interpreter ABI Platform Actions
flowfields-0.3.0-py3-none-any.whl Python 3 none any Details for flowfields-0.3.0-py3-none-any.whl

Total release size: 77.2 kB

Release files / flowfields-0.3.0.tar.gz

Download URL flowfields-0.3.0.tar.gz
Size 39.7 kB
Tags Source
SHA-256 checksum
How to use checksums
48034be212690c1d02a78241abee204dc28682e3a503a34cb8f4327accf193b8
BLAKE2b-256 checksum
How to use checksums
c15ecc660103c9d5fd4a6d490533ca9970a3a95b9935846161a8550c89b5a174
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 29, 2026.

Transparency log

Release files / flowfields-0.3.0-py3-none-any.whl

Download URL flowfields-0.3.0-py3-none-any.whl
Size 37.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cb92f4fdc93b6846a5808d66808a546115b0278c76cdf1195d62bab8a5ed1e8
BLAKE2b-256 checksum
How to use checksums
602b56fbe758d43f07b07dc56c4c8da8b7d4e9f91b5b435d7cfe1c8f4c570dc3
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 29, 2026.

Transparency log

Security for flowfields 0.3.0

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.

Select from 2 files

Attestation for flowfields-0.3.0.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 29, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page