xxxxxxxxxx
71
//Create Constants for Words
const WORD0 = 0;
const WORD1 = 1;
const WORD2 = 2;
const WORD3 = 3;
const WORD4 = 4;
const WORD5 = 5;
const WORD6 = 6;
//Create Array for Words
let wordArray = [];
//Load CSV File
function preload() {
wordArray = loadStrings("thoughts.csv");
}
function setup() {
createCanvas(400, 400);
}
function draw() {
background(210);
//Create Array for 8 Lines of Poem
let lines = [];
//Load Array with 8 Blank Values
for (let i = 0; i < 8; i++) {
lines[i] = "";
}
//Create Array for Retrieving Words from CSV File Array
let singleRow = [];
//Retrieve Random Word from First Column of File Array
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
//Using Constant as Index Value, Load Array with Line 1 of Poem
lines[0] = "There we sat in the " + singleRow[WORD0] + ",";
//Repeat Process for Each Word and Line
//Line 2
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
lines[1] = "A space devoid of " + singleRow[WORD1] + ".";
//Line 3; Uses 2 Words
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
lines[2] = "We were " + singleRow[WORD2] + " about the " + singleRow[WORD3] + ".";
//Line 4
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
lines[3] = "Then, a" + singleRow[WORD4] + " call. Hark!";
//Line 5
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
lines[4] = "We looked up to witness a falling " + singleRow[WORD5] + ",";
//Line 6
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
lines[5] = "Large in size and " + singleRow[WORD6] + " in temperament."
//Line 7; Uses No Words
lines[6] = "We knew we could not stop it."
//Line 8; Uses First Word
lines[7] = "There we sat in the " + singleRow[WORD0] + ".";
//Display Poem
for (let i = 0; i < 8; i++) {
let xPos = 40;
let yPos = 95;
textSize(16);
textFont('Georgia');
text(lines[i], xPos, yPos + 30 * i);
}
//Stop Loop Until Mouse is Clicked
noLoop();
}
//New Poem is Generated When Mouse is Clicked
function mouseClicked() {
loop();
}