xxxxxxxxxx
99
let words = []; // Array of Word objects
let csvLines = []; // For csv data
let wordCap = 50;//setting a cap for the amount of words that can appear on the screen
function preload(){
csvLines = loadStrings('output-onlinetools-2.csv');//preloading a CSV file with a random selection of words
}
function setup() {
createCanvas(400, 400);
newFont = loadFont('GajrajOne-Regular.ttf');//loading a font
//print(csvLines);
// Get the words from line 1 of the csv
// TODO - randomly choose which line
csvWords = split(csvLines[0], ",");
print(csvWords);
// Create the Words
for (let i = 0; i<wordCap; i++) {
// Choose a random word for the Word instance
let randomWord = random(csvWords);
// Create the Word
words[i] = new Word(randomWord);//allows more words to appear
}
}
function draw() {
background(0);
angleMode(DEGREES);
for (let i = 0; i<wordCap; i++){
words[i].display();//creating a function for words to be shown
}
}
function mousePressed(){
for (let i = 0;i<wordCap;i++){
words[i].changeWordPosition();
}//changes the speed and the position of the words
}
class Word {
constructor (word, textX, textY, Size, storkeThickness,newWord,speed,textColor){
this.originalWord = word;
this.word = word;
this.textX = random (350);
this.textY = random(350);
this.Size = random(50);
this.strokeThickness = random(5);
this.speed = 1;
this.textColor = random(250);
}
display(){
fill(this.textColor);
// Make text brighter each frame
this.textColor = this.textColor+1;
// Shuffle word at certain time
if (this.textColor > 100) {
if (this.word == this.originalWord) {
// TODO something
}
}
// Reset if too bright
if (this.textColor >= 250) {
this.textColor = 0; // Black
this.word = this.originalWord;
}
textSize (this.Size);
textFont(newFont);
this.textX = this.textX + 1;//allows the words to move to the right
text(this.word,this.textX,this.textY);
if(this.textX>400) {
this.textX = -70;//allows the word to move back to its initial position
}
}
changeWordPosition(){
background(random(250));
fill(this.textColor);
this.textX = random (350);
this.textY = random(350);
this.Size = random(50);
this.strokeThickness = random(5);
this.speed = 1;
text(splitString,this.textX,this.textY);
this.speed = this.speed + random(5);//changes the speed of the word upon clicking the mouse
}
}