Sort colors by shade

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have an array of colors and I would like to sort this array from dark to
light. What is the easiest way to do this?

Thanks,
Joe
 
I have an array of colors and I would like to sort this array from dark to
light. What is the easiest way to do this?

Thanks,
Joe

Colors are represented usually by 3 or 4 values (Red, Green, Blue) or
(Red, Green, Blue, Alpha). You cannot sort colours from 'dark' to
'light', but through the rainbow, like all the hues.

Consider this:

List<Color> myColors = new List<Color>();

for (int r = 0; r < 256; r ++)
for (int g = 0; g < 256; g ++)
for int (b = 0; b < 256; b ++)
myColors.Add (new Color (r,g,b))

That would give you a pretty good sorted array of colours. Of course
there are other ways to sort colours, but I'm sure you can figure it
out when you break them down into their RGB components.
 
I have an array of colors and I would like to sort this array from dark to
light. What is the easiest way to do this?

Thanks,
Joe

Something like:

List<Color> colors;
.....
colors.Sort(delegate(System.Drawing.Color left, System.Drawing.Color
right)
{
return
left.GetBrightness().CompareTo(right.GetBrightness());
});
 
Thanks Clark. That solved problem 1.

Now problem 2 is I need an assorted list of colors without having similar
color too close to each other and can't start with a light color.

I'm guessing I'll have to look at the RGB for this case.
 
Hi Joe,

Have you resolved your issue? I'm not sure if I have understood your issue
completely. According to your description of problem two, I think you need
three lists (Red List , Green List ,Blue List). Each color is represented
by RGB (Red,Green,Blue). For this reason, if the value represented Red is
greater than the other two values, we can add it into Red list. Similar to
other lists, we can separate the colors into three lists.

Please don't hesitate to let me know if there is anything we can help with.
Sincerely,
Wen Yuan
 
Hi Joe,

Just want to know if this issue has been resolved. Please feel free to
reply me if there is anything we can help with.

Have a great day.
Sincerely,
Wen Yuan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top