Fooidge / PleaseJS

JavaScript Library for creating random pleasing colors and color schemes
2.28k stars 159 forks source link

Not too bright / not too dark colors #12

Open ocombe opened 10 years ago

ocombe commented 10 years ago

I'd like to be able to define a max brightness or darkness for the color generation. If I want to put text over it, I want it to be easy to read, with a white or dark font.

I've implemented something like that using YIQ:

var yiq = ((rgb.r*299)+(rgb.g*587)+(rgb.b*114))/1000;
return (yiq >= 128) ? 'black' : 'white';

In this case I test the color generated to adapt the font color, but it would be better if I could generate only colors that are suitable for a dark font, or for a white font.

Another great article about it: http://24ways.org/2010/calculating-color-contrast/

Fooidge commented 10 years ago

I actually already have something like this in the works :) check branch for contrast. Going to add levels to color generation as well.

Jordan Checkman

On Jul 15, 2014, at 10:42 AM, Olivier Combe notifications@github.com wrote:

I'd like to be able to define a max brightness or darkness for the color generation. If I want to put text over it, I want it to be easy to read, with a white or dark font.

I've implemented something like that using YIQ:

var yiq = ((rgb.r_299)+(rgb.g_587)+(rgb.b*114))/1000; return (yiq >= 128) ? 'black' : 'white'; In this case I test the color generated to adapt the font color, but it would be better if I could generate only colors that are suitable for a dark font, or for a white font.

— Reply to this email directly or view it on GitHub.

ocombe commented 10 years ago

Damn you're good, working on features before we ask them ! I'll wait for it then.

Fooidge commented 10 years ago

Oops accidentally closed.

Madd0g commented 10 years ago

I really hope schemes will support this. I wanted to use schemes as a background color generator, but every scheme variation of my very bright blue is dark and makes it impossible to put anything over it.

Fooidge commented 10 years ago

That doesn't make sense, many of the schemes don't change the value of the resulting colors. They should be roughly as light as your blue.

Jordan Checkman

On Sep 25, 2014, at 4:10 AM, Madd0g notifications@github.com wrote:

I really hope schemes will support this. I wanted to use schemes as a background color generator, but every scheme variation of my very bright blue is dark and makes it impossible to put anything over it.

— Reply to this email directly or view it on GitHub.

Madd0g commented 10 years ago

@Fooidge - So sorry, you are correct, I was using the wrong starting color, I had the correct color in the css, but the wrong one in the variable, I was surprised at how different the demos and my own tests looked :)