I was generating a linear gradient using code I found online and then tried adding rotation using transformation matrix. The gradient did rotate, however artifacts appeared: the gradient was no longer perfect, dark lines appeared in between the lines of the gradient. What’s the cause of this and how do I fix it?
final float ALPHA = radians(90); // change this from 90 to 0 and see the difference
final color c1 = color(255, 0, 0);
final color c2 = color(0, 0, 255);
void setup() {
size(1024, 576);
frameRate(30);
noFill();
}
void draw() {
pushMatrix();
float w1 = height * sin(ALPHA);
float w2 = width * cos(ALPHA);
float h1 = height * cos(ALPHA);
float h2 = width * sin(ALPHA);
rotate(-ALPHA);
translate(-w1, 0);
scale((w1 + w2) / width, (h1 + h2) / height);
background(0);
for (int y = 0; y < height; ++y) {
stroke(lerpColor(c1, c2, map(y, 0, height, 0, 1)));
line(0, y, width, y);
}
popMatrix();
}