Skip to content

Instantly share code, notes, and snippets.

@otar
Created September 16, 2010 13:25
Show Gist options
  • Save otar/582414 to your computer and use it in GitHub Desktop.
Save otar/582414 to your computer and use it in GitHub Desktop.
function array_nbr(row_idx, column_idx, rows, columns, level)
{
level = level || 1;
var nbr = [];
for (var y = Math.max(0, row_idx - level); y <= Math.min(row_idx + level, rows); y++)
{
for (var x = Math.max(0, column_idx - level); x <= Math.min(column_idx + level, columns); x++)
{
nbr.push([x, y]);
}
}
return nbr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment