xxxxxxxxxx
86
let textData = [
"We swore when we took him in we put a stop to that rubbish,",
"said Uncle Vernon, swore we stamp it out of him! Wizard indeed!",
"You knew ?",
"said Harry. You knew I am a wizard?",
"Knew!",
"shrieked Aunt Petunia suddenly. Knew! Of course we knew!",
"How could you not be, my dratted sister being what she was? Oh, she got a letter just like that and disappeared off",
"to that -- that school -- and came home every vacation with her pockets full of frog spawn, turning teacups into rats.",
"I was the only one who saw her for what she was a freak! But for my mother and father, oh no, it was Lily this and Lily that,",
"they were proud of having a witch in the family!",
"She stopped to draw a deep breath and then went ranting on. It seemed she had been wanting to say all this for years.",
"Then she met that Potter at school and they left and got married and had you, and of course I knew you be just the same,",
"just as strange, just as abnormal and then, if you please, she went and got herself blown up and we got landed with you!",
"Harry had gone very white. As soon as he found his voice he said, Blown up? You told me they died in a car crash!",
"CAR CRASH!",
"roared Hagrid, jumping up so angrily that the Dursleys scuttled back to their corner.",
"How could a car crash kill Lily an' James Potter? It's an outrage! A scandal! Harry Potter not knowin' his own story when every kid in our world knows his name!",
"But why? What happened?",
"Harry asked urgently.",
"The anger faded from Hagrid's face. He looked suddenly anxious.",
"I never expected this, he said, in a low, worried voice. I had no idea, when Dumbledore told me there might be trouble gettin' hold of yeh, how much yeh didn't know.",
"Ah, Harry, I know if I am the right person ter tell yeh -- but someone's gotta -- yeh can't go off ter Hogwarts not knowin'.",
"He threw a dirty look at the Dursleys.",
"Well, it's best yeh know as much as I can tell yeh -- mind, I can't tell yeh everything, it's a great myst'ry, parts of it...",
"He sat down, stared into the fire for a few seconds, and then said, It begins, I suppose, with -- with a person called -- but it's incredible yeh don't know his name, everyone in our world knows--",
"Who?",
];
function setup() {
createCanvas(500, 500);
background(30); // Set background color to dark gray
drawWordCloud();
}
function drawWordCloud() {
let words = {};
let maxCount = 0;
let minCount = Number.MAX_SAFE_INTEGER;
// Count the frequency of each word
for (let i = 0; i < textData.length; i++) {
let tokens = textData[i].split(/\W+/);
for (let j = 0; j < tokens.length; j++) {
let word = tokens[j].toLowerCase();
if (word.length > 0) {
if (words[word] === undefined) {
words[word] = 1;
} else {
words[word]++;
}
if (words[word] > maxCount) {
maxCount = words[word];
}
if (words[word] < minCount) {
minCount = words[word];
}
}
}
}
for (let word in words) {
let wordSize = map(words[word], minCount, maxCount, 15, 70);
let textSizeVariation = random(0.8, 1.2);
let fontWeight = random(300, 700);
let grayValue = random(50, 200);
textSize(wordSize * textSizeVariation);
textStyle(NORMAL);
if (random() > 0.5) {
textStyle(BOLD);
}
fill(grayValue);
text(word, random(width), random(height));
}
}
function mousePressed() {
clear();
background(30);
drawWordCloud();
}