A port of https://github.com/zenozeng/color-hash
hash a string into a colour hex string. set hue, lighting and saturation to keep colours matching.
iex> ColourHash.hex("test")
"A46CE0"
iex> ColourHash.hex("test", lightness: [0.1], saturation: [0.1, 0.9], hue_range: %{min: 30, max: 30} )
"1C1A17"
iex> ColourHash.rgb("test")
{164, 108, 224}
iex> ColourHash.rgb("test", lightness: [0.1], saturation: [0.3, 0.9], hue_range: %{min: 50, max: 330} )
{23, 18, 33}
iex> ColourHash.hsl("test")
{268.88583218707015, 0.65, 0.65}
iex> ColourHash.hsl("test", lightness: [0.1], saturation: [0.3, 0.9], hue_range: %{min: 150, max: 330} )
{284.4429160935351, 0.3, 0.1}
If available in Hex, the package can be installed
by adding colour_hash
to your list of dependencies in mix.exs
:
def deps do
[
{:colour_hash, "~> 1.0.3"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/colour_hash.