Skip to content

Instantly share code, notes, and snippets.

@khoparzi
Created May 24, 2019 06:02
Show Gist options
  • Save khoparzi/ad2f3b8dd88f4a72a6bd9d2d598ec8d2 to your computer and use it in GitHub Desktop.
Save khoparzi/ad2f3b8dd88f4a72a6bd9d2d598ec8d2 to your computer and use it in GitHub Desktop.
// Importing GIPHY gifs in Hydra
// NPM install https://github.com/Giphy/giphy-js-sdk-core
var GphApiClient = require('giphy-js-sdk-core')
giffer = GphApiClient(<YourGiphyApiKey>)
// With p5
p = new P5()
s0.init({src: p.canvas})
p.hide()
let img;
// Remove old image element before making a new one
if (img.elt != null) { img.remove() }
giffer.search('gifs', {"q": "hydra", "limit": 1, "offset": 5})
.then((response) => {
response.data.forEach((gifObject) => {
img = p.createImg(gifObject.images.original.url)
img.elt.style.zIndex = -10 // Push back the image element
// Connect the canvas to buffer after loading image
img.elt.onload = () => {
s0.init({src: img.elt})
}
})
})
p.draw = () => {
img.position(100,0)
}
src(s0).scale(1,1.7,1)
.repeat(5)
.out()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment