Skip to content

Instantly share code, notes, and snippets.

@buzzdecafe
Last active December 18, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzzdecafe/5784246 to your computer and use it in GitHub Desktop.
Save buzzdecafe/5784246 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<head>
<style>
#c {
border: 1px dotted #006;
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
(function() {
var r;
var c = document.getElementById("c");
var ctx = c.getContext("2d");
var globe = new Image();
globe.src = "globe.svg";
c.setAttribute("width", "700px");
c.setAttribute("height", "500px");
function clear() {
c.width = c.width;
}
globe.onload = function() {
var cw = c.width;
var cCtr = cw/2;
ctx.drawImage(globe, 0, -cCtr, cw, cw);
function mkSpin(ctx, image) {
var ctrX = cCtr;
var ctrY = 0;
return function rotate(angle) {
clear();
ctx.translate(ctrX, ctrY);
ctx.rotate(angle * TO_RADIANS);
ctx.drawImage(image, -cCtr, -cCtr, cw, cw);
};
}
r = mkSpin(ctx, globe);
};
var TO_RADIANS = Math.PI/180;
function clickHandler() {
var t = false;
return function(e) {
if (t) {
clearTimeout(t);
t = false;
} else {
t = setInterval((function() {
var i = 0;
return function() {
i = i + 10 % 360;
r(i);
};
})(), 20);
}
};
}
c.addEventListener("click", clickHandler());
}());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment