Skip to content

Instantly share code, notes, and snippets.

@neogeek
Created August 30, 2020 02:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neogeek/a648752a4cad67b7713c988fbc1f3e2f to your computer and use it in GitHub Desktop.
Save neogeek/a648752a4cad67b7713c988fbc1f3e2f to your computer and use it in GitHub Desktop.
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