views:

540

answers:

2

I am assigning each color a numeric value. For example:

Color.red: 12 
Color.Blue: 6

I need to find a color between two colors (for example, red and blue). But how? I have tried this,

(Color.red+color.blue)/2=> (12 + 6)/2 = 9

9 corresponds to Color.yellow

+1  A: 

Colors are normally represented as a six digit hex value for computers with Red, Green & Blue taking two digits each in that order e.g. FF0000 is red, 00FF00 is blue and 0000FF is Green. You should consider how to move between those kinds of values.

Michael Leigeber has a nice color transition algorithm in JavaScript which you can download to see how he has implemented moving between two values.

Dave Anderson
+3  A: 

You'll need to use the RGB values of the colour and interpolate between those. Using a single value isn't going to give you the discrimination you need.

The answer that yx quotes http://stackoverflow.com/questions/576861/c-drawing-a-line-with-a-gradient-colour looks like a good place to start

ChrisF