473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sort colors by shade

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
Feb 23 '07 #1
5 10742
On Feb 22, 10:35 pm, "Joe" <jbassk...@noemail.noemailwrote:
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<ColormyColors = 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.

Feb 23 '07 #2
On Feb 22, 10:35 pm, "Joe" <jbassk...@noemail.noemailwrote:
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<Colorcolors;
.....
colors.Sort(delegate(System.Drawing.Color left, System.Drawing.Color
right)
{
return
left.GetBrightness().CompareTo(right.GetBrightness ());
});

Feb 23 '07 #3
Joe
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" <aq*****@gmail.comwrote in message
news:11*********************@t69g2000cwt.googlegro ups.com...
On Feb 22, 10:35 pm, "Joe" <jbassk...@noemail.noemailwrote:
>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<Colorcolors;
....
colors.Sort(delegate(System.Drawing.Color left, System.Drawing.Color
right)
{
return
left.GetBrightness().CompareTo(right.GetBrightness ());
});

Feb 23 '07 #4
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

Feb 26 '07 #5
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

Feb 28 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: me | last post by:
good day, i found this message: and i want to know more about it too. ========================================== Hey all, example:...
47
by: Matt Kruse | last post by:
http://www.mattkruse.com/temp/css_expressions.html One of the standard CSS questions is "how can I shade every other table row a different color with CSS?" The answers are usually 1) you can't...
2
by: Mike N. | last post by:
I am looking to use an HTML checkbox feature as a trigger to shade/unshade a multiple select field in an HTML form. For instance: there are four options in the multiple select field and one outside...
3
by: gambler | last post by:
let's say you have: var games = new Array(); games = new GAME(gameNum, rotNum1, rotNum2, ... ); ( so a sparsley populate array which enables me to locate a game usin the game number...
19
by: opt_inf_env | last post by:
Hello all, I know that in html to set colors of visited and activ links one need to use line in the following format: <BODY text="#FF0000" link="#0000FF" alink="#FFFF00" vlink="#00FF00"> ...
2
by: Danny | last post by:
HI, I am trying to do a group by such as this: "select code, colors from productdb group by code, colors" I need to sort on the key field, but cannot throw in the 'ordre by key', because i...
2
by: jrhoads23 | last post by:
If you look at a standard Button in a .NET Windows Forms app, you will notice its default BackColor is "Control" and it has a 3D raised border which is 2 pixels wide. The outer edge on the left and...
3
by: VJ | last post by:
How do I use shade effect as colors. For example when I change the backcolor of my tab page, how do I set it to a faded 2 color combination? VJ
5
by: Mark | last post by:
I have a button or a Panel where I want to set the backcolor. I want to put a kind of shade on the control. On top I want light blue and dark blue at tbe bottom of the control. Is there any way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.