improved drawPolygon, changed inner hex

This commit is contained in:
Michael Yang 2014-05-24 15:06:57 -04:00
parent af612dcedb
commit 19fa87eb5a
3 changed files with 16 additions and 27 deletions

View file

@ -270,7 +270,7 @@ function Clock(sideLength) {
}
ctx.shadowColor = '#2980b9';
ctx.shadowBlur = 15;
drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle, this.fillColor);
drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle, this.fillColor, 0, 'rgba(0,0,0,0)');
clearShadows();
};
}

View file

@ -179,6 +179,7 @@ function update() {
function render() {
ctx.clearRect(0, 0, canvas.originalWidth, canvas.originalHeight);
clearGameBoard();
drawPolygon(canvas.originalWidth / 2 , canvas.originalHeight / 2 , 6, 220, 30, 'lightgrey', 0, 'rgba(0,0,0,0)');
var i;
for (i in MainClock.blocks) {
for (var j = 0; j < MainClock.blocks[i].length; j++) {
@ -192,7 +193,7 @@ function render() {
}
MainClock.draw();
drawPolygon(canvas.originalWidth / 2 , canvas.originalHeight / 2 , 6, 220, 30, '#BDA0CB', false,6);
// drawPolygon(canvas.originalWidth / 2 , canvas.originalHeight / 2 , 6, 220, 30, '#BDA0CB', false,6);
}
function stepInitialLoad() {

View file

@ -48,29 +48,20 @@ function clearShadows() {
function clearGameBoard() {
// ctx.shadowColor = '#2980b9';
// ctx.shadowBlur = 25;
drawPolygon(canvas.originalWidth / 2, canvas.originalHeight / 2, 6, canvas.originalWidth / 2 - 25, 30, hexagonBackgroundColor);
drawPolygon(canvas.originalWidth / 2, canvas.originalHeight / 2, 6, canvas.originalWidth / 2 - 25, 30, hexagonBackgroundColor, 0, 'rgba(0,0,0,0)');
// clearShadows();
}
function drawPolygon(x, y, sides, radius, theta, color, fill, lineWidth) { // can make more elegant, reduce redundancy, fix readability
if (fill == undefined) {
fill = true;
}
if (lineWidth == undefined) {
lineWidth = 3;
}
if (fill) {
ctx.fillStyle = color;
} else {
// ctx.shadowColor = '#2980b9';
// ctx.shadowColor = color;
// ctx.shadowColor = '#2ecc71';
// ctx.shadowBlur = 10;
// ctx.strokeStyle = rgba(0,0,0,0);
ctx.lineWidth = lineWidth;
ctx.strokeStyle = color;
}
function drawPolygon(x, y, sides, radius, theta, fillColor, lineWidth, lineColor) { // can make more elegant, reduce redundancy, fix readability
ctx.fillStyle = fillColor;
// ctx.shadowColor = '#2980b9';
// ctx.shadowColor = color;
// ctx.shadowColor = '#2ecc71';
// ctx.shadowBlur = 10;
// ctx.strokeStyle = rgba(0,0,0,0);
ctx.lineWidth = lineWidth;
ctx.strokeStyle = lineColor;
ctx.beginPath();
var coords = rotatePoint(0, radius, theta);
ctx.moveTo(coords.x + x, coords.y + y);
@ -84,11 +75,8 @@ function drawPolygon(x, y, sides, radius, theta, color, fill, lineWidth) { // ca
oldY = coords.y;
}
ctx.closePath();
if (fill) {
ctx.fill();
} else {
ctx.stroke();
}
ctx.fill();
ctx.stroke();
};
function showHighScores() {