cocoa - Algorithm For Generating Unique Colors -


I'm looking for an algorithm that will generate a series of colors so that the color can possibly be distributed (so they can easily Will not be mixed).

I have several objects that have an ID that are counted as 1. I would like to represent each of these, a different, beautiful colorful, color that won could not be easily confused with its neighbors, although the colors should not necessarily be random. Every time I input the same ID, I would like to get the same color.

Is it possible to have less appropriate boundaries with the elements? A quick and easy solution is to store an array of color values ​​using only the item's ID; It assumes that you have a relatively low color color, and you are certain that you will not go up a certain number.

If you want to create colors rather than using a list, there is a trick to make them a consistent and decent format so that they can use HSB. Pre-define a brightness and saturation, then base the value of color with some functions of the id (this can be many things, depending on the many IDs you have created, but multiplying some amount ID (and When it is more 255!) Is a good rough attitude. With this approach, all "align" in the case of color saturation and brightness, but each will have a different color.

Bored, this I hit a sharp solution together:

  class hsbillore {public entity hu {set; set;} public integer saturation {get; set;} public ent brightness {get; set; } Public color ToRGB {// Reader has been left as an exercise ...}} Public category item {public entry ID (get; set;} private static constant byte EXPECTED_MAX = 15; Private static id HUE_FACTOR = 255 / EXPECTED_MAX; Public HSB color color {mill {var color = New HsbColor () {saturation = 175, gloss = 175}, color.hu = (id * HUE_FACTOR)% 255; color of return;}}}  
Click

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -