var can, ctx, vid, play, vidTimer, mouseIsDown = 0, knobMid, pixData, pixels, knobX = 100;
function init() {
vid = document.getElementById("hm_realvideo");
play = document.getElementById("play");
can = document.getElementById("hm_animcanvas");
ctx = can.getContext('2d');
vid.addEventListener('ended', vidEnd, false);
vid.addEventListener('play', vidSet, false);
knobMid = knob.offsetWidth / 2;
showVid();
}
function vidSet() {
clearTimeout(vidTimer);
vidTimer = setTimeout(showVid, 25);
}
function showVid() {
ctx.drawImage(vid, 0, 0);
processImage();
if (!document.querySelector("video").paused)
// Repeat 40 times a second to oversample 30 fps video
vidTimer = setTimeout(showVid, 25);
}
function processImage() {
// get pixel data for entire canvas
pixels = ctx.getImageData(0, 0, can.width, can.height);
pixData = pixels.data;
// set alpha value using slider
var alphaVal = parseInt(knobX * 2.55)
// for each pixel
for (i = 0; i < can.width * can.height; i++) {
// get combined rgb value to determine brightness
var rgbVal = pixData[i * 4] + pixData[i * 4 + 1] + pixData[i * 4 + 2];
// set alpha value for dark pixels to knob value
if (rgbVal < 150) pixData[i * 4 + 3] = alphaVal;
}
// put modified data back into image object
pixels.data = pixData;
// blit modified image object to screen
ctx.putImageData(pixels, 0, 0);
}
function playPauseVideo() {
if (play.value == "Play") {
vid.play();
play.value = "Pause";
} else {
vid.pause();
play.value = "Play";
}
}
function vidEnd() {
console.log(playing);
play.value = "Play";
}
function mouseDown() {
mouseIsDown = 1;
mouseXY();
}
function mouseUp() {
mouseIsDown = 0;
}
function mouseXY(e) {
if (mouseIsDown) {
if (!e) var e = event;
var mouseX = e.pageX - slider.offsetLeft;
if (mouseX >= 0 &&...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.