xxxxxxxxxx
let gridC = 100;
let midLine = 0;
let showRefLines = false;
let rr = 0;
let gg = 0;
let bb = 0;
function setup() {
//Creates the application window params: width=600, height=600
createCanvas(600, 600);
noLoop();
}
function draw() {
//Background color
background(255);
angleMode(DEGREES);
for (let a = 0; a < 10; a++) {
for (let b = 0; b < 10; b++) {
let dice = random(1, 2);
let rot = 0;
if (dice > 1 && dice < 1.25) {
rot = 60;
}
if (dice > 1.25 && dice < 1.5) {
rot = 120;
}
if (dice > 1.5 && dice < 1.75) {
rot = 180;
}
if (dice > 1.75 && dice < 2) {
rot = 240;
}
let x = a * gridC;
let y = b * gridC;
push();
translate(x, y);
rotate(rot);
pattern();
pop();
}
}
}
function pattern() {
push();
translate(-gridC / 2, -gridC / 2);
// Calculating the mid point
midLine = gridC / 2;
noFill();
if (showRefLines == true) {
//Canvas for pattern
rect(0, 0, gridC, gridC);
stroke(255, 0, 0);
line(0, midLine, gridC, midLine);
line(midLine, 0, midLine, gridC);
}
//Stroke Weight
strokeWeight(6);
stroke(rr, gg, bb);
noFill();
//Pattern - triangles
beginShape();
vertex(midLine / 2, 0);
vertex(gridC - midLine / 2, 0);
vertex(gridC / 2, midLine);
endShape();
beginShape();
vertex(0, midLine);
vertex(midLine / 2, gridC);
vertex(midLine, gridC);
endShape();
beginShape();
vertex(midLine, 0);
vertex(gridC - midLine / 2, midLine / 2);
vertex(gridC, midLine);
endShape();
pop();
}
//When the "e" key is pressed the pattern changes colors
//When the "r" key is pressed the pattern changes shapes
function keyPressed() {
if (key == 'e') {
rr = random(0, 255);
gg = random(0, 255);
bb = random(0, 255);
draw();
}
if(key == 'r') {
draw();
}
}