Skip to content

Instantly share code, notes, and snippets.

@zaun
Created November 1, 2017 23:53
Show Gist options
  • Save zaun/77dac74305600acf6fcfaa4d103362e2 to your computer and use it in GitHub Desktop.
Save zaun/77dac74305600acf6fcfaa4d103362e2 to your computer and use it in GitHub Desktop.
Grid.hexagonalShape = function(size) {
var hexes = [];
var _g1 = -size;
var _g = size + 1;
while(_g1 < _g) {
var x = _g1++;
var _g3 = -size;
var _g2 = size + 1;
while(_g3 < _g2) {
var y = _g3++;
var z = -x - y;
if(Math.abs(x) <= size && Math.abs(y) <= size && Math.abs(z) <= size) hexes.push(new Cube(x,y,z));
}
}
return hexes;
};
Grid.triangularShape = function(size) {
var hexes = [];
var _g1 = 0;
var _g = size + 1;
while(_g1 < _g) {
var k = _g1++;
var _g3 = 0;
var _g2 = k + 1;
while(_g3 < _g2) {
var i = _g3++;
hexes.push(new Cube(i,-k,k - i));
}
}
return hexes;
};
Grid.trapezoidalShape = function(minQ,maxQ,minR,maxR,toCube) {
var hexes = [];
var _g1 = minQ;
var _g = maxQ + 1;
while(_g1 < _g) {
var q = _g1++;
var _g3 = minR;
var _g2 = maxR + 1;
while(_g3 < _g2) {
var r = _g3++;
hexes.push(toCube(new Hex(q,r)));
}
}
return hexes;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment