Public
Edited
Feb 2, 2023
Insert cell
Insert cell
Insert cell
Insert cell
p5((s) => {
let system, x, y, n, w_diff, w, wds, rnd, wt;
x = 0;
y = 0;
n = form.words;
rnd = s.random(0.5);
wt = s.random(300);
w_diff = H / n;
wds = words(n);
// Color
let bg = getColor();

s.setup = function () {
s.createCanvas(W, H);
s.background(bg);
s.noStroke();
s.textSize(s.floor(H / n));
};
s.draw = function () {
if (!form.paint) {
s.background(bg);
}
for (let i = 1; i <= n; i++) {
w = wds[i];
align(i % 3);
if (s.random(1) > form.frequency) {
s.fill(255);
} else {
s.fill(0);
}
x = W * 0.5 + wt * s.sin((s.frameCount * rnd * i) / n);
y = -form.wiggle / 2 + s.floor(H / n) / 2 + w_diff * i;
s.text(w, x, y + form.wiggle * s.noise(x * 0.002, y * 0.002));
}
};

const align = (t) => {
switch (t) {
case 1:
s.textAlign(s.LEFT);
break;
case 2:
s.textAlign(s.CENTER);
break;
case 3:
s.textAlign(s.RIGHT);
break;
}
};
})
Insert cell
Insert cell
poem = "Madame Sosostris, famous clairvoyante, Had a bad cold, nevertheless Is known to be the wisest woman in Europe, With a wicked pack of cards. Here, said she, Is your card, the drowned Phoenician Sailor, (Those are pearls that were his eyes. Look!) Here is Belladonna, the Lady of the Rocks, The lady of situations. Here is the man with three staves, and here the Wheel, And here is the one-eyed merchant, and this card, Which is blank, is something he carries on his back, Which I am forbidden to see. I do not find The Hanged Man. Fear death by water. I see crowds of people, walking round in a ring. Thank you. If you see dear Mrs. Equitone, Tell her I bring the horoscope myself: One must be so careful these days."
Insert cell
note(
"These words come from the The Waste Land by T. S. Eliot and are a fun default way to generate interesting concepts on how we might create the bag of words from which the poem might be generated"
)
Insert cell
getWord = () => {
let w = form.text.split(" ");
return w[Math.floor(Math.random() * w.length)];
}
Insert cell
words = (n) => {
let arr = [];
for (let i = 0; i < n; i++) {
arr[i] = getWord();
}
return arr;
}
Insert cell
W = form.width
Insert cell
H = form.height
Insert cell
Insert cell
Insert cell
import { p5 } from "@tmcw/p5"
Insert cell
import { try_it, note } from "@observablehq/notes"
Insert cell
import { textcolor } from "@observablehq/text-color-annotations-in-markdown"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more