How to create pastel colors programmatically in C#?

后端 未结 2 1325
盖世英雄少女心
盖世英雄少女心 2021-02-01 22:51

To generate them equally spaced out based on the number of colors wanted. Something that looks like this if 8 is given for the count specified:

List         


        
2条回答
  •  春和景丽
    2021-02-01 23:50

    You'll find colors easier to work with in these sorts of problems if you use HSV instead of RGB.

    "equally spaced colors" almost always means "equally spaced hues". So, for [0,360) in hue, you just equally space by dividing that range equally.

    Now you have a hue, and you just need to find the "pastel" version of that hue. To me, this means desaturating the color a bit. I'd say to 80% saturated for starters.

    In my tests, I used 100% for value. Then just convert to RGB. Here's what I've been playing with:

    
    
    
    

    Not C#, I know, but just trying to nail the light & sat down.

    Otherwise, you could look at your sample colors, and see if there is any correlation in the HSV/HSL values, and try to derive an algorithm from that. If you plot S/H and V/H, you'll see a large dip in the graph at the grey color --- it seems to be an outlier. (Third from left on bottom row.) Ignoring that value, S is about at 75% and value is just under 90%. Using those values probably gave the nicest result.

    Link: http://jsfiddle.net/ZHyAQ/

提交回复
热议问题