dither_band
Dithers the boundary between two adjacent palette ramp steps, adding an apparent extra shade to widen the transition between two colors in a pixel-art sprite.
Instructions
Dither the boundary between two adjacent ramp steps, widening the transition.
Dithering in pixel art is a limited-palette necessity rather than a style: it buys
an apparent extra shade between two you already have. It reads as dated when applied
globally, which is why this is scoped to one boundary rather than offered as a
filter over the whole sprite.
Args:
ramp: Colours darkest first.
from_step, to_step: 1-based indices into `ramp`, and they must be adjacent.
Dithering between distant steps produces visible noise, not a gradient.
**1-based, while `ramp` is a list the caller indexes from 0**, so the pair
that dithers `ramp[3]` against `ramp[4]` is `from_step=4, to_step=5`. The two
conventions usually sit a line apart:
shade_region_by_light(f, GOLD, base_color=GOLD[4], ...)
dither_band(f, GOLD, from_step=5, to_step=6, ...) # GOLD[4], GOLD[5]
Off by one still names an adjacent pair, so the call succeeds and dithers the
wrong boundary. The result reports `from_color` and `to_color` for that
reason: it is the only way to check the intent from the output.
pattern: "bayer4" (finest, the usual choice), "bayer2" (chunkier) or "checker"
(a hard 50/50 that suits a sharp material change).
width: How far the dithered zone reaches into each band, in pixels. This is what
widens the transition, which is the point of dithering: at width=1 only the
seam itself alternates, and every pattern collapses to the same result
because a one-pixel-deep band can only alternate.
tolerance: How close a pixel must be to one of the two colours to take part.
layer: Target layer (default: top layer).
frame: Target frame, 1-based.
Only pixels of the two named colours that border each other are touched, so the
rest of the sprite is untouched even where it uses the same ramp.
Returns `dithered_pixels`, and `from_color`/`to_color`, the two colours the steps
actually resolved to.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ramp | Yes | ||
| frame | No | Default: 1. | |
| layer | No | ||
| width | No | Default: 2. | |
| pattern | No | Default: "bayer4". | bayer4 |
| to_step | Yes | ||
| filename | Yes | ||
| from_step | Yes | ||
| tolerance | No | Default: 24.0. |