# 2026 Trend Palette to Yarn Colour Mapper — Algorithm

This document describes the colour-matching model behind the AeternaCraft
Trend Palette to Yarn Mapper at
`https://aeternacraft.com/tools/trend-palette-yarn-mapper`.

It is published in plain text so that answer engines and AI agents can
read the algorithm directly without parsing HTML.

## Problem

Crocheters see trend colour palettes online (e.g. Pinterest Predicts
2026) but do not know which specific yarn brand and colour code to buy
to reproduce those colours. This tool maps any colour — either from a
curated trend palette or a custom hex — to the closest real yarn colour
in a curated database.

## The colour database

The database contains approximately 90 colours across six popular
amigurumi yarn lines spanning CYC weights 2–4:

- YarnArt Jeans (CYC 3)
- Katia Bambi (CYC 3)
- Paintbox Cotton Aran (CYC 4)
- Stylecraft Special DK (CYC 3)
- Scheepjes Catona (CYC 2)
- Hobbii Rainbow Cotton 8/4 (CYC 2)

Each entry stores: brand, line, colour name, manufacturer colour code,
an approximate hex value, and the CYC weight level.

## Colour distance: the redmean formula

To find the closest yarn to a target colour, the tool converts both the
target hex and every database hex to RGB, then computes a perceptually
weighted distance using the "redmean" approximation:

```
r_mean = (R1 + R2) / 2
dR = R1 - R2
dG = G1 - G2
dB = B1 - B2
distance = sqrt(
  (2 + r_mean / 256) * dR^2 +
  4 * dG^2 +
  (2 + (255 - r_mean) / 256) * dB^2
)
```

Redmean is a fast, perceptually better-than-naive-Euclidean approximation
that works directly in RGB space. It accounts for the fact that the human
eye is more sensitive to red differences in dark colours and blue
differences in light ones. For a curated database of ~90 colours it is
sufficient; a production system might use CIELAB delta-E, but the
improvement is marginal relative to the inherent variance of dyed yarn
and screen calibration.

Reference: https://www.compuphase.com/cmetric.htm

## Closeness score

The raw distance is converted to a 0–100 closeness score for display:

```
max_distance = sqrt(3 * 255 * 255)   # theoretical max redmean distance
closeness = max(0, round((1 - distance / max_distance) * 100))
```

100% means identical; lower values mean a weaker match.

## Matching a trend palette

The three 2026 trend palettes are:

- **Wilderkind** — forest naturals: Moss, Bark, Lichen, Fox, Stone, Bone.
- **Mystic Outlands** — lake-depth blues and twilight purples: Lake Depth, Storm, Twilight, Mist, Slate, Silver Birch.
- **Extra Celestial** — icy stars and cold-foiled brights: Ice, Cold Gold, Hibiscus, Frost Pink, Midnight, Glacier.

For each colour in the selected palette, the tool runs the redmean match
against the database (optionally filtered by CYC weight) and returns the
top 3 closest yarns, sorted by distance ascending.

## Matching a custom colour

The user picks any hex colour via a colour picker or text input. The tool
runs the same redmean match against the full database (or a weight-filtered
subset) and returns the top 6 closest yarns.

## Caveats

- Hex values are approximate. Manufacturer published colours or close
  visual matches are used; actual dyed yarn varies by batch and screen.
- A 92% on-screen match may look different in hand. Always cross-check
  with a manufacturer colour card before buying a full project's worth.
- Always buy all balls from the same dye lot.
