xxxxxxxxxx
61
let x, y;
let opacity = 255;
let iterations = 0;
const maxIterations = 500;
let arabicChars = [];
function setup() {
createCanvas(600, 600);
background(255);
x = width / 2;
y = height / 2;
pixelDensity(2);
// Generate a list of ASCII Arabic characters
for (let i = 0x0600; i <= 0x06FF; i++) {
arabicChars.push(String.fromCharCode(i));
}
}
function draw() {
if (iterations >= maxIterations) {
//noLoop(); // Stop the draw loop
return;
}
let charIndex = floor(random(arabicChars.length)); // Random character index
let char = arabicChars[charIndex]; // Get the character
let size = random(10, 40); // Random size between 5 and 20
textSize(size);
fill(random(255),random(255),random(255), opacity);
textAlign(CENTER, CENTER);
// Draw the character at the current position
text(char, x, y);
let direction = floor(random(4));
switch (direction) {
case 0: // Move up
y -= 10;
break;
case 1: // Move down
y += 10;
break;
case 2: // Move left
x -= 15;
break;
case 3: // Move right
x += 10;
break;
}
// Keep the characters within the canvas
x = constrain(x, 0, width / 2);
y = constrain(y, 0, height / 2);
iterations++;
opacity = max(0, opacity - 0.5); // Decrease opacity by 1, but not below 0
}