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
9对应Color.yellow
3 个解决方案
#1
5
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.
您需要使用颜色的RGB值并在这些值之间进行插值。使用单一值不会给您带来所需的歧视。
The answer that yx quotes Drawing a line with a gradient color looks like a good place to start
yx引用使用渐变颜色绘制线条的答案看起来像是一个好的起点
#2
1
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.
对于具有红色,绿色和蓝色的计算机,颜色通常表示为六位十六进制值,每个按照该顺序取两个数字,例如, FF0000为红色,00FF00为蓝色,0000FF为绿色。您应该考虑如何在这些值之间移动。
Michael Leigeber has a nice color transition algorithm in JavaScript which you can download to see how he has implemented moving between two values.
Michael Leigeber在JavaScript中有一个很好的颜色转换算法,你可以下载它来看看他是如何在两个值之间实现移动的。
#3
0
This problem requires you to split the alpha, red, green, and blue componenets of each colour, find the average of each, and create a new color:
此问题要求您拆分每种颜色的alpha,red,green和blue组件,找到每种颜色的平均值,并创建一种新颜色:
Color first = Color.Red;
Color second = Color.Blue;
byte r = (byte)((first.R + second.R) / (byte)2);
byte g = (byte)((first.G + second.G) / (byte)2);
byte b = (byte)((first.B + second.B) / (byte)2);
byte a = (byte)((first.A + second.A) / (byte)2);
Color mix = Color.FromArgb(a, r, g, b);
#1
5
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.
您需要使用颜色的RGB值并在这些值之间进行插值。使用单一值不会给您带来所需的歧视。
The answer that yx quotes Drawing a line with a gradient color looks like a good place to start
yx引用使用渐变颜色绘制线条的答案看起来像是一个好的起点
#2
1
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.
对于具有红色,绿色和蓝色的计算机,颜色通常表示为六位十六进制值,每个按照该顺序取两个数字,例如, FF0000为红色,00FF00为蓝色,0000FF为绿色。您应该考虑如何在这些值之间移动。
Michael Leigeber has a nice color transition algorithm in JavaScript which you can download to see how he has implemented moving between two values.
Michael Leigeber在JavaScript中有一个很好的颜色转换算法,你可以下载它来看看他是如何在两个值之间实现移动的。
#3
0
This problem requires you to split the alpha, red, green, and blue componenets of each colour, find the average of each, and create a new color:
此问题要求您拆分每种颜色的alpha,red,green和blue组件,找到每种颜色的平均值,并创建一种新颜色:
Color first = Color.Red;
Color second = Color.Blue;
byte r = (byte)((first.R + second.R) / (byte)2);
byte g = (byte)((first.G + second.G) / (byte)2);
byte b = (byte)((first.B + second.B) / (byte)2);
byte a = (byte)((first.A + second.A) / (byte)2);
Color mix = Color.FromArgb(a, r, g, b);