xxxxxxxxxx
53
function getColorGradient(x_loc) {
// example 1, okay!
// let start = [50, 0, 0];
// let end = [100, 100, 0];
// let start = [100, 0, 0];
// let end = [0, 100, 0];
let start = [100, 0, 0];
let end = [0, 100, 100];
// you probably don't need to change anything in this function
// below this comment! unless you want to, then feel free :D
r = lerp(start[0], end[0], x_loc);
g = lerp(start[1], end[1], x_loc);
b = lerp(start[2], end[2], x_loc);
// hue rotates around, so 101 = 1
// sat and value should be between 0 and 100, so clamp them!
return [r, g, b];
}
function setup() {
createCanvas(800, 800);
colorMode(RGB, 100);
}
function draw() {
// you probably won't need to change this unless you want to!
// we go through and draw 100 rectangles, stepping through
// each of the colors
let count = 100;
for (let i = 0; i < count; i++) {
let x_loc = i / count;
let x = x_loc * width;
let hsv = getColorGradient(x_loc);
let fillColor = color(hsv[0], hsv[1], hsv[2], 100)
fill(fillColor);
noStroke();
rect(x, 0, width / count, height);
}
}