Higher FPS! (#19)

This commit is contained in:
gavin
2018-10-05 20:22:11 -04:00
committed by Gitea
parent 0e2b7ea69d
commit 52017e8e30
7 changed files with 160 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
import {FLAT, POINTY} from './consts.js';
import {getColor, range, toFixed} from './utils.js';
import {getColor, range, toFixed, quickCanvas} from './utils.js';
export default class DrawHexagon {
constructor(settings) {
@@ -50,6 +50,34 @@ export default class DrawHexagon {
context.stroke();
}
// fill(context, scale, x, y, cell) {
// if (cell.cacheScale !== scale) {
// cell.cacheScale = scale;
// scale = scale * cell.scale;
//
// cell.cacheHalfWidth = scale;
// cell.cacheHalfHeight = scale;
//
// cell.cacheHex = quickCanvas((context, height, width) => {
// const hexCornerX = cell.orientation === POINTY ? this.pointyTopCornerX : this.flatTopCornerX;
// const hexCornerY = cell.orientation === POINTY ? this.pointyTopCornerY : this.flatTopCornerY;
//
// context.beginPath();
// context.moveTo(scale + scale * hexCornerX[0], scale + scale * hexCornerY[0]);
// context.lineTo(scale + scale * hexCornerX[1], scale + scale * hexCornerY[1]);
// context.lineTo(scale + scale * hexCornerX[2], scale + scale * hexCornerY[2]);
// context.lineTo(scale + scale * hexCornerX[3], scale + scale * hexCornerY[3]);
// context.lineTo(scale + scale * hexCornerX[4], scale + scale * hexCornerY[4]);
// context.lineTo(scale + scale * hexCornerX[5], scale + scale * hexCornerY[5]);
//
// context.fillStyle = getColor(cell.color);
// context.fill();
// }, scale * 2);
// }
//
// context.drawImage(cell.cacheHex, x - cell.cacheHalfWidth, y - cell.cacheHalfHeight);
// }
fill(context, scale, x, y, cell) {
scale = scale * cell.scale;
let hexCornerX = cell.orientation === POINTY ? this.pointyTopCornerX : this.flatTopCornerX;