How could I apply a gradient to something like this? Just got a solid colour.
for (int i = 0; i < screen.pixels.length; i++)
screen.pixels[i] = 0xff0000;
How could I apply a gradient to something like this? Just got a solid colour.
for (int i = 0; i < screen.pixels.length; i++)
screen.pixels[i] = 0xff0000;
Solved the issue by getting the RGB values of hex codes, looping through the size of the rectangle that got the gradient, and interpolated between the two r, g, and b values.
float r = Color.decode(colourOne).getRed();
float g = Color.decode(colourOne).getGreen();
float b = Color.decode(colourOne).getBlue();
float r2 = Color.decode(colourTwo).getRed();
float g2 = Color.decode(colourTwo).getGreen();
float b2 = Color.decode(colourTwo).getBlue();
float interp, newR, newG, newB;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
interp = (float) (x + y) / (float) (width + height);
newR = r * (1 - interp) + r2 * interp;
newG = g * (1 - interp) + g2 * interp;
newB = b * (1 - interp) + b2 * interp;
pixels[x + y * width] = (int) (Math.floor(newR) * 0x10000 + Math.floor(newG) * 0x100 + Math.floor(newB));
}
}