Hello all
I’m trying to create a series of adjacent tiles from a grid. The intended result is a snake-like formation. (The ultimate result would be a subdivision of this grid into as many as possible abutting ‘snakes’ of different lengths and shapes, but I would like to resolve this stage of the process first.)
I’m stuck where the tile selected would produce repeats and even then it only works with some n number of tiles. Any help is greatly appreciated!
Instead of making the grid walk geometry dependant and thus computationally heavy, the idea of the grid can be abstracted to a unit grid, where every geometry cell is represented by its item index.
If you know the number of grid rows and columns, you can calculate everything else, meaning cell adjacencies, row and column numbers from cell indices, etc., with simple formulas.
I created a straightforward grid class with some of these utility functions.
For the walk recursion can be used, but is not necessary. You don’t seem to keep track of already visited cells in the right way, and thus some cells seem to get revisited.
Anyway, here’s a demo of a single walk of a given cell length, here 20:
The idea can be extended to numerous, sized walks (below 6) that flood the grid, meaning the given size is a maximum, but shorter walks are also allowed to effectively visited each grid cell: