Palette Generation
Distill a complex extraction into a curated palette. Find the accent color. Score how harmonious the result is.
Source: 12 colors
Generated Palette
#2d1a06
#c9b39c
accent
#734d26
#93806c
#121621
Accent: #c9b39c
Most visually distinct non-dominant color (8% of palette)
import { generatePalette, extractAccentColor, harmonyScore } from "colorscope/analysis";Functions
generatePalette
Generate a curated subset of maximally-distinct colors.
function generatePalette(
colors: readonly QuantizedColor[],
size?: number
): QuantizedColor[]| Param | Type | Default | Description |
|---|---|---|---|
colors | readonly QuantizedColor[] | — | Source palette |
size | number | 5 | Number of colors to select |
Uses a greedy furthest-point algorithm in OKLab space: starts with the highest-proportion color, then iteratively adds the color most distant from all already-selected colors.
const palette = generatePalette(kilimPalette, 5);
// 5 colors with maximum perceptual spreadextractAccentColor
Extract the most visually distinct non-dominant color.
function extractAccentColor(
colors: readonly QuantizedColor[],
minProportion?: number
): QuantizedColor | null| Param | Type | Default | Description |
|---|---|---|---|
colors | readonly QuantizedColor[] | — | Palette (sorted by proportion descending) |
minProportion | number | 0.05 | Minimum proportion to consider |
Returns: The accent color, or null if no suitable accent exists. Skips tiny slivers that are likely artifacts.
const accent = extractAccentColor(kilimPalette);
// → The forest green that contrasts the dominant redsharmonyScore
Score how harmonically related the colors in a palette are.
function harmonyScore(colors: readonly QuantizedColor[]): numberTests each pair of chromatic colors against known harmonic relationships (complementary, analogous, triadic, etc.) in OKLCH hue space. Tolerance is ±15°.
Returns: 0-1 score. 1 = all pairs are harmonically related.
harmonyScore(kilimPalette); // 0.73 — near-triadic distribution