Reputation: 427
In my program, I need to cycle through the Known user colors available in order so it looks smooth and natural, like the DWM color slider.
The colors have to be converted to a uint aswell
private static uint ColorToBgra(Color
{
return (uint)
(color.B | (color.G << 8) | (color.R << 16) | (color.A << 24));
}
Then set it. I tried setting it to white which uint is 0 then adding +1 every 0.1 seconds, but it isn't smooth and at intervals of about uint 250 it'll turn black then proceed. Would this work for me?I tried it but it doesn't.
Any ideas?
Upvotes: 3
Views: 2094
Reputation: 2241
This might push you in the right direction?
// w goes from 0 to 100
private static Color spectrumColor(int w)
{
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
w = w % 100;
if (w < 17) {
r = -(w - 17.0f) / 17.0f;
b = 1.0f;
} else if (w < 33) {
g = (w - 17.0f) / (33.0f - 17.0f);
b = 1.0f;
} else if (w < 50) {
g = 1.0f;
b = -(w - 50.0f) / (50.0f - 33.0f);
} else if (w < 67) {
r = (w - 50.0f) / (67.0f - 50.0f);
g = 1.0f;
} else if (w < 83) {
r = 1.0f;
g = -(w - 83.0f) / (83.0f - 67.0f);
} else {
r = 1.0f;
b = (w - 83.0f) / (100.0f - 83.0f);
}
return Color.FromArgb((int)r * 255, (int)g * 255, (int)b * 255);
}
Upvotes: 2