Flags (#12)
This commit is contained in:
@@ -2,7 +2,8 @@ import {sqrt2} from './utils.js';
|
||||
import {FLAT, POINTY} from './consts.js';
|
||||
|
||||
const DEFAULTS = {
|
||||
pipScale: 0.05,
|
||||
flagScale: 0.5,
|
||||
pipScale: 0.15,
|
||||
pipDistance: 0.4,
|
||||
};
|
||||
|
||||
@@ -19,31 +20,37 @@ export default class DrawSquare {
|
||||
this.squarePips[FLAT] = [];
|
||||
this.squarePips[POINTY] = [];
|
||||
|
||||
const getFlatVertex = ([x, y]) => [x ? this.squareX[x - 1] : 0, y ? this.squareY[y - 1] : 0];
|
||||
const flatPipVerticesX = [0].concat(this.squareX).concat([this.squareX[1], this.squareX[3], 0, 0]);
|
||||
const flatPipVerticesY = [0].concat(this.squareY).concat([0, 0, this.squareY[1], this.squareY[3]]);
|
||||
|
||||
const getFlatVertex = n => [flatPipVerticesX[n], flatPipVerticesY[n]];
|
||||
|
||||
// start with 0,0 as center
|
||||
this.squarePips[FLAT][1] = [[0, 0]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][2] = [[1, 1], [3, 3]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][3] = [[0, 0], [1, 1], [3, 3]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][4] = [[1, 1], [2, 2], [3, 3], [4, 4]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][5] = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][6] = [[1, 0], [1, 1], [2, 2], [3, 0], [3, 3], [4, 4]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][7] = [[0, 0], [1, 0], [1, 1], [2, 2], [3, 0], [3, 3], [4, 4]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][8] = [[0, 1], [0, 3], [1, 0], [1, 1], [2, 2], [3, 0], [3, 3], [4, 4]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][9] = [[0, 0], [0, 1], [0, 3], [1, 0], [1, 1], [2, 2], [3, 0], [3, 3], [4, 4]].map(getFlatVertex);
|
||||
this.squarePips[FLAT][1] = [0].map(getFlatVertex);
|
||||
this.squarePips[FLAT][2] = [1, 3].map(getFlatVertex);
|
||||
this.squarePips[FLAT][3] = [0, 1, 3].map(getFlatVertex);
|
||||
this.squarePips[FLAT][4] = [1, 2, 3, 4].map(getFlatVertex);
|
||||
this.squarePips[FLAT][5] = [0, 1, 2, 3, 4].map(getFlatVertex);
|
||||
this.squarePips[FLAT][6] = [1, 2, 3, 4, 5, 6].map(getFlatVertex);
|
||||
this.squarePips[FLAT][7] = [0, 1, 2, 3, 4, 5, 6].map(getFlatVertex);
|
||||
this.squarePips[FLAT][8] = [1, 2, 3, 4, 5, 6, 7, 8].map(getFlatVertex);
|
||||
this.squarePips[FLAT][9] = [0, 1, 2, 3, 4, 5, 6, 7, 8].map(getFlatVertex);
|
||||
|
||||
const getPointyVertex = ([x, y]) => [x ? this.diamondX[x - 1] : 0, y ? this.diamondY[y - 1] : 0];
|
||||
const pointyPipVerticesX = [0].concat(this.diamondX).concat([this.diamondX[4], this.diamondX[5]]);
|
||||
const pointyPipVerticesY = [0].concat(this.diamondY).concat([this.diamondY[5], this.diamondY[4]]);
|
||||
|
||||
const getPointyVertex = n => [pointyPipVerticesX[n], pointyPipVerticesY[n]];
|
||||
|
||||
// start with 0,0 as center
|
||||
this.squarePips[POINTY][1] = [[0, 0]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][2] = [[1, 1], [3, 3]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][3] = [[0, 0], [1, 1], [3, 3]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][4] = [[1, 1], [2, 2], [3, 3], [4, 4]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][5] = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][6] = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][7] = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][8] = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [5, 6], [6, 5], [6, 6]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][9] = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [5, 6], [6, 5], [6, 6]].map(getPointyVertex);
|
||||
this.squarePips[POINTY][1] = [0].map(getPointyVertex);
|
||||
this.squarePips[POINTY][2] = [1, 3].map(getPointyVertex);
|
||||
this.squarePips[POINTY][3] = [0, 1, 3].map(getPointyVertex);
|
||||
this.squarePips[POINTY][4] = [1, 2, 3, 4].map(getPointyVertex);
|
||||
this.squarePips[POINTY][5] = [0, 1, 2, 3, 4].map(getPointyVertex);
|
||||
this.squarePips[POINTY][6] = [1, 2, 3, 4, 5, 6].map(getPointyVertex);
|
||||
this.squarePips[POINTY][7] = [0, 1, 2, 3, 4, 5, 6].map(getPointyVertex);
|
||||
this.squarePips[POINTY][8] = [1, 2, 3, 4, 5, 6, 7, 8].map(getPointyVertex);
|
||||
this.squarePips[POINTY][9] = [0, 1, 2, 3, 4, 5, 6, 7, 8].map(getPointyVertex);
|
||||
}
|
||||
|
||||
fill(context, scale, x, y, cell) {
|
||||
@@ -83,7 +90,7 @@ export default class DrawSquare {
|
||||
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) {
|
||||
@@ -103,5 +110,16 @@ export default class DrawSquare {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user