xxxxxxxxxx
72
//Citation: The sketch uses code from Daniel Shiffman's series of tutorials about API with some adjustment https://www.youtube.com/playlist?list=PLRqwX-V7Uu6a-SQiI4RtIwuOrLJGnel0r
let api = 'https://api.nytimes.com/svc/search/v2/articlesearch.json?';
let beginDate = 'begin_date=';
let endDate = '&end_date=';
let queryQ = '&q=LGBTQIA%2B&';
let queryH = '&q=anti%20lgbt%20hate%20crimes';
let apiKey = '&api-key=a9LMWhZ9ZHWOTHHNGNIWQVZ1ACeHhhnn';
var input;
let queerData;
let homophobData;
let flagImg;
function preload() {
flagImg = loadImage('assets/flag.png');
}
function setup() {
createCanvas(600, 600);
noStroke();
var button = select('#submit');
button.mousePressed(visualizeQData);
input = select('#getYear');
}
function visualizeQData() {
var urlQ = api + beginDate + input.value() + '0101' + endDate + input.value() + '1231' + queryQ + apiKey;
loadJSON(urlQ, gotQData);
var urlH = api + beginDate + input.value() + '0101' + endDate + input.value() + '1231' + queryH + apiKey;;
loadJSON(urlH, gotHData);
}
function gotQData(qdata) {
queerData = qdata;
}
function gotHData(hdata) {
homophobData = hdata;
}
function draw() {
background(255);
//Number of articles with keyword LGBTQIA
if (queerData) {
flagOpacity = queerData.response.meta.hits;
console.log(flagOpacity)
tint(255, flagOpacity*30);
image(flagImg, 0, 0, width, height);
}
//Number of articles with keyword homophobia
var w = 0.5;
var h = 0.5;
var x = 0;
var y = 0;
if (homophobData) {
console.log(homophobData.response.meta.hits);
fill(0);
for (i = 0; i < homophobData.response.meta.hits; i++) {
rect(x, y, 5, height);
x = x + 10;
}
}
}