Как-то так:
var
sizex = 10,
sizey = 10,
cur_pos = 35,
dist = 2,
list = [];
var
pos_x = (cur_pos - 1) % sizex,
pos_y = Math.floor((cur_pos - 1)/sizex);
var
start_x = (pos_x - dist >= 0) ? pos_x - dist : 0,
start_y = (pos_y - dist >= 0) ? pos_y - dist : 0,
end_x = (pos_x + dist < sizex) ? pos_x + dist : sizex - 1,
end_y = (pos_y + dist < sizey) ? pos_y + dist : sizey - 1;
for (var y = start_y; y <= end_y; y++) {
for (var x = start_x; x <= end_x; x++) {
list.push(y * sizex + x + 1);
}
}
console.log(list);