i saw a lot of Js example but none fit my needs:
I'd like to have a script to generate colros, but if I use the common solution
color = '#'+Math.floor(Math.random()*16777215).toString(16);
it generates pastel colors, where I'd like better more saturated colors...or more ambitious, how can i select the palette form which i pick the colors?
how can I "restrict" the randomness?
For fully saturated colours use the HSL colour space with H from 0-360, S at (or slightly below) 100% and L at 50%.
If you know the browser has CSS3 support you may be able to use that directly. Failing that, use an HSL to RGB algorithm (20ish lines of code) readily available via Google to convert into hex format.
The formulae for conversion from HSL to RGB are also on the Wikipedia page on HSL and are easily translated into Javascript (and most other languages too!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With