combinationLockPG/lock.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-03-11 08:11:56 +00:00
var context;
2014-03-11 08:24:07 +00:00
var lockinit = function () {
2014-03-11 08:11:56 +00:00
var canvas = document.getElementById("canvas");
context = canvas.getContext('2d');
drawLock();
drawDial(0);
}
var drawLock = function() {
context.save();
context.translate(100, 100);
context.fillStyle = "#999";
context.beginPath();
context.arc(0, 0, 100, 0, 2 * Math.PI);
context.closePath();
context.fill();
context.beginPath();
context.moveTo(0, - 82);
context.lineTo(- 6, - 95);
context.lineTo(+ 6, - 95);
context.closePath();
context.stroke();
context.restore();
}
var drawDial = function(rot) {
context.save();
context.translate(100, 100);
context.rotate(rot)
context.fillStyle = "#555";
context.beginPath();
context.arc(0, 0, 80, 0, 2 * Math.PI);
context.closePath();
context.fill();
context.fillStyle = "#111";
context.beginPath();
context.arc(0, 0, 7, 0, 2 * Math.PI);
context.closePath();
context.fill();
context.fillStyle = "#fff";
var num = 32;
for (var i = 0; i < num; i++) {
context.beginPath();
context.fillText(i, 72 * Math.cos(2 * Math.PI / num * i) - 7, 72 * Math.sin(2 * Math.PI / num * i) + 3);
context.closePath();
context.fill();
}
context.restore();
2014-03-16 11:30:15 +00:00
}