> On Jul 25, 2020, at 4:09 AM, Siamak Sarmady <[log in to unmask]> wrote:
>
> Now I want to store RGB values in it (as a single Int). I want to have a map which maps the RGB values to java.awt.Color objects.
>
> How can I do this? Is it possible to do it using sim.util.gui.SimpleColorMap?
SimpleColorMap isn't the right tool here. Just use ColorMap. Here's something I just typed in, no idea if it works but you should get the idea. See the documentation for ColorMap for information about each of these methods.
public class SiamakColorMap implements ColorMap
{
public Color getColor(double level)
{
// getRGB really includes alpha
return new Color(getRGB(level));
}
public int getRGB(double level)
{
// despite its name, this needs to include alpha
// I presume alpha is in the high 24 bits, should be 255 I think?
return level | (255 >> 24);
}
public int getAlpha(double level)
{
return 255;
}
public boolean validLevel(double level)
{
// I'm gonna assume that all levels are valid regardless of their
// alpha bits so we'll just say true here.
return true;
}
public double defaultValue()
{
// um, how about...
return 0;
}
}
|