murex 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ # Beads - AI-Native Issue Tracking
2
+
3
+ Welcome to Beads! This repository uses **Beads** for issue tracking - a modern, AI-native tool designed to live directly in your codebase alongside your code.
4
+
5
+ ## What is Beads?
6
+
7
+ Beads is issue tracking that lives in your repo, making it perfect for AI coding agents and developers who want their issues close to their code. No web UI required - everything works through the CLI and integrates seamlessly with git.
8
+
9
+ **Learn more:** [github.com/steveyegge/beads](https://github.com/steveyegge/beads)
10
+
11
+ ## Quick Start
12
+
13
+ ### Essential Commands
14
+
15
+ ```bash
16
+ # Create new issues
17
+ bd create "Add user authentication"
18
+
19
+ # View all issues
20
+ bd list
21
+
22
+ # View issue details
23
+ bd show <issue-id>
24
+
25
+ # Update issue status
26
+ bd update <issue-id> --claim
27
+ bd update <issue-id> --status done
28
+
29
+ # Sync with Dolt remote
30
+ bd dolt push
31
+ ```
32
+
33
+ ### Working with Issues
34
+
35
+ Issues in Beads are:
36
+ - **Git-native**: Stored in Dolt database with version control and branching
37
+ - **AI-friendly**: CLI-first design works perfectly with AI coding agents
38
+ - **Branch-aware**: Issues can follow your branch workflow
39
+ - **Sync-ready**: Uses Dolt remotes for backup and team sharing
40
+
41
+ ## Why Beads?
42
+
43
+ ✨ **AI-Native Design**
44
+ - Built specifically for AI-assisted development workflows
45
+ - CLI-first interface works seamlessly with AI coding agents
46
+ - No context switching to web UIs
47
+
48
+ 🚀 **Developer Focused**
49
+ - Issues live in your repo, right next to your code
50
+ - Works offline, syncs when you push
51
+ - Fast, lightweight, and stays out of your way
52
+
53
+ 🔧 **Git Integration**
54
+ - Dolt-native sync via bd dolt push / bd dolt pull
55
+ - Branch-aware issue tracking
56
+ - Dolt-native three-way merge resolution
57
+
58
+ ## Get Started with Beads
59
+
60
+ Try Beads in your own projects:
61
+
62
+ ```bash
63
+ # Install Beads
64
+ curl -sSL https://raw.githubusercontent.com/steveyegge/beads/main/scripts/install.sh | bash
65
+
66
+ # Initialize in your repo
67
+ bd init
68
+
69
+ # Create your first issue
70
+ bd create "Try out Beads"
71
+ ```
72
+
73
+ ## Learn More
74
+
75
+ - **Documentation**: [github.com/steveyegge/beads/docs](https://github.com/steveyegge/beads/tree/main/docs)
76
+ - **Quick Start Guide**: Run `bd quickstart`
77
+ - **Examples**: [github.com/steveyegge/beads/examples](https://github.com/steveyegge/beads/tree/main/examples)
78
+
79
+ ---
80
+
81
+ *Beads: Issue tracking that moves at the speed of thought* ⚡
murex-0.1.1/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+
10
+ # Version file written at build time by hatch-vcs
11
+ murex/_version.py
12
+
13
+ # Test and coverage output
14
+ .coverage
15
+ coverage.xml
16
+ junit*.xml
17
+ htmlcov/
18
+
19
+ # Tools
20
+ .pytest_cache/
21
+ .mypy_cache/
22
+ .ruff_cache/
23
+ .tox/
24
+ .uv-cache/
25
+ node_modules/
26
+
27
+ # Editors / OS
28
+ .vscode/
29
+ .idea/
30
+ .DS_Store
31
+
32
+
33
+ # Beads / Dolt files (added by bd init)
34
+ .dolt/
35
+ *.db
36
+ .beads-credential-key
37
+ .beads/proxieddb/
38
+ *.gate.lock*
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
+ and the project adheres to [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.1] - 2026-11-12
10
+
11
+ The first release. There is no 0.1.0: an unrelated project that once had this
12
+ name on PyPI used that version number in 2017, and PyPI never lets a file name
13
+ be used twice.
14
+
15
+ ### Added
16
+
17
+ - The modules oilpaint and fusain share, taken from oilpaint as they are:
18
+ `spectral` (colour science and Kubelka-Munk mixing), `spline` (stroke paths
19
+ and profiles), `noise` (textures), `reference` (reference images), `png`
20
+ and `filters` (oilpaint's `_filters`, with public names).
21
+ - `Pigment`: oilpaint's `Paint` without what is particular to oil paint
22
+ (its body).
23
+
24
+ [Unreleased]: https://github.com/joce/murex/compare/v0.1.1...HEAD
25
+ [0.1.1]: https://github.com/joce/murex/releases/tag/v0.1.1
murex-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jocelyn Legault
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
murex-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.5
2
+ Name: murex
3
+ Version: 0.1.1
4
+ Summary: What simulations of artists' media share: pigments that mix like the real thing (spectral Kubelka-Munk), stroke paths, textures and reference images.
5
+ Project-URL: Homepage, https://github.com/joce/murex
6
+ Project-URL: Repository, https://github.com/joce/murex
7
+ Project-URL: Issues, https://github.com/joce/murex/issues
8
+ Project-URL: Changelog, https://github.com/joce/murex/blob/main/CHANGELOG.md
9
+ Author-email: Jocelyn Legault <jocelynlegault@gmail.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: color,color-mixing,generative-art,kubelka-munk,noise,pigment,spectral,spline
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: Python :: 3.15
24
+ Classifier: Topic :: Artistic Software
25
+ Classifier: Topic :: Multimedia :: Graphics
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: <4.0,>=3.11
28
+ Requires-Dist: numba>=0.57
29
+ Requires-Dist: numpy>=1.24
30
+ Provides-Extra: pil
31
+ Requires-Dist: pillow>=9.1; extra == 'pil'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # murex
35
+
36
+ [![CI](https://github.com/joce/murex/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/joce/murex/actions/workflows/ci.yml)
37
+ [![Coverage](https://codecov.io/gh/joce/murex/graph/badge.svg)](https://codecov.io/gh/joce/murex)
38
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
39
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
40
+ [![GitHub License](https://img.shields.io/github/license/joce/murex)](https://github.com/joce/murex/blob/main/LICENSE)
41
+
42
+ What simulations of artists' media share. The murex is the sea snail Tyrian
43
+ purple was made from; this is where [oilpaint](https://github.com/joce/oilpaint)
44
+ and [fusain](https://github.com/joce/fusain) get their colour.
45
+
46
+ - `Pigment` and `murex.spectral`: colours as pigments that mix like the real
47
+ thing (blue and yellow give green, not grey), using spectral Kubelka-Munk
48
+ theory over 24 bands.
49
+ - `Bezier`, `CatmullRom`, `Polyline`: stroke paths resampled by arc length,
50
+ and values that vary along a stroke.
51
+ - `murex.noise`: textures (paper, weaves, wood grain).
52
+ - `Reference`: a reference image, asked for its colour, direction and detail
53
+ at the scale of the tool in hand.
54
+ - `write_png` and `murex.filters`: output and small image filters.
55
+
56
+ ```python
57
+ from murex import Pigment, mix_colors
58
+
59
+ mix_colors(["#1b3fa0", "#f5d000"]) # a green
60
+ glaze = Pigment("#8e1b2c", opacity=0.3) # a transparent crimson
61
+ glaze.appearance(thickness=1.0, over="#f2c80f")
62
+ ```
63
+
64
+ ## Development
65
+
66
+ ```bash
67
+ uv sync --group dev --frozen # install the package and the development tools
68
+ uv run pytest # run the tests
69
+ make pre-push # what CI runs: tox, coverage, spelling
70
+ ```
71
+
72
+ ## License
73
+
74
+ [MIT](LICENSE)
murex-0.1.1/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # murex
2
+
3
+ [![CI](https://github.com/joce/murex/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/joce/murex/actions/workflows/ci.yml)
4
+ [![Coverage](https://codecov.io/gh/joce/murex/graph/badge.svg)](https://codecov.io/gh/joce/murex)
5
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
6
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
7
+ [![GitHub License](https://img.shields.io/github/license/joce/murex)](https://github.com/joce/murex/blob/main/LICENSE)
8
+
9
+ What simulations of artists' media share. The murex is the sea snail Tyrian
10
+ purple was made from; this is where [oilpaint](https://github.com/joce/oilpaint)
11
+ and [fusain](https://github.com/joce/fusain) get their colour.
12
+
13
+ - `Pigment` and `murex.spectral`: colours as pigments that mix like the real
14
+ thing (blue and yellow give green, not grey), using spectral Kubelka-Munk
15
+ theory over 24 bands.
16
+ - `Bezier`, `CatmullRom`, `Polyline`: stroke paths resampled by arc length,
17
+ and values that vary along a stroke.
18
+ - `murex.noise`: textures (paper, weaves, wood grain).
19
+ - `Reference`: a reference image, asked for its colour, direction and detail
20
+ at the scale of the tool in hand.
21
+ - `write_png` and `murex.filters`: output and small image filters.
22
+
23
+ ```python
24
+ from murex import Pigment, mix_colors
25
+
26
+ mix_colors(["#1b3fa0", "#f5d000"]) # a green
27
+ glaze = Pigment("#8e1b2c", opacity=0.3) # a transparent crimson
28
+ glaze.appearance(thickness=1.0, over="#f2c80f")
29
+ ```
30
+
31
+ ## Development
32
+
33
+ ```bash
34
+ uv sync --group dev --frozen # install the package and the development tools
35
+ uv run pytest # run the tests
36
+ make pre-push # what CI runs: tox, coverage, spelling
37
+ ```
38
+
39
+ ## License
40
+
41
+ [MIT](LICENSE)
@@ -0,0 +1,52 @@
1
+ # Releasing murex
2
+
3
+ murex publishes to [PyPI](https://pypi.org/project/murex/) from GitHub
4
+ Actions (`.github/workflows/publish.yml`) using **Trusted Publishing** (OIDC):
5
+ no API tokens. The workflow runs when a **GitHub Release is published**; a bare
6
+ `git push` of a tag does *not* trigger it.
7
+
8
+ ## One-time setup
9
+
10
+ 1. On PyPI, add a *pending* trusted publisher (Account → Publishing → Add a new
11
+ pending publisher, GitHub tab): project `murex`, owner `joce`, repository
12
+ `murex`, workflow `publish.yml`, environment `pypi`. The first release
13
+ then creates the project.
14
+ 2. On GitHub, create the `pypi` environment (Settings → Environments → New
15
+ environment) and add yourself as a required reviewer, so that every upload
16
+ waits for your approval.
17
+
18
+ ## Cutting a release
19
+
20
+ The version is derived from the git tag by `hatch-vcs`: there is **no manual
21
+ version bump**. `murex/__init__.py` reads it from `murex/_version.py`,
22
+ generated at build time. Tagging `vX.Y.Z` makes the build `X.Y.Z`; commits
23
+ after a tag get a `X.Y.(Z+1).devN` version automatically.
24
+
25
+ 1. Move the `## [Unreleased]` notes in `CHANGELOG.md` under a new
26
+ `## [X.Y.Z] - YYYY-MM-DD` heading and update the links at the bottom.
27
+ Commit and push to `main`. Wait for CI to go green.
28
+ 2. Create the release. This creates the `vX.Y.Z` tag *and* triggers publishing:
29
+
30
+ ```bash
31
+ gh release create vX.Y.Z --title "vX.Y.Z" --notes-file docs/release_vX.Y.Z.md
32
+ ```
33
+
34
+ Write real notes (overview and highlights), not a one-liner: draft them in
35
+ `docs/release_next.md` and move them to `docs/release_vX.Y.Z.md` in step 1.
36
+ 3. The `publish` job pauses on the `pypi` environment. **Approve the deployment**:
37
+ the run page shows *"Review pending deployments"* → tick `pypi` → *Approve and
38
+ deploy*. After approval it uploads to PyPI.
39
+ 4. Verify: <https://pypi.org/project/murex/> shows the new version.
40
+
41
+ ## Verify locally before releasing
42
+
43
+ ```bash
44
+ uv build
45
+ uvx twine check dist/*
46
+ uv run tox -e wheel
47
+ ```
48
+
49
+ The built filenames carry the version `hatch-vcs` derived from git
50
+ (`murex-X.Y.Z...`). A clean checkout *at* the tag yields exactly `X.Y.Z`; a
51
+ dirty tree or post-tag commit yields a `.devN`/`+g<sha>` suffix. The `wheel` env
52
+ installs the built wheel on its own and checks that it imports and mixes colours.
@@ -0,0 +1,32 @@
1
+ """murex: what simulations of artists' media share.
2
+
3
+ Colour as pigments that mix like the real thing (spectral Kubelka-Munk),
4
+ stroke paths, noise for textures, reference images and PNG output. Used by
5
+ ``oilpaint`` and ``fusain``.
6
+ """
7
+
8
+ from . import filters, noise, reference, spectral
9
+ from ._about import __version__
10
+ from .pigment import ColorLike, Pigment, as_pigment, mix_colors
11
+ from .png import write_png
12
+ from .reference import Reference
13
+ from .spline import Bezier, CatmullRom, Path, Polyline, Profile
14
+
15
+ __all__ = [
16
+ "Bezier",
17
+ "CatmullRom",
18
+ "ColorLike",
19
+ "Path",
20
+ "Pigment",
21
+ "Polyline",
22
+ "Profile",
23
+ "Reference",
24
+ "__version__",
25
+ "as_pigment",
26
+ "filters",
27
+ "mix_colors",
28
+ "noise",
29
+ "reference",
30
+ "spectral",
31
+ "write_png",
32
+ ]
@@ -0,0 +1,10 @@
1
+ """The package version: from the git tag (hatch-vcs), written to _version.py
2
+ when the package is built or installed (see pyproject.toml,
3
+ [tool.hatch.version])."""
4
+
5
+ try:
6
+ from ._version import __version__
7
+ except ImportError: # a source checkout that was never built or installed
8
+ __version__ = "0.0.0+unknown"
9
+
10
+ __all__ = ["__version__"]
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.1.1'
22
+ __version_tuple__ = version_tuple = (0, 1, 1)
23
+
24
+ __commit_id__ = commit_id = None
@@ -0,0 +1,81 @@
1
+ """Small image filters (numpy only)."""
2
+
3
+ import numpy as np
4
+
5
+
6
+ def box_blur(a: np.ndarray, r: int, axis: int | None = None) -> np.ndarray:
7
+ """Box blur of radius r, the edges repeating the border value: along
8
+ ``axis``, or (by default) along the first two axes in turn, in float64
9
+ from first to last. The result has ``a``'s type."""
10
+ if r <= 0:
11
+ return a
12
+ if axis is not None:
13
+ return _box_pass(a, r, axis).astype(a.dtype)
14
+ out = a.astype(np.float64)
15
+ for ax in (0, 1):
16
+ out = _box_pass(out, r, ax)
17
+ return out.astype(a.dtype)
18
+
19
+
20
+ def _box_pass(a: np.ndarray, r: int, axis: int) -> np.ndarray:
21
+ """One pass of :func:`box_blur` along ``axis`` (float64: running sums)."""
22
+ pad = [(0, 0)] * a.ndim
23
+ pad[axis] = (r + 1, r)
24
+ c = np.cumsum(np.pad(a, pad, mode="edge"), axis=axis, dtype=np.float64)
25
+ n = a.shape[axis]
26
+ hi = np.take(c, np.arange(2 * r + 1, 2 * r + 1 + n), axis=axis)
27
+ lo = np.take(c, np.arange(0, n), axis=axis)
28
+ return (hi - lo) / (2 * r + 1)
29
+
30
+
31
+ def max_filter(a: np.ndarray, r: int) -> np.ndarray:
32
+ """Maximum over a (2r+1)-square neighbourhood (separable, edges clamped)."""
33
+ out = a.astype(np.float32)
34
+ for axis in (0, 1):
35
+ n = out.shape[axis]
36
+ pad = [(0, 0), (0, 0)]
37
+ pad[axis] = (r, r)
38
+ p = np.pad(out, pad, mode="edge")
39
+ res = np.take(p, np.arange(0, n), axis=axis)
40
+ for k in range(1, 2 * r + 1):
41
+ np.maximum(res, np.take(p, np.arange(k, k + n), axis=axis), out=res)
42
+ out = res
43
+ return out
44
+
45
+
46
+ def smooth121(a: np.ndarray) -> np.ndarray:
47
+ """Light [1, 2, 1] smoothing in both directions (softens pixel steps, keeps
48
+ fine grooves)."""
49
+ out = a.astype(np.float32)
50
+ for axis in (0, 1):
51
+ p = np.pad(
52
+ out, [(1, 1) if k == axis else (0, 0) for k in range(2)], mode="edge"
53
+ )
54
+ n = out.shape[axis]
55
+ out = (
56
+ 0.25 * np.take(p, np.arange(0, n), axis=axis)
57
+ + 0.5 * out
58
+ + 0.25 * np.take(p, np.arange(2, n + 2), axis=axis)
59
+ )
60
+ return out
61
+
62
+
63
+ def smoothstep(e0, e1, x):
64
+ """0 below ``e0``, 1 beyond ``e1`` (either way round), and a smooth S
65
+ between them."""
66
+ t = np.clip((x - e0) / (e1 - e0), 0.0, 1.0)
67
+ return t * t * (3.0 - 2.0 * t)
68
+
69
+
70
+ def bilinear(grid: np.ndarray, y, x):
71
+ """Sample ``grid`` (H, W, ...) at the fractional indices ``y`` and ``x``
72
+ (arrays, 0..H-1 and 0..W-1), linearly between the four cells around
73
+ each point."""
74
+ H, W = grid.shape[:2]
75
+ y0, x0 = np.minimum(y.astype(int), H - 2), np.minimum(x.astype(int), W - 2)
76
+ fy, fx = y - y0, x - x0
77
+ if grid.ndim == 3:
78
+ fx, fy = fx[..., None], fy[..., None]
79
+ return (grid[y0, x0] * (1 - fx) + grid[y0, x0 + 1] * fx) * (1 - fy) + (
80
+ grid[y0 + 1, x0] * (1 - fx) + grid[y0 + 1, x0 + 1] * fx
81
+ ) * fy
@@ -0,0 +1,169 @@
1
+ """Small procedural noise helpers (numpy only)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import numpy as np
6
+
7
+
8
+ def _smooth(t):
9
+ return t * t * (3.0 - 2.0 * t)
10
+
11
+
12
+ def value_noise_2d(h: int, w: int, cell: float, rng: np.random.Generator) -> np.ndarray:
13
+ """Smooth value noise in [0, 1] with features about ``cell`` pixels wide."""
14
+ gh, gw = int(h / cell) + 3, int(w / cell) + 3
15
+ grid = rng.random((gh, gw))
16
+ y = np.arange(h) / cell
17
+ x = np.arange(w) / cell
18
+ yi, xi = y.astype(int), x.astype(int)
19
+ fy, fx = _smooth(y - yi)[:, None], _smooth(x - xi)[None, :]
20
+ g00 = grid[yi][:, xi]
21
+ g01 = grid[yi][:, xi + 1]
22
+ g10 = grid[yi + 1][:, xi]
23
+ g11 = grid[yi + 1][:, xi + 1]
24
+ top = g00 + (g01 - g00) * fx
25
+ bot = g10 + (g11 - g10) * fx
26
+ return top + (bot - top) * fy
27
+
28
+
29
+ def fractal_noise_2d(h, w, cell, rng, octaves=4, gain=0.5) -> np.ndarray:
30
+ out = np.zeros((h, w))
31
+ amp, total = 1.0, 0.0
32
+ for _ in range(octaves):
33
+ out += amp * value_noise_2d(h, w, max(cell, 1.0), rng)
34
+ total += amp
35
+ amp *= gain
36
+ cell /= 2.0
37
+ return out / total
38
+
39
+
40
+ def value_noise_1d(n: int, cell: float, rng: np.random.Generator) -> np.ndarray:
41
+ grid = rng.random(int(n / cell) + 3)
42
+ x = np.arange(n) / cell
43
+ xi = x.astype(int)
44
+ f = _smooth(x - xi)
45
+ return grid[xi] + (grid[xi + 1] - grid[xi]) * f
46
+
47
+
48
+ def canvas_weave(h: int, w: int, period: float, rng: np.random.Generator) -> np.ndarray:
49
+ """Height field in [0, 1] resembling primed plain-weave canvas."""
50
+ y, x = np.mgrid[0:h, 0:w].astype(np.float64)
51
+ jitter = fractal_noise_2d(h, w, period * 6, rng, octaves=2) - 0.5
52
+ xs = x + jitter * period * 0.6
53
+ ys = y - jitter * period * 0.6
54
+ cell_x = np.floor(xs / period)
55
+ cell_y = np.floor(ys / period)
56
+ fx = np.sin(np.pi * xs / period) ** 2
57
+ fy = np.sin(np.pi * ys / period) ** 2
58
+ over = ((cell_x + cell_y) % 2) == 0
59
+ weave = np.where(over, fx * (0.6 + 0.4 * fy), fy * (0.6 + 0.4 * fx))
60
+ grain = fractal_noise_2d(h, w, period * 1.5, rng, octaves=3)
61
+ out = 0.75 * weave + 0.25 * grain
62
+ out -= out.min()
63
+ return out / max(out.max(), 1e-9)
64
+
65
+
66
+ # ---------------------------------------------------------------------------
67
+ # Surface textures (height fields in 0..1)
68
+ # ---------------------------------------------------------------------------
69
+
70
+
71
+ def lattice_noise(U, V, rng: np.random.Generator) -> np.ndarray:
72
+ """Smooth value noise evaluated at arbitrary lattice coordinates (U, V)."""
73
+ U = U - U.min()
74
+ V = V - V.min()
75
+ grid = rng.random((int(U.max()) + 3, int(V.max()) + 3))
76
+ iu, iv = U.astype(int), V.astype(int)
77
+ fu, fv = _smooth(U - iu), _smooth(V - iv)
78
+ g00, g01 = grid[iu, iv], grid[iu, iv + 1]
79
+ g10, g11 = grid[iu + 1, iv], grid[iu + 1, iv + 1]
80
+ a = g00 + (g01 - g00) * fv
81
+ b = g10 + (g11 - g10) * fv
82
+ return a + (b - a) * fu
83
+
84
+
85
+ def aniso_noise(h, w, along, across, angle_deg, rng, octaves=2) -> np.ndarray:
86
+ """Noise stretched along a direction: features ``along`` px long and
87
+ ``across`` px wide, oriented ``angle_deg`` from horizontal."""
88
+ y, x = np.mgrid[0:h, 0:w].astype(np.float64)
89
+ a = np.radians(angle_deg)
90
+ u = x * np.cos(a) + y * np.sin(a)
91
+ v = -x * np.sin(a) + y * np.cos(a)
92
+ out = np.zeros((h, w))
93
+ amp, total = 1.0, 0.0
94
+ for _ in range(octaves):
95
+ out += amp * lattice_noise(u / max(along, 1.0), v / max(across, 0.5), rng)
96
+ total += amp
97
+ amp *= 0.5
98
+ along /= 2.0
99
+ across /= 2.0
100
+ return out / total
101
+
102
+
103
+ def _normalize(a: np.ndarray) -> np.ndarray:
104
+ lo, hi = np.percentile(a, [0.5, 99.5])
105
+ return np.clip((a - lo) / max(hi - lo, 1e-9), 0.0, 1.0)
106
+
107
+
108
+ def woven(h, w, period, rng, irregularity=0.3, twill=False) -> np.ndarray:
109
+ """Woven cloth: threads going over and under each other.
110
+
111
+ ``irregularity`` 0 gives machine-even cotton; higher values give linen,
112
+ with wandering threads of uneven thickness and slubs (thick spots).
113
+ """
114
+ y, x = np.mgrid[0:h, 0:w].astype(np.float64)
115
+ wander = 0.2 + 0.8 * irregularity
116
+ x = x + (fractal_noise_2d(h, w, period * 7, rng, octaves=2) - 0.5) * period * wander
117
+ y = y + (fractal_noise_2d(h, w, period * 7, rng, octaves=2) - 0.5) * period * wander
118
+ gx, gy = x / period, y / period
119
+ i, j = np.floor(gx), np.floor(gy)
120
+ fx, fy = gx - i, gy - j
121
+ nx, ny = int(w / period) + 8, int(h / period) + 8
122
+ # thread-to-thread thickness
123
+ warp_t = 1.0 + 0.7 * irregularity * (rng.random(nx) - 0.5) * 2
124
+ weft_t = 1.0 + 0.7 * irregularity * (rng.random(ny) - 0.5) * 2
125
+ tw = warp_t[np.clip(i.astype(int) + 4, 0, nx - 1)]
126
+ tf = weft_t[np.clip(j.astype(int) + 4, 0, ny - 1)]
127
+ sec_x = np.sin(np.pi * fx) ** (0.9 / tw) # rounded thread cross-sections
128
+ sec_y = np.sin(np.pi * fy) ** (0.9 / tf)
129
+ over = (((i - j) % 4) < 2) if twill else (((i + j) % 2) == 0)
130
+ cloth = np.where(
131
+ over, sec_x * tw * (0.55 + 0.45 * sec_y), sec_y * tf * (0.55 + 0.45 * sec_x)
132
+ )
133
+ slubs = (
134
+ aniso_noise(h, w, period * 6, period * 0.9, 90, rng) * 0.5
135
+ + aniso_noise(h, w, period * 6, period * 0.9, 0, rng) * 0.5
136
+ )
137
+ cloth = cloth * (1.0 + 1.2 * irregularity * (slubs - 0.5))
138
+ fibre = fractal_noise_2d(h, w, max(period * 0.6, 1.5), rng, octaves=2)
139
+ return _normalize(0.85 * cloth + 0.15 * fibre)
140
+
141
+
142
+ def paper(h, w, scale, rng) -> np.ndarray:
143
+ """Paper tooth: fine felted fibres."""
144
+ fibres = sum(
145
+ aniso_noise(h, w, scale * 5, scale * 0.6, a, rng, octaves=2)
146
+ for a in (15, 75, 125)
147
+ )
148
+ tooth = fractal_noise_2d(h, w, scale * 1.5, rng, octaves=3)
149
+ return _normalize(0.5 * fibres / 3 + 0.5 * tooth)
150
+
151
+
152
+ def wood(h, w, scale, angle, rng) -> np.ndarray:
153
+ """Wood grain: wavy growth rings and fine fibres along the grain."""
154
+ y, x = np.mgrid[0:h, 0:w].astype(np.float64)
155
+ a = np.radians(angle)
156
+ v = -x * np.sin(a) + y * np.cos(a)
157
+ warp = aniso_noise(h, w, scale * 25, scale * 4, angle, rng)
158
+ rings = 0.5 + 0.5 * np.sin(2 * np.pi * (v / scale + 2.5 * warp))
159
+ rings = rings**3 # narrow dark latewood bands
160
+ fibres = aniso_noise(h, w, scale * 4, 1.2, angle, rng, octaves=2)
161
+ return _normalize(0.6 * rings + 0.4 * fibres)
162
+
163
+
164
+ def brushmarks(h, w, angle, rng) -> np.ndarray:
165
+ """Ridges left by the brush that applied the priming: fine parallel
166
+ striations in broad bands of varying strength."""
167
+ fine = aniso_noise(h, w, 90, 1.8, angle, rng, octaves=2)
168
+ bands = aniso_noise(h, w, 260, 40, angle, rng, octaves=1)
169
+ return _normalize(fine * (0.35 + bands))