Skip to main content
colorscope

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

Harmony Score:
1.00

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[]
ParamTypeDefaultDescription
colorsreadonly QuantizedColor[]Source palette
sizenumber5Number 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 spread

extractAccentColor

Extract the most visually distinct non-dominant color.

function extractAccentColor(
  colors: readonly QuantizedColor[],
  minProportion?: number
): QuantizedColor | null
ParamTypeDefaultDescription
colorsreadonly QuantizedColor[]Palette (sorted by proportion descending)
minProportionnumber0.05Minimum 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 reds

harmonyScore

Score how harmonically related the colors in a palette are.

function harmonyScore(colors: readonly QuantizedColor[]): number

Tests 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