xxxxxxxxxx
123
let NYTdata;
let note = "What you can see is what media want you to see.\nWhat you have known is what media want you to know.";
let manifesto = [];
let time;
let nytapi = "https://api.nytimes.com/svc/search/v2/articlesearch.json?q=";
let keyword;
let apikey = "&api-key=gYvSJ5GMWAbghAFyGDfvT3FzTsO9nGDB"
let din;
let poem = [];
function preload() {
din = loadFont('DIN-Bold.otf');
}
function setup() {
createCanvas(600, 600);
background(255);
fill(0);
noStroke();
textFont(din);
input = createInput();
input.position(20, 140);
button = createButton('submit');
button.mousePressed(submit);
button.position(175, 140);
button2 = createButton('clear');
button2.mousePressed(cleararray);
button2.position(20, height - 120);
for (let i = 0; i < 10; i++) {
poem[i] = new poems("", width / 2, 170 + i * 20, 0);
}
}
function cleararray() {
manifesto = [];
fill(255);
noStroke();
rect(20, 121, width, 200);
}
function whisper() {
textAlign(LEFT, CENTER);
textSize(16);
textLeading(24);
text(note, 20, height - 70);
text("Type what you want to say word by word, and the words will change the size based on the its frequency on New York Times.n/Eventually, it will make up a poem which is written by you but controlled by the media actually.", 20, 20, width / 2, 120);
}
function submit() {
keyword = input.value();
let nytUrl = nytapi + keyword + apikey;
append(manifesto, keyword);
loadJSON(nytUrl, gotdata);
console.log(nytUrl);
}
function gotdata(data) {
NYTdata = data;
}
function draw() {
background(255);
whisper();
textAlign(CENTER);
fill(255);
noStroke();
// rect(20,130,width,height - 250);
fill(0);
if (NYTdata) {
for (let i = 0; i < manifesto.length; i++) {
let time = map(NYTdata.response.meta.time, 10, 1000, 5, 60);
poem[i].z = manifesto[i];
poem[i].x = width / 2;
poem[i].y = 170 + i * 20;
poem[i].s = time;
poem[i].display();
}
}
}
// for (let i = 0; i < 10; i++) {
// let time = map(NYTdata.response.meta.time, 10, 1000, 5, 60);
// poem[i].constructor(manifesto[i], width / 2, 170 + i * 30, time)
// if (time > 5) {
//
// let b=new poems(manifesto[i],width/2,170+i*20,time);
// poem.push[i];
// poem[i].display();
// }
// if (NYTdata) {
// let time = map(NYTdata.response.meta.time, 10, 1000, 5, 60);
// let b = new poems(manifesto[i], width / 2, 170 + i * 20, time);
// poem.push(b);
// }
// pop();
class poems {
constructor(z, x, y, s) {
this.x = width / 2;
this.z = z;
this.y = y;
this.s = s;
}
display() {
noStroke();
textSize(this.s);
text(this.z, this.x, this.y);
}
}