xxxxxxxxxx
let nTiles = 10; // Number of tiles per row/column
let colorList = []; // Stores colors
let w; // Tile width
let h; // Tile height
let lapse = 0; // mouse timer
// Returns a random color from colorList
function randomColor() {
let index = floor(random(colorList.length));
return colorList[index];
}
function setup() {
createCanvas(500, 500);
frameRate(2);
noLoop();
//background(setBg());
// Caculate tile width and height
w = height / nTiles;
h = height / nTiles;
// Add colors to palette
//colorList.push(color(16)); // Dark Grey
colorList.push(color(214, 150, 159)); // Hollyhock Pink
//colorList.push(color(212, 99, 88)); // Saffron
//colorList.push(color(254, 204, 113)); // Yellow Magnolia
colorList.push(color(151, 179, 183)); // Shale
}
function draw() {
background(setBg());
// Create 2D tile layout
for (let row = 0; row < nTiles; row++) {
for (let col = 0; col < nTiles; col++) {
// Caculate x and y positions of tile position
let x = col * w;
let y = row * h;
noStroke();
//triangle(0, 0, w, 0, w, h);
push(); // Push transalation matrix
translate(x-w/4, y); // Move point of origin
// Random fill and stroke colors
let inter = map(row, w, h, 0, 1);
//fill(lerpColor(random(colorList), random(colorList), inter));
fill(setBg());
noStroke();
// Draw random truchet tile
let r = floor(random(10));
rect(w, h/4, w/2, h/2);
rect(w/2, 0, w/2, h/2);
rect(w/4, h/4, w/2, h/2);
rect(w/2, h/2, w/2, h/2);
fill(0);
pop();
fill(setBg());
ellipse(x+w/2,y+h/2,w/4,h/4)
}
}
//translate(-width/2, -height/2);
//fill(255,0,0);
}
function mousePressed(){
// prevents mouse press from registering twice
if (millis() - lapse > 500){
save('20200710.jpg');
lapse = millis();
}
}
const setBg = () => {
const randomColor = Math.floor(Math.random()*16777215).toString(16);
return "#" + randomColor;
}