Created
August 30, 2020 02:02
-
-
Save neogeek/a648752a4cad67b7713c988fbc1f3e2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sampleColorFromVideo = (video, x, y) => { | |
const canvas = document.createElement('canvas'); | |
const context = canvas.getContext('2d'); | |
const width = video.clientWidth; | |
const height = video.clientHeight; | |
canvas.setAttribute('width', width); | |
canvas.setAttribute('height', height); | |
context.drawImage(video, 0, 0, width, height); | |
const pixels = context.getImageData(x, y, 1, 1).data; | |
return [pixels[0], pixels[1], pixels[2]]; | |
}; | |
document | |
.querySelector('#flip-jacks-video') | |
.addEventListener('loadeddata', () => { | |
document.querySelector( | |
'#flip-jacks' | |
).style.backgroundColor = `rgb(${sampleColorFromVideo( | |
document.querySelector('#flip-jacks-video'), | |
0, | |
0 | |
).join(',')})`; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment