xxxxxxxxxx
function setup() {
createCanvas(1080, 726); // Set canvas size to match the image
// noLoop(); // Run the draw function only once
}
function draw() {
background(250); // A slightly off-white background
// Define the number of shapes and the palette of colors
let numberOfShapes = 1000;
let colors = [
color(255, 178, 102), // a light orange
color(153, 102, 255), // a soft purple
color(255, 153, 204), // a pink
color(204, 204, 255), // a light blue
color(255, 229, 204), // a peach
color(204, 255, 204) // a pale green
];
// Draw the rectangles
for (let i = 0; i < numberOfShapes; i++) {
// Randomize position, size, and color of the rectangles
let x = random(width);
let y = random(height);
let w = random(5, 20); // Width of the rectangle
let h = random(5, 20); // Height of the rectangle
let c = random(colors); // Choose a random color from the palette
fill(c);
noStroke();
rect(x, y, w, h); // Draw the rectangle
}
// After drawing everything, apply the texture
addTexture();
}
// Function to add texture to the background
function addTexture() {
loadPixels();
for (let i = 0; i < pixels.length; i += 4) {
let noise = random(-50, 50); // Generate a random value for the noise
pixels[i] += noise; // Add noise to the red channel
pixels[i+1] += noise; // Add noise to the green channel
pixels[i+2] += noise; // Add noise to the blue channel
// pixels[i+3] is the alpha channel
}
updatePixels();
}