Last active
August 16, 2017 13:46
-
-
Save apaleslimghost/cc4e3d3f34b4953b92ae608d51b9a679 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
const range = require('lodash.range'); | |
const flatMap = require('lodash.flatmap'); | |
const root3by2 = Math.sqrt(3) / 2; | |
module.exports = ({rows, cols, size = 1, map = a => a}) => flatMap( | |
range(rows), | |
row => range(cols).map( | |
col => map([ | |
row % 2 | |
? col * size | |
: size / 2 + col * size, | |
row * size * root3by2, | |
]) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment