I’m not sure exactly what it’s called, but I’m trying to generate an RGB color map like what you see when creating a custom color in MS Paint (or Photoshop or any other countless applications).
The code I currently found and am using:
private final static int COLORS_WIDTH = 256;
private final static int COLORS_HEIGHT = 256;
_colorPixmap = new Pixmap(256, 256, Format.RGB888);
for (int x = 0; x < COLORS_WIDTH; ++x)
{
for (int y = 0; y < COLORS_HEIGHT; ++y)
{
float h = x / (float) COLORS_WIDTH;
float s = (COLORS_HEIGHT - y) / (float) COLORS_HEIGHT;
float l = 0.5f;
Color color = HSLtoRGB(h, s, l);
_colorPixmap.setColor(color);
_colorPixmap.drawPixel(x, y);
}
}
Generates this:
http://i.imgur.com/9sHrfJR.png
Which is great, however, I absolutely require to have black/white as selectable colors too, but this RGB map doesn’t have it.
I’m not good with color stuff (hue, saturation, brightness) and can’t seem to tweak the code to get what I’m looking for.
Any help / suggestions or do I need a different approach?
Thanks!
2
Answers
Colour in the HSL space has three dimensions. You are mapping two of them right now (hue and saturation), while keeping lightness at a constant value
float l = 0.5f;
. In order to obtain all colours you need to provide a slider for the lightness in the same way that MS Paint does.You could use the JColorChooser. This tutorial shows you how.