Converting HSBtoRGB into the domain [0,300]

Hi,

I want to convert the scalar value into RGB color value. That is, I want to convert HSL color space to RGB values. In the HSL color space, I have taken hue as the scalar value, saturation=1 and brightness=0.5. Then, I want to convert it to RGB.

Using the method below, I am getting the same value of the RGB color for both max and min scalar values. Because it maps to the domain [0, 360]. I want to map it into [0,300]. That is minimum scalar vaue will be 0 and the maximum scalar value will be 300.

I could not do this. Can anyone please tell me how to do this.

Thanks in advance.

okd
----

// The complete java class with method
import java.awt.*;

class RGBConvert {

      static float[]  HSB_to_RGB1(float hue) {
              float saturation1 = 1.0f;
              float brightness1 = 0.5f;  
              float[] rgb1;
              rgb1 = new float[3];
              Color color;

              color = new Color (Color.HSBtoRGB(hue, saturation1, brightness1));
              rgb1[0] = 1.0f - (float)color.getRed()/ 256 ;
              rgb1[1] = 1.0f - (float)color.getGreen()/ 256 ;  
              rgb1[2] = 1.0f - (float)color.getBlue()/ 256 ;
            System.out.println(rgb1[0] + "          "+ rgb1[1]+ "        " + rgb1[2]);  
              return rgb1;
          }

    public static void main(String args[]) {
   
          float x =1.0f;
        //float x =0.0f;
          HSB_to_RGB1(x);
    }
}
okdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
> Because it maps to the domain [0, 360].
> I want to map it into [0,300].

why don't you multiply your final result with 5/6
0
okdAuthor Commented:
I have multiplied the final result by 5/6. Still the maximum and the minimum value is same.

I made it below:
    rgb1[0] = 1.0f - (float)color.getRed()*5/(256*6) ;
    rgb1[1] = 1.0f - (float)color.getGreen()*5/(256*6) ;  
    rgb1[2] = 1.0f - (float)color.getBlue()*5/(256*6) ;

Result :

For hue=  1.0   0.16992188          1.0        1.0
For hue=  0.0   0.16992188          1.0        1.0

Please help.

          
0
okdAuthor Commented:
I did it. I am sorry.  I was always trying to multiply the rgb[0] by 5/6. Actually, I have to multiply all hue values by 5/6 to map it into [0, 300].

Once again thanks a lot.

0
heyhey_Commented:
this code

// The complete java class with method
import java.awt.*;

class RGBConvert {

static float[]  HSB_to_RGB1(float hue)
{
//  float hue = 1.0f;
  float saturation1 = 1.0f;
  float brightness1 = 0.5f;    
  float[] rgb1;

  rgb1 = new float[3];
  Color color = Color.getHSBColor(hue, saturation1, brightness1);

//  System.out.println(color.getRed() + ", "+ color.getGreen()+ ", " + color.getBlue());  
  rgb1[0] = ((float)color.getRed())/ 256 ;
  rgb1[1] = ((float)color.getGreen())/ 256 ;  
  rgb1[2] = ((float)color.getBlue())/ 256 ;
  System.out.println(rgb1[0] + ", "+ rgb1[1]+ ", " + rgb1[2]);
  return rgb1;
}

public static void main(String args[])
{

  float x =1.0f;
  HSB_to_RGB1(x);
  x =0.75f;
  HSB_to_RGB1(x);
  x =0.5f;
  HSB_to_RGB1(x);
  x =0.25f;
  HSB_to_RGB1(x);
  x =0f;
  HSB_to_RGB1(x);

}
}

returns

0.49609375, 0.0, 0.0
0.24609375, 0.0, 0.49609375
0.0, 0.49609375, 0.49609375
0.24609375, 0.49609375, 0.0
0.49609375, 0.0, 0.0

so it's quite normal that you receive equal colors for hue = 0 and hue = 1.
0
heyhey_Commented:
>> Once again thanks a lot.

so Answer ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.