xxxxxxxxxx
49
function setup() {
createCanvas(600, 600);
noLoop(); // Prevent continuous drawing
}
function draw() {
background(220);
// Define rectangle properties
let rectWidth = 200;
let rectHeight = 200;
// Calculate the center position
let x = (width - rectWidth) / 2;
let y = (height - rectHeight) / 2;
// Draw the original rectangle
stroke(0);
noFill();
rect(x, y, rectWidth, rectHeight);
// Generate random points for splitting with slight offsets
let offset = 200; // Offset distance
let p1 = createVector(random(x + offset, x + rectWidth - offset), random(y + offset, y + rectHeight - offset));
let p2 = createVector(random(x + offset, x + rectWidth - offset), random(y + offset, y + rectHeight - offset));
// Offset the points slightly to separate the quadrilaterals
p1.x += random(-offset, offset);
p1.y += random(-offset, offset);
p2.x += random(-offset, offset);
p2.y += random(-offset, offset);
// Draw the first quadrilateral
beginShape();
vertex(x, y); // Top-left
vertex(p1.x, p1.y); // Random point 1
vertex(p2.x, p2.y); // Random point 2
vertex(x + rectWidth, y); // Top-right
endShape(CLOSE);
// Draw the second quadrilateral
beginShape();
vertex(x + rectWidth, y); // Top-right
vertex(p2.x, p2.y); // Random point 2
vertex(p1.x, p1.y); // Random point 1
vertex(x + rectWidth, y + rectHeight); // Bottom-right
endShape(CLOSE);
}