xxxxxxxxxx
65
let timestamp = 0;
const colors = [
[0, 0, 204],
[0, 0, 128],
[0, 0, 0],
];
let tw = 180;
let th = 180;
function setup() {
createCanvas(640, 640);
// noLoop();
}
function draw() {
if (millis() - timestamp > 2000) {
timestamp = millis();
noStroke();
for (var x = 0; x < width; x+=tw) {
for (var y = 0; y < height; y+=th) {
/* logic for two triangles per box */
let rand = random();
drawTriangles(x, y, rand);
}
}
}
}
//for splitting squares into two trianges
function drawTriangles(x, y, dir){
//dir > .5 draws line ul to lr
//dir < .5 draws line lr to ur
//define triangle points
let ulx = x;
let uly = y;
let llx = x;
let lly = y + th;
let urx = x + tw;
let ury = y;
let lrx = x + tw;
let lry = y + th;
//draw triangles by dir
if (dir > .5) {
fill(getColor());
triangle(ulx, uly, llx, lly, urx, ury);
fill(getColor());
triangle(llx, lly, urx, ury, lrx, lry);
} else if (dir <= .5) {
fill(getColor());
triangle(ulx, uly, llx, lly, lrx, lry);
fill(getColor());
triangle(ulx, uly, urx, ury, lrx, lry);
}
}
function getColor() {
let col;
col = colors[parseInt(random(colors.length))];
stroke(col);
return col;
}