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))], ',');
//Usi
//let word0 = singleRow[WORD0];
//lines[0] = "There we sat in the " + word0 + ",";
lines[0] = "There we sat in the " + singleRow[WORD0] + ",";
//Repeat Process for Each Word and Line
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
let word1 = singleRow[WORD1];
lines[1] = "A space devoid of " + word1 + ".";
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
let word2 = singleRow[WORD2];
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
let word3 = singleRow[WORD3];
lines[2] = "We were " + word2 + " about the " + word3 + ".";
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
let word4 = singleRow[WORD4];
lines[3] = "Then, a" + word4 + " call. Hark!";
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
let word5 = singleRow[WORD5];
lines[4] = "We looked up to witness a falling " + word5 + ",";
singleRow = split(wordArray[int(random(0, wordArray.length))], ',');
let word6 = singleRow[WORD6];
lines[5] = "Large in size and " + word6 + " in temperament."
lines[6] = "We knew we could not stop it."
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);
}
noLoop();
}
//New Poem is Generated When Mouse is Clicked
function mouseClicked() {
loop();
}