Skip to content

Instantly share code, notes, and snippets.

@ronsims2
Created April 1, 2015 20:44
Show Gist options
  • Save ronsims2/6ffb7702aeedc2f77905 to your computer and use it in GitHub Desktop.
Save ronsims2/6ffb7702aeedc2f77905 to your computer and use it in GitHub Desktop.
Ninjafy
(function(d){
var drawNinja = function(){
//var wrapper = d.getElementById('wrapper');
var wrapper = d.getElementsByTagName('body');
//the ninja head
var ninjaCanvas = d.createElement('canvas');
ninjaCanvas.style.position = "absolute";
ninjaCanvas.style.zIndex = 9999999999;
ninjaCanvas.id = "ninjafied";
var ctx = ninjaCanvas.getContext("2d");
ctx.beginPath();
ctx.arc(100,75,50,0,2*Math.PI);
ctx.fillStyle = "rgb(0,0,0)";
ctx.closePath();
ctx.fill();
ctx.stroke();
//ninja mask eye cut outs
ctx.beginPath();
ctx.scale(1, 0.35);
ctx.arc(100,170,40,0,2*Math.PI);
ctx.fillStyle = "rgb(255,255,255)";
ctx.closePath();
ctx.fill();
ctx.stroke();
//eyeballs
ctx.scale(1, 2.5);
ctx.beginPath();
ctx.arc(80,67,8,0,2*Math.PI);
ctx.fillStyle = "rgb(0,0,0)";
ctx.closePath();
ctx.fill();
ctx.stroke();
//ctx.scale(1, 2.5);
ctx.beginPath();
ctx.arc(120,67,8,0,2*Math.PI);
ctx.fillStyle = "rgb(0,0,0)";
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = "rgb(255,0,0)";
ctx.font = "24px Arial Black";
ctx.fillText("Ninjafied!", 43, 20);
var kid = wrapper[0].childNodes.item(0);
if(kid){
wrapper[0].insertBefore(ninjaCanvas, kid);
}
else{
wrapper[0].appendChild(ninjaCanvas);
}
};
d.addEventListener("keyup",function(e){
if (e.keyCode === 78) {
var ninja = d.getElementById("ninjafied");
if(ninja){
d.body.removeChild(ninja);
}
else{
drawNinja();
}
}
});
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment