开发者

selecting a cell in a grid, spiral outwards through neighbour cells?

开发者 https://www.devze.com 2023-02-14 15:59 出处:网络
I would like to accomplish two things with this: Select (any) cell开发者_如何学C from a grid, and give the \'bands\' of neighboring cells an ever increasing value (in this example 1 -5)

I would like to accomplish two things with this:

  • Select (any) cell开发者_如何学C from a grid, and give the 'bands' of neighboring cells an ever increasing value (in this example 1 -5)

  • From the selected cell, select the next cell in a spiral fashion as show in blue, also accounting for if the 'route' leave the grid.

How would I go about this?

selecting a cell in a grid, spiral outwards through neighbour cells?


From your picture, you don't actually have to do it in spiral. The picture just shows, so to say, concentric circles (or, rather, squares).

You can calculate the next concentric square easily by subtracting or adding one to left/top or right/bottom edge coordinate correspondingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号