xxxxxxxxxx
66
function setup() {
createCanvas(800, 600);
noLoop(); // Prevent continuous drawing
textAlign(CENTER, CENTER); // Center text alignment
textFont("Courier New"); // Set the font to typewriter
textSize(5); // Set font size
pixelDensity(3);
}
function draw() {
background(255); // White background
let startY = height / 2 - (5 * 50) / 2; // Calculate starting Y position to center the stack
for (let i = 0; i < 5; i++) {
// Set a slight random rotation angle
let angle = random(-PI / 20, PI / 20); // Slight rotation between -9 and 9 degrees
// Save the current state
push();
// Translate to the center of the canvas
translate(width / 2, startY + i * 50 + 75); // Center X and adjust Y for each rectangle
// Rotate by the random angle
rotate(angle);
// Fill the rectangle with random 0s and 1s
fill(0); // Black color for the text
let rows = 10; // Number of rows
let cols = 50; // Number of columns
let w = 300 / cols; // Width of each column
let h = 50 / rows; // Height of each row
// Randomly choose a position to place "1956"
let randomRow = floor(random(rows));
let randomCol = floor(random(cols));
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
if (r === randomRow && c === randomCol) {
fill(255, 0, 0); // Set color to red for "1956"
textSize(12); // Set text size to 10 for "1956"
text("1956", c * w - 150 + w / 2, r * h - 75 + h / 2); // Draw "1956" at the chosen position
} else {
let randomValue = floor(random(2)); // Get random 0 or 1
fill(0);
textSize(10);
text(randomValue, c * w - 150 + w / 2, r * h - 75 + h / 2); // Draw the random value in the grid
}
}
}
// Restore the original state
pop();
}
}
//Save a 5-second GIF when the user presses the 's' key
function keyPressed() {
if (key === 's') {
saveGif('mySketch', 5);
}
}