xxxxxxxxxx
55
var url;
var mediums = [];
var sizes = [];
var medSize = 0;
var count = 0;
function preload() {
var API_KEY = '92a293ab-3ce4-4311-9070-11d9921d12a1';
var query = 'medium';
var params = '&size=50'
url = 'https://api.harvardartmuseums.org/' + query + '?apikey=' + API_KEY + params;
loadJSON(url, gotResponse)
}
function gotResponse(response) {
var totalPages = response.info.pages;
for (var currentPage = 1; currentPage <= totalPages; currentPage += 1) {
url = url + '&page=' + currentPage;
loadJSON(url, gotPages)
}
}
function gotPages(response) {
for (var i = 0; i < response.records.length; i++) {
var med = response.records[i].name;
var freq = response.records[i].objectcount;
if (!mediums.includes(med)){
mediums = mediums.concat(med);
sizes = sizes.concat(freq)
medSize ++;
if (med == "Pb") console.log(response.records[i]);
}
}
}
function setup() {
createCanvas(400, 400);
console.log(mediums);
title = createElement('h2', 'Top Mediums!');
title.position(10,5);
legend = createElement('h2', 'Frequency in Collections: Medium').style('text-indent', '20px').style('font-size', '12pt').position(10, 30 * count + 55);
count++;
for (var i = 0; i < medSize; i++) {
if (sizes[i] > 300) {
label = createElement('h3', sizes[i]+ ': ' + mediums[i]).style('text-indent', '20px').style('font-size', '12pt').position(10, 30 * count + 55);
count++;
}
}
}
function draw() {
background(240);
}