BuckleScript bindings for davidmerfield/randomColor (library for generating attractive random colors). This implementation gives couple functions:
randomColor()
randomColorMultiple()
randomColorHslArray()
(int, int, int)
).randomColorRgbArray()
(int, float, float)
).yarn add bs-randomcolor
Then add bs-randomcolor
as a dependency to bsconfig.json
:
"bs-dependencies": [
+ "bs-randomcolor"
]
hue
Controls the hue of the generated color. Possible values:
HueRed
HueOrange
HueYellow
HueGreen
HueBlue
HuePurple
HuePink
HueMonochrome
hueHex
Hexadecimal value of any color which will be used instead of "hue" option. The randomColor will extract its hue value and use that to generate colors.
luminosity
Controls the luminosity of the generated color. Possible values:
LuminosityBright
(default)LuminosityLight
LuminosityDark
count
An integer which specifies the number of colors to generate.
Notice: option available only for randomColorMultiple()
.
seed
An integer or string which when passed will cause randomColor to return the same color each time.
format
Specifies the format of the generated color. Possible values:
FormatHex
(default)FormatRgb
FormatRgba
FormatHsl
FormatHsla
FormatRgbArray
(available only for randomColorRgbArray()
)FormatHslArray
(available only for randomColorHslArray()
)alpha
A decimal between 0 and 1. Only relevant when using a format with an alpha channel (FormatRgba
and FormatHsla
). Defaults to a random value.
open RandomColorRe;
randomColor(); // "#f9a05c"
randomColor(~seed="test", ~format=FormatRgb, ()); // "rgb(249, 160, 92)"
randomColor(~seed="test", ~format=FormatRgba, ~alpha=0.2, ()) // "rgba(249, 160, 92, 0.2)"
randomColor(~seed="test", ~hue=HuePurple, ~luminosity=LuminosityDark, ()) // "#070707"
randomColorMultiple(~seed="test123", ~count=3, ()) // [|"#b6f453", "#4cdbb2", "#f9d759"|]
randomColorMultiple(~seed="test123", ~count=3, ()) // [|"#b6f453", "#4cdbb2", "#f9d759"|]
randomColorRgbArray(~seed="test", ~hue=HueRed, ()) // (137, 4, 44)
randomColorHslArray(~seed="test", ()) // (71, 94.17, 23.69)
2553: <UNKNOWN SYNTAX ERROR>
More examples in tests :).