Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximize color difference #50

Closed
jareware opened this issue Oct 12, 2015 · 11 comments · May be fixed by vishalkdotcom/Ghost-Desktop#3 or scrambledeggs/react-native-atoz-list#3
Closed

Maximize color difference #50

jareware opened this issue Oct 12, 2015 · 11 comments · May be fixed by vishalkdotcom/Ghost-Desktop#3 or scrambledeggs/react-native-atoz-list#3

Comments

@jareware
Copy link

This looks exactly like a lib that I'd soon need!

I see there's an option for providing a seed for having deterministic results, but is there any way of specifying "I want 5 colors (with these settings) that are as different from each other as possible"? So that if I ask for 3 colors, I won't get 3 different shades of red.

@davidmerfield
Copy link
Owner

No, not yet. This is number 1 on the to-do list. I'd be happy to hear your ideas!

@jareware
Copy link
Author

jareware commented Nov 4, 2015

Hmm, this might take a bit more understanding of color spaces, but my naive solution would be picking a random starting color, and then solving the next point that's furthest away within the 3D search space (from which some regions would be excluded, as we don't want the murky browns etc). Then repeat for as many points as you need.

Sounds like an O(n) algorithm, but I'd have to better understand how to avoid the murky regions etc.

Will be watching this space. ;)

@davidschlachter
Copy link

What could work well would be to convert the colour to HSL, then split the 360º of hue to get the number of colours desired.

Here's a pretty kludgy implementation: https://jsfiddle.net/32obz8jd/ (hit "Run" to get new colours)

I use something similar on my website to adjust the luminosity of the random colour for the menu.

@breznak
Copy link

breznak commented Jan 19, 2016

Hi,
I'm very interested in this functionality as well.
To my knowledge, there is no other JS library providing generation of distinct colors.

There is a lot of interesting research on the "color perception" and "how to generate easily distinguishable set of colors":

It boils down to: RGB (even HSV) does not suitably model human color-perception; for smaller sets, it's best to use man-made (=evaluated) fixed color pallet and pick from it; for arbitrary number, use some specialized algorithm.

Note: In my opinion the idea of dividing HUE to a fixed sized steps does not work well. This is a problem in DyGraphs why I came here: https://github.com/danvk/dygraphs/blob/f71d9959ee259394813cc4434674e95033054842/src/dygraph.js#L1287 My aim is to create a better solution in JS and then use randomColor in DyGraphs. The current problematic results can be seen here: https://raw.githubusercontent.com/wiki/nupic-community/nupic.visualizations/images/nupic_visualizations.png

You can try a nice working solution at: http://phrogz.net/css/distinct-colors.html
I hope we could reuse the code: http://phrogz.net/JS/color_conversion.js to implement this feature.

@jackycute
Copy link

+1

1 similar comment
@joadr
Copy link

joadr commented Jan 19, 2017

+1

@Offirmo
Copy link

Offirmo commented Mar 17, 2017

You might want to check chroma-js

@davidmerfield
Copy link
Owner

I just closed #87. Here's why:

It looks like the approach in this pull request is to keep generating colors until you find one that is dissimilar enough to any existing colors. This approach entails lots of unnecessary computation.

Here's one way to implement this feature:

I'd divide the 'attractive' color space into region, one region per generated color. For each region within the 'attractive' color space, pick a color from within.

Afterwards, we could then sort the generated colors to make neighbors as distinct as possible.

@davidmerfield davidmerfield changed the title Maximizing color difference Maximizing color difference? May 4, 2017
@davidmerfield davidmerfield changed the title Maximizing color difference? Maximize color difference? May 4, 2017
@davidmerfield davidmerfield changed the title Maximize color difference? Maximize color difference May 6, 2017
@jcubic
Copy link

jcubic commented Jan 28, 2018

+1

@davidmerfield
Copy link
Owner

Merged #106, closing this for now

@Angelk90
Copy link

@davidmerfield : Are there any news?
Link: codesandbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants