how to change color in HSB color system
I am studying the sample code from the last answer on this post
to see how to make a good flashing button. That sample code use the following code to specify the colors:
for (int i = 0; i < N; i++)
{
clut.add(Color.getHSBColor(1, 1 - (i / N), 1));
}
for (int i 开发者_如何学运维= 0; i < N; i++)
{
clut.add(Color.getHSBColor(1, i / N, 1));
}
Color.getHSBColor(1, 1 - (i / N), 1) is the place building the colors. The first parameter (Hue) of the getHSBColor() will specify the base color. So if I change it to 230, the colors should be blue based colors; if it is 60, the colors should be yellow based. But the sample program doesn't work as I expected. There is no flashing color changes after I set the Hue to different value. Anybody knows why?
Color.getHSBColor()
should receive floating point numbers from 0 to 1, so any value bigger than 1 will be treated like 1...
Take a look:
The hue parameter is a decimal number between 0.0 and 1.0 which indicates the hue of the color. You'll have to experiment with the hue number to find out what color it represents.
For example, setPenColor(Color.getHSBColor(0.56f, 1.0f, 0.8f));
source: http://www.otherwise.com/Lessons/ColorsInJava.html
For example, you could do:
float hue = your_color/255; // if you want to use 0-255 range
for (int i = 0; i < N; i++) {
clut.add(Color.getHSBColor(hue, 1 - (i / N), 1));
}
for (int i = 0; i < N; i++) {
clut.add(Color.getHSBColor(hue, i / N, 1));
}
精彩评论