xxxxxxxxxx
37
function setup() {
createCanvas(400, 400);
textAlign(CENTER);
frameRate(5);
}
function draw() {
background(255);
// random() gives us a number between 0 and 1
let diceroll = random();
let color1 = 'black';
let color2 = 'black';
let color3 = 'black';
let color4 = 'black';
// we can divide [0,1] to different "bins"
// let's have 4 equal size bins
if (diceroll < 0.25) {
color1 = 'white';
} else if (diceroll < 0.5) {
color2 = 'white';
} else if (diceroll < 0.75) {
color3 = 'white';
} else if (diceroll < 1) {
color4 = 'white';
}
textSize(200);
scale(1, 3);
fill(color1);
text('A', 50, 150);
fill(color2);
text('A', 150, 150);
fill(color3);
text('A', 250, 150);
fill(color4);
text('A', 350, 150);
}