drawLinearGradient function
Fills a rectangular area delimited by x1
, y1
, x2
and y2
with a liner gradient blending
from c1
to c2
along the X-axis.
Implementation
Image drawLinearGradient(Image destination, int x1, int y1, int x2, int y2, int c1, int c2) {
x1 = x1.clamp(0, destination.width);
x2 = x2.clamp(x1, destination.width);
y1 = y1.clamp(0, destination.height);
y2 = y2.clamp(y1, destination.height);
for (int x = x1; x < x2; x++) {
int col = alphaBlendColors(c1, c2, ((x - x1) / (x2 - x1) * 255).floor());
for (int y = y1; y < y2; y++) {
destination.setPixelSafe(x, y, col);
}
}
return destination;
}