hopefully this is coming very soon. a side-effect of #2670 is per-vertex coloring.
so
translate(-width/2, -height/2);
noStroke();
beginShape();
fill(255, 0, 0);
vertex(0, 0);
vertex(width, 0);
fill(0, 255, 0);
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
will give you

@Spongman That sounds good. For now, I added a "gradientDetail" variable:
function yGradient (c1, c2, o, x, y, w, h, mode) {
fill(0);
strokeWeight(h/gradientDetail);
for (var i = 0; i < gradientDetail; i++) {
let yo = i/gradientDetail*h
stroke(lerpColor(c1, c2, (i/gradientDetail+o)));
if (mode === CORNER) {
line(x, y+yo, x+w, y+yo);
} else if (mode === CENTER) {
line(x-w/2, y+yo-h/2, x+w/2, y+yo-h/2);
}
}
}
Relates to #4141
The sample above provided by https://github.com/processing/p5.js/issues/2750#issuecomment-377291020 works with version 0.8.0 but in version 0.9.0 the output is wrong:

Per-vertex fill for WEBGL is working as #4147 . The code in the comments will produce the desired gradient in the current master branch. Closing for organizational purposes. Thanks!
Most helpful comment
hopefully this is coming very soon. a side-effect of #2670 is per-vertex coloring.
so
will give you
