Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Change Colors in C#

Tags:

c#

.net

colors

I am current working on a project where, as different users add text to a document, I would like the color of the text to change.

Originally, I was using C#'s predefined color values and just putting the ones I wanted to use into an enum in my application and cycling through the colors as different users added annotations. This works fine, and I am okay with this solution.

However, I also could have chosen to change the RGB values and derived colors that way. I'm curious about what type of algorithm would be good to change those values to get different sets of colors. This is more just an exercise of something I had thought about.

To clarify a little bit, I don't want to just increment one of the color values (R, G, or B) because that wouldn't give me enough variety in my colors. But, I don't think it would also work to increment all three of equal amounts. I also have to watch out for repeating colors (up to a point). The requirements for my project anticipates, at most, 10 different reviewers.

like image 675
JasCav Avatar asked Oct 14 '22 07:10

JasCav


1 Answers

The best thing to do for this kind of problem is use HSL or HSV values and vary just the hue. Then convert back to RGB.

See this link for more information.

like image 101
Brian R. Bondy Avatar answered Oct 20 '22 15:10

Brian R. Bondy