xxxxxxxxxx
55
/*
----- Coding Tutorial by Patt Vira -----
Name: Dynamic ASCII Art with Random Distribution and Colors
----------------------------------------
*/
let characters = [
{ char: "⌇", colors: ["#FFD700", "#FFCC00", "#FFC107", "#FFB300", "#FFA000"] },
{ char: "⥀", colors: ["#D3D3D3", "#A9A9A9", "#808080", "#696969", "#505050"] },
{ char: "⏚", colors: ["#4169E1", "#6A5ACD", "#8A2BE2", "#FF00FF", "#FF1493"] }
];
let currentSet = 0;
let size = 40;
let gridSize = 10;
let timer;
function setup() {
createCanvas(400, 400);
timer = millis();
}
function draw() {
background(0);
let elapsedTime = millis() - timer;
// Switch character set every 3 seconds
if (elapsedTime > 3000) {
currentSet = (currentSet + 1) % characters.length;
timer = millis();
}
let charSet = characters[currentSet];
for (let i = 0; i < gridSize; i++) {
for (let j = 0; j < gridSize; j++) {
// Randomly decide whether to draw a character in this grid cell
if (random() < 0.5) { // Adjust this value to control density
let x = i * (width / gridSize) + (width / gridSize) / 2;
let y = j * (height / gridSize) + (height / gridSize) / 2;
let char = charSet.char;
let col = random(charSet.colors);
fill(col);
noStroke();
textSize(size);
textAlign(CENTER, CENTER);
text(char, x, y);
}
}
}
}