Skip to content

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 ​

complementtriadtetradsplitComplementanalogousmonochromaticSame hue, varied L= base color (red H=0°)Position on ring = hue angleDashed line = relationship

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.

ParameterTypeDefaultDescription
resultsnumber6Number of colors to return
slicesnumber30Number of wheel divisions

Returns: XColor[]

ts
xcolor('#ff0000').analogous().map(c => c.toHex())
// 6 colors near red

monochromatic(results?) ​

Monochromatic scheme — same hue, varying lightness.

ParameterTypeDefaultDescription
resultsnumber6Number of colors to return

Returns: XColor[]

ts
xcolor('#ff0000').monochromatic().map(c => c.toHex())
// 6 shades of red from dark to light

Released under the MIT License.