xxxxxxxxxx
54
let fontsize = 20;
let corpus;
function preload() {
// Alexander Blok - 'The night, the pharmacy, the street'
poem = `The night, the pharmacy, the street,
The pointless lamppost in the mist.
A quarter century recedes –
There’s no escape. It all persists.
You’ll die – and you’ll begin anew,
As in the past, all will repeat:
The icy channel flowing through,
The lamp, the pharmacy, the street.`;
}
function setup() {
createCanvas(500, 500);
textSize(fontsize);
frameRate(3);
}
function draw() {
background(40);
textAlign(RIGHT);
drawWords(width * 0.7, height * 0.3);
textAlign(CENTER);
drawWords(width * 0.5, height * 0.5);
textAlign(LEFT);
drawWords(width * 0.3, height * 0.8);
}
function drawWords(x, y) {
let corpus = poem.split(' ').filter(y => y!="");
let first_word = floor(random(corpus.length));
let last_word = first_word + random(2, 8);
fill(255,233,0);
text(corpus.slice(first_word, last_word).join(' ').trim(), x, y);
}
function keyPressed(){
clear();
background(40);
text(poem,0.2*width,0.2*height);
}