Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Last active August 16, 2017 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apaleslimghost/cc4e3d3f34b4953b92ae608d51b9a679 to your computer and use it in GitHub Desktop.
Save apaleslimghost/cc4e3d3f34b4953b92ae608d51b9a679 to your computer and use it in GitHub Desktop.
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