This commit is contained in:
gavin
2018-08-04 18:10:18 +00:00
committed by Gitea
parent d147a520bb
commit 56a769588d
4 changed files with 166 additions and 67 deletions

View File

@@ -2,7 +2,8 @@ import {FLAT, POINTY} from './consts.js';
import {range, toFixed} from './utils.js';
const DEFAULTS = {
pipScale: 0.05,
flagScale: 0.5,
pipScale: 0.15,
pipDistance: 0.4,
};
@@ -39,27 +40,33 @@ export default class DrawHexagon {
this.hexPips[FLAT] = [];
this.hexPips[POINTY] = [];
const getFlatVertex = ([x, y]) => [x ? this.flatTopCornerX[x - 1] : 0, y ? this.flatTopCornerY[y - 1] : 0];
const flatPipVerticesX = [0].concat(this.flatTopCornerX);
const flatPipVerticesY = [0].concat(this.flatTopCornerY);
const getFlatVertex = n => [flatPipVerticesX[n], flatPipVerticesY[n]];
// start with 0,0 as center
this.hexPips[FLAT][1] = [[0, 0]].map(getFlatVertex);
this.hexPips[FLAT][2] = [[1, 1], [4, 4]].map(getFlatVertex);
this.hexPips[FLAT][3] = [[1, 1], [3, 3], [5, 5]].map(getFlatVertex);
this.hexPips[FLAT][4] = [[0, 0], [2, 2], [4, 4], [6, 6]].map(getFlatVertex);
this.hexPips[FLAT][5] = [[0, 0], [2, 2], [3, 3], [5, 5], [6, 6]].map(getFlatVertex);
this.hexPips[FLAT][6] = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]].map(getFlatVertex);
this.hexPips[FLAT][7] = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]].map(getFlatVertex);
this.hexPips[FLAT][1] = [0].map(getFlatVertex);
this.hexPips[FLAT][2] = [1, 4].map(getFlatVertex);
this.hexPips[FLAT][3] = [1, 3, 5].map(getFlatVertex);
this.hexPips[FLAT][4] = [0, 2, 4, 6].map(getFlatVertex);
this.hexPips[FLAT][5] = [0, 2, 3, 5, 6].map(getFlatVertex);
this.hexPips[FLAT][6] = [1, 2, 3, 4, 5, 6].map(getFlatVertex);
this.hexPips[FLAT][7] = [0, 1, 2, 3, 4, 5, 6].map(getFlatVertex);
const getPointyVertex = ([x, y]) => [x ? this.pointyTopCornerX[x - 1] : 0, y ? this.pointyTopCornerY[y - 1] : 0];
const pointyPipVerticesX = [0].concat(this.pointyTopCornerX);
const pointyPipVerticesY = [0].concat(this.pointyTopCornerY);
const getPointyVertex = n => [pointyPipVerticesX[n], pointyPipVerticesY[n]];
// start with 0,0 as center
this.hexPips[POINTY][1] = [[0, 0]].map(getPointyVertex);
this.hexPips[POINTY][2] = [[2, 2], [5, 5]].map(getPointyVertex);
this.hexPips[POINTY][3] = [[1, 1], [3, 3], [5, 5]].map(getPointyVertex);
this.hexPips[POINTY][4] = [[0, 0], [2, 2], [4, 4], [6, 6]].map(getPointyVertex);
this.hexPips[POINTY][5] = [[0, 0], [1, 1], [3, 3], [4, 4], [6, 6]].map(getPointyVertex);
this.hexPips[POINTY][6] = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]].map(getPointyVertex);
this.hexPips[POINTY][7] = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]].map(getPointyVertex);
this.hexPips[POINTY][1] = [0].map(getPointyVertex);
this.hexPips[POINTY][2] = [2, 5].map(getPointyVertex);
this.hexPips[POINTY][3] = [1, 3, 5].map(getPointyVertex);
this.hexPips[POINTY][4] = [0, 2, 4, 6].map(getPointyVertex);
this.hexPips[POINTY][5] = [0, 1, 3, 4, 6].map(getPointyVertex);
this.hexPips[POINTY][6] = [1, 2, 3, 4, 5, 6].map(getPointyVertex);
this.hexPips[POINTY][7] = [0, 1, 2, 3, 4, 5, 6].map(getPointyVertex);
}
outline(context, scale, x, y, cell) {
@@ -103,7 +110,7 @@ export default class DrawHexagon {
const y = cellY + (pipDistance * vertexY);
context.moveTo(x, y);
context.arc(x, y, pipRadius*3, 0, Math.PI*2, true);
context.arc(x, y, pipRadius, 0, Math.PI*2, true);
}
pips(context, scale, x, y, cell) {
@@ -123,5 +130,16 @@ export default class DrawHexagon {
context.fill();
}
}
flag (context, scale, x, y) {
context.beginPath();
context.moveTo(x, y);
context.arc(x, y, scale * this.settings.flagScale, 0, Math.PI*2, true);
context.closePath();
context.fillStyle = 'rgb(255,0,0)';
context.fill();
}
}