Skip to content

Instantly share code, notes, and snippets.

@bevchou
Created November 28, 2017 08:26
Show Gist options
  • Save bevchou/08c8adc16a4c8f7bd4070557a9cd907a to your computer and use it in GitHub Desktop.
Save bevchou/08c8adc16a4c8f7bd4070557a9cd907a to your computer and use it in GitHub Desktop.
function updateNoun() {
//do not allow user to input white space or empty string into the word array
if (trim(nounInput.value()) != "") {
//push input to word array
nounArray.push(nounInput.value());
//display submitted words below input field
nounPara.push(createP(nounInput.value()));
for (let i = 0; i < nounPara.length; i++) {
nounPara[i].position(nounInpX, inpY + 20 * (i - 1));
}
//get photos from flickr
flickrQuery = nounInput.value();
flickrURL = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + apiKey + '&safe_search=1&sort=interestingness-desc&text=' + flickrQuery + '&format=json&nojsoncallback=1';
loadJSON(flickrURL, getPhotos);
//clear input field
nounInput.remove();
nounInput = createInput('');
nounInput.position(nounInpX, inpY + nounArray.length * 20);
}
return false;
}
//flickr loadJSON callback
function getPhotos(photoData) {
flickrData = photoData;
//once data loads
if (flickrData) {
for (let i = 0; i < numImgPerQuery; i++) {
let farmid = flickrData.photos.photo[i].farm;
let serverid = flickrData.photos.photo[i].server;
let id = flickrData.photos.photo[i].id;
let secret = flickrData.photos.photo[i].secret;
//create photo url
photoURL = 'https://farm' + farmid + '.staticflickr.com/' + serverid + '/' + id + '_' + secret + '_s.jpg';
//and create an array of img elements
let r = random(faceH / 2 + 20, vidWidth / 2 + 50);
let theta = 0;
let theta_vel = random(-.05, .05);
photoArray.push(new Imgcloud(loadImage(photoURL), r, theta, theta_vel));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment