|
|
|
@ -2,6 +2,7 @@ var canvas; |
|
|
|
|
var needsRedraw = false; |
|
|
|
|
|
|
|
|
|
var waifuImgs = new Array(); |
|
|
|
|
var waifuColour = "#FFF"; |
|
|
|
|
|
|
|
|
|
var blurTime = 8; |
|
|
|
|
var blurIterations = 20; |
|
|
|
@ -16,9 +17,18 @@ waifuCanvas = {}; |
|
|
|
|
|
|
|
|
|
waifuCanvas.init = function() { |
|
|
|
|
canvas = document.getElementById("waifu").getContext("2d"); |
|
|
|
|
window.addEventListener('resize', waifuCanvas.resize); |
|
|
|
|
waifuCanvas.resize(); |
|
|
|
|
canvas.drawImage(waifuImgs[0], 0, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
waifuCanvas.resize = function() { |
|
|
|
|
// height is constant 720px, we expand width to suit
|
|
|
|
|
var ratio = window.innerWidth / window.innerHeight; |
|
|
|
|
canvas.canvas.width = 720 * ratio + 1; |
|
|
|
|
needsRedraw = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
waifuCanvas.preload = function() { |
|
|
|
|
for(var waifu in waifus) { |
|
|
|
|
newImg = new Image(); |
|
|
|
@ -29,22 +39,45 @@ waifuCanvas.preload = function() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
waifuCanvas.redraw = function() { |
|
|
|
|
canvas.clearRect(0,0,1280,720); |
|
|
|
|
var offset; // for centering/right/left align
|
|
|
|
|
var width = canvas.canvas.width; |
|
|
|
|
var image = waifuImgs[nCurrentWaifu]; |
|
|
|
|
// white BG for the hard light filter
|
|
|
|
|
canvas.globalAlpha = 1; |
|
|
|
|
canvas.globalCompositeOperation = "source-over"; |
|
|
|
|
canvas.fillStyle = "#FFF"; |
|
|
|
|
canvas.fillRect(0,0,width,720); |
|
|
|
|
|
|
|
|
|
switch(waifus[nCurrentWaifu].align) { |
|
|
|
|
case "left": |
|
|
|
|
offset = 0; |
|
|
|
|
break; |
|
|
|
|
case "right": |
|
|
|
|
offset = width - image.width; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
offset = width/2 - image.width/2; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(xBlur) { |
|
|
|
|
canvas.globalAlpha = 1/blurIterations; |
|
|
|
|
for(var i=blurMin; i<blurMax; i++) { |
|
|
|
|
canvas.drawImage(waifuImgs[nCurrentWaifu], blurDistance * i * xBlur, 0); |
|
|
|
|
canvas.drawImage(image, blurDistance * i * xBlur + offset, 0); |
|
|
|
|
} |
|
|
|
|
} else if(yBlur) { |
|
|
|
|
canvas.globalAlpha = 1/blurIterations; |
|
|
|
|
for(var i=blurMin; i<blurMax; i++) { |
|
|
|
|
canvas.drawImage(waifuImgs[nCurrentWaifu], 0, blurDistance * i * yBlur); |
|
|
|
|
canvas.drawImage(image, offset, blurDistance * i * yBlur); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
canvas.globalAlpha = 1; |
|
|
|
|
canvas.drawImage(waifuImgs[nCurrentWaifu], 0, 0); |
|
|
|
|
canvas.drawImage(image, offset, 0); |
|
|
|
|
} |
|
|
|
|
canvas.globalAlpha = 0.7; |
|
|
|
|
canvas.fillStyle = waifuColour; |
|
|
|
|
canvas.globalCompositeOperation = "hard-light"; |
|
|
|
|
canvas.fillRect(0,0,width,720); |
|
|
|
|
|
|
|
|
|
needsRedraw = false; |
|
|
|
|
} |
|
|
|
@ -64,19 +97,11 @@ waifuCanvas.animationLoop = function() { |
|
|
|
|
|
|
|
|
|
waifuCanvas.newWaifu = function() { |
|
|
|
|
GetRandomWaifu(); // increments the waifu counter
|
|
|
|
|
var style = document.getElementById("waifu").style; |
|
|
|
|
style["margin-right"] = "auto"; |
|
|
|
|
style["margin-left"] = "auto"; |
|
|
|
|
switch(waifus[nCurrentWaifu].align) { |
|
|
|
|
case "left": |
|
|
|
|
style["margin-left"] = "0"; |
|
|
|
|
break; |
|
|
|
|
case "right": |
|
|
|
|
style["margin-right"] = "0"; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
needsRedraw = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
waifuCanvas.setColour = function(colour) { |
|
|
|
|
waifuColour = colour; |
|
|
|
|
needsRedraw = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|