gapoly
gapoly = GA + polygons (distribution carmelolg-gapoly, import carmelolg.gapoly, command gapoly).
Genetic algorithm that evolves semi-transparent polygons until, stacked, they look like a target photo.
Built on GALib (carmelolg.galib, on PyPI as carmelolg-galib).
- Genome: float32 array, one row per polygon (3-6 vertices in [0,1] coordinates, RGBA), drawn in row order.
- Fitness: pixel MSE between render and target (lower is better,
maximize = False). - Mutation: move a vertex, shift a polygon, change colour/alpha, add / remove a polygon, change overlap order.
- Crossover: swap tails of the two polygon lists.
Genome layout
A genome is a float32 array, one row per polygon, drawn in row order (later rows on top). Values are in [0, 1]; coordinates are fractions of the image side.
column: 0 | 1 2 | 3 4 | ... | 11 12 | 13 14 15 16
meaning: n | x0 y0 x1 y1 ... x5 y5 | r g b a
n is the number of vertices used (3-6), the rest are ignored. Do not index rows with bare numbers: use the names
in shapes.py (N_VERTICES, X(v), Y(v), RED..ALPHA, vertices, color, make_row).
describe(genome) prints a genome as text, one line per polygon. The numba kernel (fast_render.py) reads the
same layout; test_row_layout_is_the_documented_one fails if the columns change.
Setup
pip install carmelolg-gapoly # from PyPI
pip install "carmelolg-gapoly[live]" # plus the live matplotlib window
From a clone (development):
python -m venv .venv && source .venv/bin/activate
pip install -e ".[live,dev]"
Run
python -m carmelolg.gapoly photo.jpg --generations 5000 --live # live window
python -m carmelolg.gapoly photo.jpg --snapshot-every 1 --generations 300 # one PNG per generation
Output in out/<name>/: snapshots/gen_*.png, final.png, evolution.gif, history.csv.
Polygons shrink coarse-to-fine: from --start-size (0.5) to --max-size (0.12, fraction of image side) over the first 70% of the run.
The live window lays out its panels by photo orientation: stacked for landscape, side by side for portrait/square.
Rendering and error are one compiled Numba loop (fast_render.py, releases the GIL). Fitness runs in parallel with GALib workers=: --workers N (default all CPUs), --parallel thread|process (default thread).
Useful options: --polygons, --population, --mutation-rate, --size (working resolution: smaller = faster), --seed.
Tests
python -m pytest
Ideas not done yet
More shape types, region weights (face counts more), SSIM fitness, greedy hill-climbing baseline.
Metadata
Release files for carmelolg-gapoly 0.1.0
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 |
|---|---|---|---|---|
| carmelolg_gapoly-0.1.0.tar.gz | 18.0 kB | With provenance | Details for carmelolg_gapoly-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| carmelolg_gapoly-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for carmelolg_gapoly-0.1.0-py3-none-any.whl |
Total release size: 35.2 kB
Release files / carmelolg_gapoly-0.1.0.tar.gz
| Download URL | carmelolg_gapoly-0.1.0.tar.gz |
|---|---|
| Size | 18.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
927cbfa7638a0b1cd684e119a32620d14df894fc7699f99aef452f09cc4e6818
|
|
BLAKE2b-256 checksum How to use checksums |
5199cfbadcc7096c7dd55fb8be26a6d8fd0be6895fa476a62400e045cdd813b9
|
| 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 18, 2026.
Transparency logRelease files / carmelolg_gapoly-0.1.0-py3-none-any.whl
| Download URL | carmelolg_gapoly-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca34eacf7ba61bffc3ce727985d84dcf676da88dfcd76ab1a20c33dee6b97376
|
|
BLAKE2b-256 checksum How to use checksums |
99af52962b30160507d09884cbaab8ed3842ab974c449f7be42905525bcfd960
|
| 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 18, 2026.
Transparency logSecurity for carmelolg-gapoly 0.1.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.
Attestation for carmelolg_gapoly-0.1.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 18, 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.