harmony - Color Schemes
Generate classic color schemes based on color theory. Except for complement(), which returns a single XColor, all methods return arrays of XColor instances.
Install
ts
import xcolor from '@xpyjs/color'
import harmonyPlugin from '@xpyjs/color/plugins/harmony'
xcolor.use(harmonyPlugin)Methods
complement()
The complementary color — the color 180° from the original on the color wheel.
Returns: XColor (the complement, original excluded)
ts
xcolor('#ff0000').complement().toHex()
// '#00ffff'triad()
Triadic scheme — three colors 120° apart on the color wheel.
Returns: XColor[] (3 colors)
ts
xcolor('#ff0000').triad().map(c => c.toHex())
// ['#ff0000', '#00ff00', '#0000ff']tetrad()
Tetradic scheme — four colors 90° apart on the color wheel.
Returns: XColor[] (4 colors)
ts
xcolor('#ff0000').tetrad().map(c => c.toHex())
// ['#ff0000', '#80ff00', '#00ffff', '#8000ff']splitComplement()
Split-complementary — the original color plus two colors 30° to each side of the complement.
Returns: XColor[] (3 colors)
ts
xcolor('#ff0000').splitComplement().map(c => c.toHex())
// ['#ff0000', '#00ff80', '#0080ff']analogous(results?, slices?)
Analogous colors — adjacent colors on the color wheel.
| Parameter | Type | Default | Description |
|---|---|---|---|
results | number | 6 | Number of colors to return |
slices | number | 30 | Number of wheel divisions |
Returns: XColor[]
ts
xcolor('#ff0000').analogous().map(c => c.toHex())
// 6 colors near redmonochromatic(results?)
Monochromatic scheme — same hue, varying lightness.
| Parameter | Type | Default | Description |
|---|---|---|---|
results | number | 6 | Number of colors to return |
Returns: XColor[]
ts
xcolor('#ff0000').monochromatic().map(c => c.toHex())
// 6 shades of red from dark to light