Color.Harmony
(Color v0.4.0)
Copy Markdown
Color harmony helpers — rotations and named combinations on the hue circle.
All helpers operate in Oklch by default, which gives visually
consistent rotations across the hue wheel. Pass :in to select a
different cylindrical space (Color.LCHab, Color.LCHuv,
Color.HSL, Color.HSV).
Every function accepts any color accepted by Color.new/1 and
returns a list of Color.SRGB structs, ordered starting with the
input color.
Summary
Functions
Returns the three-color analogous set ([-30°, 0, +30°]).
Returns the two-color complementary pair ([input, +180°]).
Rotates a color's hue by degrees.
Returns the three-color split-complementary set
([0, 180 − spread, 180 + spread]).
Returns the four-color tetradic set ([0, +90°, +180°, +270°]).
Returns the three-color triadic set ([0, +120°, +240°]).
Functions
@spec analogous( Color.input(), keyword() ) :: {:ok, [Color.SRGB.t()]} | {:error, Exception.t()}
Returns the three-color analogous set ([-30°, 0, +30°]).
Arguments
coloris any color accepted byColor.new/1.optionsis the same as forrotate_hue/3, plus:spread(degrees, default30).
Returns
{:ok, [%Color.SRGB{}, %Color.SRGB{}, %Color.SRGB{}]}ordered[anchor, anchor - spread, anchor + spread].
@spec complementary( Color.input(), keyword() ) :: {:ok, [Color.SRGB.t()]} | {:error, Exception.t()}
Returns the two-color complementary pair ([input, +180°]).
Arguments
coloris any color accepted byColor.new/1.optionsis the same as forrotate_hue/3.
Returns
{:ok, [%Color.SRGB{}, %Color.SRGB{}]}.
@spec rotate_hue(Color.input(), number(), keyword()) :: {:ok, Color.SRGB.t()} | {:error, Exception.t()}
Rotates a color's hue by degrees.
Arguments
coloris any color accepted byColor.new/1.degreesis the rotation in degrees. Positive is counter-clockwise on the hue wheel.optionsis a keyword list.
Options
:inis the cylindrical color space to rotate in. Defaults toColor.Oklch.
Returns
{:ok, %Color.SRGB{}}.
Examples
iex> {:ok, rotated} = Color.Harmony.rotate_hue("red", 120)
iex> hex = Color.SRGB.to_hex(rotated)
iex> String.starts_with?(hex, "#")
true
@spec split_complementary( Color.input(), keyword() ) :: {:ok, [Color.SRGB.t()]} | {:error, Exception.t()}
Returns the three-color split-complementary set
([0, 180 − spread, 180 + spread]).
Arguments
coloris any color accepted byColor.new/1.optionsis the same as forrotate_hue/3, plus:spread(degrees, default30).
Returns
{:ok, [%Color.SRGB{}, %Color.SRGB{}, %Color.SRGB{}]}.
@spec tetradic( Color.input(), keyword() ) :: {:ok, [Color.SRGB.t()]} | {:error, Exception.t()}
Returns the four-color tetradic set ([0, +90°, +180°, +270°]).
Arguments
coloris any color accepted byColor.new/1.optionsis the same as forrotate_hue/3.
Returns
{:ok, [%Color.SRGB{}, %Color.SRGB{}, %Color.SRGB{}, %Color.SRGB{}]}.
@spec triadic( Color.input(), keyword() ) :: {:ok, [Color.SRGB.t()]} | {:error, Exception.t()}
Returns the three-color triadic set ([0, +120°, +240°]).
Arguments
coloris any color accepted byColor.new/1.optionsis the same as forrotate_hue/3.
Returns
{:ok, [%Color.SRGB{}, %Color.SRGB{}, %Color.SRGB{}]}.