xxxxxxxxxx
// Giphy-hyperslideshow -- Gets many transparent, non-animated GIFs from giphy and quickly collages them together.
//
//Code built on a Daniel Shiffman example: https://www.youtube.com/watch?v=mj8_w11MvH8&index=10&list=PLRqwX-V7Uu6a-SQiI4RtIwuOrLJGnel0r
//Register with Giphy to get your own key
//See the JSON here:
//http://api.giphy.com/v1/gifs/search?&api_key=Ln1OMDKTMpwmS1AX3OnlmVBfPsuSEkje&q=rainbow
var query = "&q=weird"; //change to make a different search query
//break the API call into parts. Make sure you are using https (http wont work with openProcessing which is https)
var api = "https://giphy.com/search/what?!-stickers";
var apiKey = "&api_key=Ln1OMDKTMpwmS1AX3OnlmVBfPsuSEkje";
// var apiKey = ["A6MgOoK9jJ0wFHnuM3rI9GzXLkrmAChZ", "cSsLBM6hA6jGEF5CySVunnXgEviMsWwF", "fpK8CwaWa9vraD6NFgEAjHMfnOTgvhZr"];
var images = [];
var frameSkip = 2;
function setup() {
createCanvas(windowWidth, windowHeight);
var url = api + apiKey + query; //concatenate api call
loadJSON(url, gotData);
}
function gotData(giphy) { //this is the function that is called after loadJSON is finished
for (var i = 0; i < giphy.data.length; i++) {
loadImage(giphy.data[i].images.downsized.url, gotImage); //loadImage can also be a callback, call gotImage after the image is loaded
}
}
function gotImage(giphyImg) { //this is the function that is called after loadImage is finished
images.push(giphyImg); //push image onto image array
}
function draw(){
if (images.length > 0 && frameCount % frameSkip == 0) {
var i = (frameCount / frameSkip) % images.length;
imageMode(CENTER);
image(images[i], random(width), random(height)); //display each image
}
}