xxxxxxxxxx
// Remember to Cite Sources
let afinn;
let tree1;
let tree1pos = {};
let data = [];
let leaf;
let rose;
function preload() {
afinn = loadJSON('afinn111.json');
tree1 = loadImage('tree1.png');
tree1pos = loadJSON('tree1.json', loadTreeData);
leaf = loadImage('leaf.png');
rose = loadImage('rose.png');
}
function loadTreeData(jsonData) {
let flowerData = jsonData["data"];
for (var i = 0; i < 1; i++) {
// Get each object in the array
var flower = flowerData[i];
// Get x,y from position
var flowerX = flower[0];
var flowerY= flower[1];
// Put object in array
data.push(new Flowers(flowerX, flowerY));
}
}
function setup() {
createCanvas(600, 600);
pixelDensity(1);
console.log(afinn);
var txt = select('#txt');
txt.input(sentimentAnalysis);
}
function sentimentAnalysis() {
var textinput = txt.value();
var words = textinput.split(/\W/);
console.log(words);
var scoredwords = [];
var totalScore = 0;
for (var i = 0; i < words.length; i++) {
var word = words[i].toLowerCase();
if (afinn.hasOwnProperty(word)) {
var score = afinn[word];
console.log(word, score);
totalScore += Number(score);
scoredwords.push(word + ': ' + score + ' ');
}
}
var scorePar = select('#scoreP');
scorePar.html('score: ' + totalScore);
var comp = select('#comparativeP');
comp.html('comparative: ' + totalScore / words.length);
var wordlist = select('#wordlistP');
wordlist.html(scoredwords);
}
function draw() {
background(255);
image(tree1, 0, 0);
for(var i=0; i<data.length;i++){
data[i].show();
console.log(i, data[i].x, data[i].y);
}
// //leaf maker
// // for (let i = 0; i < allWordCounter; i++) {
// // leafy.push(new Leaves);
// // leafy[i].show();
// // }
// //flower maker
// for (let i = 0; i < allWordCounter; i++) {
// flowerImg.push(new Flowers(10,10));
// flowerImg[i].show();
// }
}
// class Leaves {
// constructor(x, y) {
// this.x = random(1,100);
// this.y = -100;
// this.leafy = loadImage("leaf.png");
// }
// show() {
// image(this.leafy, this.x, this.y);
// }
// }
class Flowers {
constructor(x, y) {
this.x = x;
this.y = y;
this.flowerImg = loadImage("rose.png");
}
show() {
image(this.flowerImg, this.x, this.y, 10, 10);
}
}