From bf30d0d3031b77f82a9091846948bcc447b3d96c Mon Sep 17 00:00:00 2001 From: Gavin McDonald Date: Sun, 24 Jun 2018 21:58:28 -0400 Subject: [PATCH] pointy top squares --- src/cartographerXY.js | 10 +++++----- src/cartographerXYZ.js | 12 ++++++------ src/main.js | 4 ++-- src/tessellate.js | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cartographerXY.js b/src/cartographerXY.js index baf7f5e..7fd4691 100644 --- a/src/cartographerXY.js +++ b/src/cartographerXY.js @@ -55,10 +55,10 @@ export default class CartographerXY extends Cartographer { const minWidth = (a) => this.minWidth() * a; - const maxWidth = (a) => this.maxWidth() * a; + const maxWidth = (a, b) => (this.maxWidth() * a) + ((b % 2) * (this.maxWidth() / 2)); - let pixelX = this.pointyTop ? maxWidth(square.getX()) : minWidth(square.getX()); - let pixelY = this.pointyTop ? maxWidth(square.getY()) : minWidth(square.getY()); + let pixelX = this.pointyTop ? maxWidth(square.getX(), square.getY()) : minWidth(square.getX()); + let pixelY = this.pointyTop ? (this.maxWidth() / 2) * square.getY() : minWidth(square.getY()); pixelX += this.originX; pixelY += this.originY; @@ -69,7 +69,7 @@ export default class CartographerXY extends Cartographer { pixelToTile(point) { let scale = this.scale; - const radiusLong = a => a / this.maxWidth(); + const radiusLong = a => (a / (this.maxWidth() / 2)); const radiusShort = a => a / this.minWidth(); let pixelX = point.getX() - this.originX; @@ -96,7 +96,7 @@ export default class CartographerXY extends Cartographer { for (let row = 0; row <= height; row++) { tiles[row] = []; let y = upperLeftTile.getY() + row; - let xOffset = upperLeftTile.getX(); + let xOffset = upperLeftTile.getX() - (row % 2); for (let x = xOffset; x <= xOffset + width; x++) { tiles[row].push(new Square(x, y)); diff --git a/src/cartographerXYZ.js b/src/cartographerXYZ.js index 9ecf6dc..e02e926 100644 --- a/src/cartographerXYZ.js +++ b/src/cartographerXYZ.js @@ -114,7 +114,7 @@ export default class CartographerXYZ extends Cartographer { } boundingBox(upperLeftPoint, lowerRightPoint) { - let hexagons = []; + let tiles = []; let upperRightPoint = new Point(lowerRightPoint.getX(), upperLeftPoint.getY()); // push out by a 1 axially to account for interlocking hexagons @@ -128,28 +128,28 @@ export default class CartographerXYZ extends Cartographer { if (this.pointyTop) { for (let row = 0; row <= height; row++) { - hexagons[row] = []; + tiles[row] = []; let r = upperLeftTile.getR() + row; let qOffset = upperLeftTile.getQ() - Math.floor(row / 2); for (let q = qOffset; q <= qOffset + width; q++) { - hexagons[row].push(new Hex(q, r)); + tiles[row].push(new Hex(q, r)); } } } else { for (let col = 0; col <= width; col++) { - hexagons[col] = []; + tiles[col] = []; let q = upperLeftTile.getQ() + col; let rOffset = upperLeftTile.getR() - Math.floor(col / 2); for (let r = rOffset; r <= rOffset + height; r++) { - hexagons[col].push(new Hex(q, r)); + tiles[col].push(new Hex(q, r)); } } } - return hexagons; + return tiles; } } diff --git a/src/main.js b/src/main.js index 92c1710..2855030 100644 --- a/src/main.js +++ b/src/main.js @@ -13,8 +13,8 @@ class Demo { let tessellate = new Tessellate({ element: '#container', - board: Tessellate.BOARD_STYLES.HEX, - tile: Tessellate.TILE_STYLES.CIRCLE, + board: Tessellate.BOARD_STYLES.SQUARE, + tile: Tessellate.TILE_STYLES.SQUARE, tap: this.onTap, draw: this.draw, pointyTop: false, //utils.random(1) ? true : false, diff --git a/src/tessellate.js b/src/tessellate.js index 3d57f98..f7abf7c 100644 --- a/src/tessellate.js +++ b/src/tessellate.js @@ -118,7 +118,7 @@ export default class Tessellate { green: utils.random(255), blue: utils.random(255), alpha: utils.random(25, 75) / 100, - scale: utils.random(5,9)/10 + scale: utils.random(6,9)/10 }); }