xxxxxxxxxx
79
/*
generative pattern 3
04.06.2024
*/
function setup() {
createCanvas(windowWidth, windowHeight);
pattern();
}
function mousePressed(){
pattern();
}
function pattern(){
background('black');
noStroke(0)
// width of columns
var cols =20 // number of columns
var w = width / cols; //column width
// var rows = 25;
var rows = cols * (height / width);
var h = height / rows; //row height
for (let x = 0; x <= width; x += w) {
for (let y = 0; y <= height; y += h) {
//ellipse(x, y, w, h);
//rect (x + w / 2, y + h /2, 10);
//set transform
push();
translate(x, y);
//choose from 7 colors
var whichColor = round (random(9));
if (whichColor === 0){
fill('#C33310')
} else if (whichColor === 1) {
fill('#FEC6E0')
} else if(whichColor === 2){
fill('#D0A34D')
} else if(whichColor === 3){
fill('#88A075');
} else if (whichColor === 4) {
fill("#FFCAD4")
} else if(whichColor === 5){
fill("#87CEEB")
} else if(whichColor === 6){
fill("#D8B2D8");
}
// draw at 0,0
var whichRect = round(random());
if (whichRect === 0) {
//draw top right rect
triangle(0,0, w,0,w,h); //(0,0, w,0)
} else {
// draw bottom left rect
rect(0,0, w,h,0,h ); //(0,0, w,h )
}
//ellipse(0, 0, w, h);
//reset transform
pop();
}
}
}