2014-05-17 14:43:16 +00:00
|
|
|
//you can change these to sexier stuff
|
|
|
|
var colors = [
|
2014-05-17 16:50:12 +00:00
|
|
|
"black",
|
|
|
|
"orange",
|
|
|
|
"red",
|
|
|
|
"blue",
|
2014-05-17 14:43:16 +00:00
|
|
|
];
|
|
|
|
|
2014-05-17 16:50:12 +00:00
|
|
|
var Clock = function(sideLength) {
|
2014-05-17 15:03:11 +00:00
|
|
|
this.position = 0;
|
2014-05-17 16:50:12 +00:00
|
|
|
this.sides = 6;
|
2014-05-17 14:24:39 +00:00
|
|
|
this.blocks = [];
|
2014-05-17 16:50:12 +00:00
|
|
|
this.angle = 30;
|
|
|
|
this.sideLength = sideLength;
|
|
|
|
this.strokeColor = 'black';
|
|
|
|
this.x = canvas.width / 2;
|
|
|
|
this.y = canvas.height / 2;
|
|
|
|
|
|
|
|
for(var i=0; i< this.sides; i++) {
|
2014-05-17 14:24:39 +00:00
|
|
|
this.blocks.push([]);
|
|
|
|
}
|
2014-05-17 15:03:11 +00:00
|
|
|
|
|
|
|
this.addBlock = function(block) {
|
|
|
|
this.blocks[this.position].push(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.rotate = function(steps) {
|
2014-05-17 16:50:12 +00:00
|
|
|
this.positione += steps;
|
2014-05-17 15:03:11 +00:00
|
|
|
this.position = Math.abs(((this.position%sides)+this.position) % sides);
|
|
|
|
}
|
2014-05-17 16:50:12 +00:00
|
|
|
|
|
|
|
this.draw = function() {
|
|
|
|
this.drawPolygon(this.x, this.y, this.sides, this.sideLength, this.angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.drawPolygon = function(x, y, sides, radius, theta) { // can make more elegant, reduce redundancy, fix readability
|
|
|
|
ctx.beginPath();
|
|
|
|
var coords = rotatePoint(0, radius, theta);
|
|
|
|
ctx.moveTo(coords.x + x, coords.y + y);
|
|
|
|
var oldX = coords.x;
|
|
|
|
var oldY = coords.y;
|
|
|
|
for (var i = 0; i < sides; i++) {
|
|
|
|
coords = rotatePoint(oldX, oldY, 360 / sides);
|
|
|
|
ctx.lineTo(coords.x + x, coords.y + y);
|
|
|
|
ctx.moveTo(coords.x + x, coords.y + y);
|
|
|
|
oldX = coords.x;
|
|
|
|
oldY = coords.y;
|
|
|
|
// console.log(coords);
|
|
|
|
}
|
|
|
|
ctx.closePath();
|
|
|
|
// ctx.fill();
|
|
|
|
ctx.strokeStyle = this.strokeColor;
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
2014-05-17 14:24:39 +00:00
|
|
|
}
|