Question: Is there is any way (in JS) to create a random color code using just bright colors, or pastel colors?
I am building a simple website that gives a random quote when I click a button, and with that, the background color changes. The thing is that sometimes the background color is too dark and the font is black, and consequently the person can't read the quote.
I found this code to generate a random color. I tried to edit to get only the strings A
to F
, but no success:
'#'+((1<<24)*(Math.random()+1)|0).toString(16).substr(1)
hsl()
color and randomize just the Hue after finding optimal Saturation and Luminosity values jsfiddle.net/sva8ckpy'#'+((1<<24)*(Math.random()+1)|0xc0c0c0).toString(16).substr(1)
might do the trick -- it should constrain every component to being in the range 0xc0-0xff but I don't know javascript so really anything at all could happen. 0x808080 allows more variation, but it might be too much. If you need more flexibility then you'll want one of the more complete answers given by people who probably know javascript.