xxxxxxxxxx
// Create the canvas
function setup() {
createCanvas(480, 480);
drawPattern();
}
function draw() {
}
// Function to draw pattern
function drawPattern() {
background(255); // Set the background color to white
noStroke();
let cellSize = 50; // The side length of each cell
let spacing = 10; // Spacing between cells
for (let x = 0; x < width; x += cellSize + spacing) {
for (let y = 0; y < height; y += cellSize + spacing) {
let randomVal = random();
fill(0); // Fill the shape with black color
ellipse(x + cellSize / 2, y + cellSize / 2, cellSize); // Draw a circle
// Randomly remove a quarter (top, bottom, left, right)
if (randomVal < 0.25) {
rect(x, y, cellSize, cellSize / 2); // Top quarter
} else if (randomVal < 0.5) {
rect(x, y + cellSize / 2, cellSize, cellSize / 2); // Bottom quarter
} else if (randomVal < 0.75) {
rect(x, y, cellSize / 2, cellSize); // Left quarter
} else {
rect(x + cellSize / 2, y, cellSize / 2, cellSize); // Right quarter
}
}
}
}
// Redraw the pattern when the "B" key is pressed
function keyPressed() {
if (key === 'B' || key === 'b') {
drawPattern();
}
}
//https://tr.pinterest.com/pin/575686764883273069/ bu çizimden hareketle yapıldı.
//Ana desen yarım elips sekli.Çalışma boyunca bu kodun farklı yönlere hareket ederek oluşturduğu deseni görebiliriz.
//B harfine her bastığımızda yarım elipsler yön değiştirerek yeni bir şekil oluşturacak.