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)

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.

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

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.2.2
File Size Uploaded Provenance Actions
flowfields-0.2.2.tar.gz 37.0 kB With provenance Details for flowfields-0.2.2.tar.gz

Built distribution (wheel)

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

Total release size: 73.2 kB

Release files / flowfields-0.2.2.tar.gz

Download URL flowfields-0.2.2.tar.gz
Size 37.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6cbb8e11a5223857228e12c74c088a36a2a61b0e07d0528f322892ac8c0f975b
BLAKE2b-256 checksum
How to use checksums
d927f67142e9a7e7a225918c76fbf85bacb5f269f6e6f637225c03d874b2aaf9
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 21, 2026.

Transparency log

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

Download URL flowfields-0.2.2-py3-none-any.whl
Size 36.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8371a86ab6a5d62d1f3aaebc8d644b7395eaa2e5c725cce096aecb68c0cd69af
BLAKE2b-256 checksum
How to use checksums
da0e8d049a8eaa88d769fd6479e5c3cf4dac30a3b40d84c8f14f7137acd5ecf1
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 21, 2026.

Transparency log

Security for flowfields 0.2.2

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.2.2.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 21, 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