xxxxxxxxxx
64
let c1; let c2;
let n = 10;
let n2 = 5;
function setup() {
createCanvas(400, 400);
c1 = color('#634AFF');
c2 = color('#FF5631');
c3 = color('#FDF48A');
}
function draw() {
background(220);
for (let i=0; i<1; i++) {
let range = width/1;
block(i*range, range, 0, 1*height, 0, 1);
}
// for (let i=0; i<3; i++) {
// let range = width/3;
// block(i*range, range, 0, 1*height/3, 0, 1);
// }
// for (let i=0; i<1; i++) {
// let range = width/1;
// block(i*range, range, 1*height/3, 2*height/3, 0, 1);
// }
// for (let i=0; i<3; i++) {
// let range = width/3;
// block(i*range, range, 2*height/3, 3*height/3, 0, 1);
// }
}
function block(min, range, y, h, a, b) {
let m = 0.3;
let x0 = 0;
let x1 = m;
let x2 = 0.5;
let x3 = 1-m;
let x4 = 1;
setGradient(min + x0*range, min + x1*range, c1, c2, y, h, a, b);
setGradient(min + x1*range, min + x2*range, c2, c3, y, h, a, b);
setGradient(min + x2*range, min + x3*range, c3, c2, y, h, a, b);
setGradient(min + x3*range, min + x4*range, c2, c1, y, h, a, b);
}
function setGradient(x, w, c1, c2, y, h, a, b) {
for (let i = x; i <= w; i++) {
let inter = map(i, x, w, a, b);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(i, y, i, y + h);
}
}