xxxxxxxxxx
48
let randRadio;
let rWidth = 32;
let mColor = {
r: 120,
g: 120,
b: 220,
};
function setup() {
createCanvas(400, 400);
randRadio = createRadio();
randRadio.option("0", "random()");
randRadio.option("1", "randomGaussian()");
randRadio.selected("0");
drawRandom();
}
function draw() {}
function drawRandom() {
background(255);
noStroke();
let gauss = randRadio.value();
fill(mColor.r, mColor.g, mColor.b);
rect(0, 0, rWidth, height);
for (let x = rWidth; x < width; x += rWidth) {
let rVal = mColor.r + random(-50, 50);
let gVal = mColor.g + random(-50, 50);
let bVal = mColor.b + random(-50, 50);
if (gauss == "1") {
rVal = mColor.r + randomGaussian(0, 17);
gVal = mColor.g + randomGaussian(0, 17);
bVal = mColor.b + randomGaussian(0, 17);
}
fill(rVal, gVal, bVal);
rect(x, 0, rWidth, height);
}
}
function mouseClicked() {
drawRandom();
}