xxxxxxxxxx
67
function setup() {
createCanvas(3000, 3000);
}
function draw() {
background(0);
stroke(255);
strokeWeight(2);
noFill();
let Crepetitions = 4;
let Rrepetitions = Crepetitions;
let patternWidth = width / Crepetitions;
let patternHeight = height / Rrepetitions;
for (let col = 0; col < Crepetitions; col++) {
for (let row = 0; row < Rrepetitions; row++) {
push();
translate(col * patternWidth, row * patternHeight);
// initialize the side length of the first triangle
let side = 50;
// draw the first triangle relative to the current pattern's position
let x1 = patternWidth / 2;
let y1 = (patternHeight - side * sqrt(3) / 2) / 2;
let x2 = (patternWidth - side) / 2;
let y2 = (patternHeight + side * sqrt(3) / 2) / 2;
let x3 = (patternWidth + side) / 2;
let y3 = (patternHeight + side * sqrt(3) / 2) / 2;
//triangle(x1, y1, x2, y2, x3, y3);
// apply scaling and rotation, and draw subsequent triangles
for (let i = 1; i < 10; i++) {
side = side + side * 0.2;
let angle = radians(2.4 * 9); // convert degrees to radians
// calculate the rotated and scaled vertices relative to the current pattern's position
let x1_rotated = patternWidth / 2;
let y1_rotated = (patternHeight - side * sqrt(3) / 2) / 2;
let x2_rotated = (patternWidth - side) / 2;
let y2_rotated = (patternHeight + side * sqrt(3) / 2) / 2;
let x3_rotated = (patternWidth + side) / 2;
let y3_rotated = (patternHeight + side * sqrt(3) / 2) / 2;
// apply rotation
let x1_final = cos(angle) * (x1_rotated - patternWidth / 2) - sin(angle) * (y1_rotated - patternHeight / 2) + patternWidth / 2;
let y1_final = sin(angle) * (x1_rotated - patternWidth / 2) + cos(angle) * (y1_rotated - patternHeight / 2) + patternHeight / 2;
let x2_final = cos(angle) * (x2_rotated - patternWidth / 2) - sin(angle) * (y2_rotated - patternHeight / 2) + patternWidth / 2;
let y2_final = sin(angle) * (x2_rotated - patternWidth / 2) + cos(angle) * (y2_rotated - patternHeight / 2) + patternHeight / 2;
let x3_final = cos(angle) * (x3_rotated - patternWidth / 2) - sin(angle) * (y3_rotated - patternHeight / 2) + patternWidth / 2;
let y3_final = sin(angle) * (x3_rotated - patternWidth / 2) + cos(angle) * (y3_rotated - patternHeight / 2) + patternHeight / 2;
// draw the rotated and scaled triangle
triangle(x1_final, y1_final, x2_final, y2_final, x3_final, y3_final);
}
pop(); // Reset translation after drawing each pattern
}
}
}