added findCenterOfBlocks
This commit is contained in:
parent
cb42564bb3
commit
573f2c5afb
2 changed files with 23 additions and 0 deletions
22
js/Block.js
22
js/Block.js
|
@ -151,3 +151,25 @@ function Block(fallingLane, color, iter, distFromHex, settled) {
|
|||
ctx.globalAlpha = 1;
|
||||
};
|
||||
}
|
||||
|
||||
function findCenterOfBlocks(arr) {
|
||||
var avgDFH = 0;
|
||||
var avgAngle = 0;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
avgDFH += arr[i].distFromHex;
|
||||
while (arr[i].angle < 0) {
|
||||
arr[i].angle += 360;
|
||||
}
|
||||
|
||||
avgAngle += arr[i].angle % 360;
|
||||
}
|
||||
|
||||
avgDFH /= arr.length;
|
||||
avgAngle /= arr.length;
|
||||
|
||||
return {
|
||||
x:trueCanvas.width/2 + Math.cos(avgAngle * (Math.PI / 180)) * avgDFH,
|
||||
y:trueCanvas.height/2 + Math.sin(avgAngle * (Math.PI / 180)) * avgDFH
|
||||
}
|
||||
|
||||
}
|
|
@ -150,6 +150,7 @@ function Clock(sideLength) {
|
|||
else {
|
||||
this.angle += this.angularVelocity;
|
||||
}
|
||||
|
||||
drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle, this.fillColor, 0, 'rgba(0,0,0,0)');
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue