xxxxxxxxxx
52
let fortunes = [];
let printing = false;
function preload() {
fortunes = loadStrings("fortunes.txt");
}
function setup() {
createCanvas(500, 500);
textAlign(CENTER);
textWrap(WORD);
textFont("Syne Mono");
fill(255);
if (fortunes == null) {
print("Error reading from file.");
while (1) {}
}
start();
}
function start() {
if (printing == false) {
printing = true;
typeWriter(random(fortunes), 0, 50, height / 2, 80);
}
}
function mouseClicked() {
start();
}
function typeWriter(f, n, x, y, s) {
if (n < f.length) {
background(0);
textSize(20);
text("YOUR FORTUNE IS:", width / 2, height / 2 - 30);
text(f.substring(0, n + 1) + "_", x, y, 400, 250);
n++;
setTimeout(function () {
typeWriter(f, n, x, y, s);
}, s);
} else {
printing = false;
}
textSize(10);
text("click anywhere to see what happens :)", width - 105, height - 5);
}
function draw() {
//background(200);
}