Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating random yet good-looking, different colors?

Tags:

c#

Is there any well-known method for generating random, good looking and yet distinctive colors? I've worked with this before, and managed to generate colors at random. However, either they had a great chance of turning out "ugly" (yellow-ish brown, green-ish gray and others), or they turned out to be almost the same.

Now, as for measuring if two colors are almost the same, it's quite easy to just take the color channels and compare the differences between them.

I suspect that I will always need to generate between 1 and 15 colors.

Edit It's for some graphing stuff I am making in JavaScript. That may help you understand why I am in need of this.

like image 723
Mathias Lykkegaard Lorenzen Avatar asked Dec 09 '22 02:12

Mathias Lykkegaard Lorenzen


2 Answers

I assume you're randomizing in the RGB color space; if you use a different color space, e.g. HSB, it is easier to determine whether two colors are similar, and you can limit the range of each axis to exclude 'ugly' colors.

For example, you may want to create the first color using:

  • full range hue
  • full saturation (100%)
  • brightness in the upper 50%

And then a contrasting color using:

  • first color's hue +/- a certain random value
  • full saturation (100%)
  • brightness in the lower 50%, but maxing at enough distance vs. the first color

The possibilities are endless, but the key idea is that HSB is a more 'natural' color space to randomize over, because you control the perceived properties of a color (hue, saturation, brightness), not the technical properties (intensities of three channels).

like image 170
tdammers Avatar answered Jan 01 '23 22:01

tdammers


I don't know about selecting single colors, since "ugly" and "good-looking" are very subjective terms.

Color schemes, or sets of colors that match, on the other hand, have some theory behind them, and it's very possible to select random colors that go together well.

Check out this website: Color Scheme Designer.

like image 22
cha0site Avatar answered Jan 01 '23 23:01

cha0site