对像素的渐变效果 [Java]

Gradient effect to pixels [Java]

我怎样才能对这样的东西应用渐变?刚刚得到纯色。

for (int i = 0; i < screen.pixels.length; i++)
    screen.pixels[i] = 0xff0000;

通过获取十六进制代码的 RGB 值、遍历获取渐变的矩形的大小并在两个 r、g 和 b 值之间进行插值来解决问题。

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));
    }
}