xxxxxxxxxx
// Inspired by the work of Hiroshi Kawano
var colors; // colors[0] is always black
var size;
var probChangeColor;
var currentColor;
function setup() {
createCanvas(800, 800);
noLoop();
size = width/40;
probChangeColor = 0.25;
noStroke();
}
function draw() {
var black = color(10, 10, 10);
var white = color(247, 243, 242);
var blue = color(0, 119, 225);
var yellow = color(245, 210, 22);
var red = color(252, 53, 3);
colors = [black, white, white, blue, yellow, red];
currentColor = randomColor();
createComposition();
addBorder();
}
function createComposition() {
for (var y = 0; y < height; y += size) {
for (var x = 0; x < width; x += size) {
if (random(1) < probChangeColor) {
currentColor = randomColor();
}
fill(currentColor);
square(x, y, size);
}
}
}
function addBorder() {
strokeWeight(2);
stroke(colors[0]);
line(0, 0, 0, height);
line(0, height, width, height);
line(width, height, width, 0);
line(width, 0, 0, 0);
noStroke();
}
function randomColor() {
return colors[floor(random(colors.length))];
}
function keyPressed() {
if (key === " ") {
draw();
}
}