xxxxxxxxxx
28
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
radialGradient(20, 20, 50, 50,color(6, 17, 60), color(238, 238, 238));
}
/**
* Renders a radial gradient.
*
* @param {Number} x X position
* @param {Number} y Y position
* @param {Number} w width
* @param {Number} h height
* @param {Color} inner Inner colour
* @param {Color} outer Outer colour
*/
function radialGradient(x, y, w, h, inner, outer) {
noStroke();
for (let i = Math.max(w, h); i > 0; i--) {
const step = i / Math.max(w, h);
const colour = lerpColor(inner, outer, step);
fill(colour);
ellipse(x, y, step * w, step * h);
}
}