var debug = false; // set to true to show the hidden canvas used for pixel manipulations
var debugAvgColor = document.getElementById("debug-avg-color");
var gameOver = false;
var compositeOperation = "xor"; // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
// canvases container
var container = document.getElementById("container");
// bottom canvas
var bottomCanvas = document.getElementById("inside");
var bottomCtx = bottomCanvas.getContext("2d");
// middle canvas
var middleCanvas = document.getElementById("the-window");
var middleCtx = middleCanvas.getContext("2d");
// top canvas
var topCanvas = document.getElementById("dirty");
var topCtx = topCanvas.getContext("2d");
// hidden canvas (bitmask)
var mask = document.createElement("canvas");
var maskCtx = mask.getContext("2d");
mask.width = topCanvas.width;
mask.height = topCanvas.height;
// fill a black rectangle in the hidden canvas (at the same position of the "glass" and removing the borders)
maskCtx.fillStyle = "rgba(0,0,0,1)";
maskCtx.fillRect(15, 15, mask.width - 30, mask.height - 27);
maskCtx.globalCompositeOperation = compositeOperation;
// load images and draw each one on its respective canvas layer:
var dirty = new Image();
dirty.onload = function() {
middleCtx.drawImage(this, 0, 0);
// make the dirty darker with a dark semi-transparent overlay
middleCtx.fillStyle = "rgba(0, 0, 0, 0.7)";
middleCtx.fillRect(0, 0, middleCanvas.width, middleCanvas.height);
middleCtx.globalCompositeOperation = compositeOperation;
}
dirty.src = "https://dl.dropboxusercontent.com/s/q4pqim0v5q0u9pc/before.png";
var windowBars = new Image();
windowBars.onload = function() {
topCtx.drawImage(this, 0, 0);
}
windowBars.src = "https://dl.dropboxusercontent.com/s/p0pbkwi2kbg2e1m/bars.png";
var wally = new Image();
wally.onload = function() {
bottomCtx.drawImage(this, 0, 0, this.width, this.height, 0, 0, bottomCanvas.width, bottomCanvas.height);
//...
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.