xxxxxxxxxx
49
const colours = [
"#ff0000",
"#00ff00",
"#0000ff",
// "#ff00ff",
// "#00ffff",
// "#ffff00",
]
function setup() {
createCanvas(400, 100);
noLoop();
}
function draw() {
background(220);
for(let i = 0; i < width; i ++) {
for(let j = 0; j < height; j ++) {
const p = i/width;
const weights = [];
let total = 0;
for(let c = 0; c < colours.length; c ++) {
const d = c/(colours.length - 1);
let w = 1 - abs(d - p);
w *= pow(w, 10);
weights.push(w);
total += w;
}
let r = random(total);
for(let c = 0; c < colours.length; c ++) {
r -= weights[c];
if(r <= 0) {
stroke(colours[c]);
break;
}
}
point(i, j);
}
}
}
function mouseReleased() {
draw();
}