Created
November 1, 2017 23:53
-
-
Save zaun/77dac74305600acf6fcfaa4d103362e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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