xxxxxxxxxx
//Define Colors
var clDp; //Dark Purple
var clLp; //Light Purple
var clO; //Orange
var clDr; //Dark Red
var clM; // Magenda
var clBlue; //Blue
var clBrown; //Brown
function setup() {
createCanvas(600, 600);
background("#fff")
noLoop();
noStroke();
// Assign values to the defined variables at top
clDp = "#781E64";
clLp = "#9632C8";
clO = "#FA9632";
clDr = "#641E1E";
clM = "#C84696";
clBlue = "#643CB4";
clBrown = "#C86432";
}
function draw() {
//Create rectangles of random heights and widths
for (var y = 0; y < height;) {
var rectH = random(10, 50);
for (var x = 0; x < width;) {
var rectW = random(50, 600);
// Draw rectangles with random colors
fill(randomColor());
rect(x, y, rectW, rectH);
// Move x to the end of the last rectangle to start the new one
x = x + rectW;
}
// Move y to the end of the last rectangle to start the new one
y = y + rectH;
}
}
function randomColor() {
// Add defined colors to an array
var colors = [clDp, clLp, clO, clDr, clM, clBlue, clBrown];
return random(colors); // Select a random color from the array and return it
}
function keyPressed() {
if (key == 'r') {
draw();
}
if (key == 's') {
saveCanvas('random.jpg');
}
}