1

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?

Community
  • 1
  • 1
5YrsLaterDBA
  • 33,370
  • 43
  • 136
  • 210

1 Answers1

1

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));             
        } 
Community
  • 1
  • 1
woliveirajr
  • 9,433
  • 1
  • 39
  • 49
  • 3
    Strange, but java doc says differently (h is for Hue): The s and b components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The h component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model. – 5YrsLaterDBA Sep 20 '11 at 16:15