Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C# Programming

Sort colors by shade


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

On Feb 22, 10:35 pm, "Joe" <jbassk@noemail.noemail> wrote:

> 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.

-----------------------------------------------Reply-----------------------------------------------

On Feb 22, 10:35 pm, "Joe" <jbassk@noemail.noemail> wrote:

> 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());
        });

-----------------------------------------------Reply-----------------------------------------------

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.

"Tim Clark" <aqui@gmail.com> wrote in message

news:1172206099.469117.72980@t69g2000cwt.googlegroups.com...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc