xxxxxxxxxx
// Configuration variables
let columns = 20;
let rows = 15;
let minBarWidthPercentage = 0.5; // Minimum width of the bar as a percentage of the cell width
let maxBarWidthPercentage = 1.0; // Maximum width of the bar as a percentage of the cell width
function setup() {
createCanvas(400, 400);
background(255); // White background
noLoop(); // No continuous loop
fill(0); // Black color for bars
// Calculating cell dimensions based on the canvas size and number of columns/rows
let w = width / columns;
let h = height / rows;
// Iterate through each position in the grid
for (let i = 0; i < columns; i++) {
for (let j = 0; j < rows; j++) {
// Calculate width of the bar based on configuration percentages
let barWidth = random(minBarWidthPercentage * w, maxBarWidthPercentage * w);
// Position for the bar
let x = i * w + (w - barWidth) / 2;
let y = j * h;
// Draw the bar
rect(x, y, barWidth, h);
}
}
}
function draw() {
// All drawing is done in setup
}