Reputation: 791
For a fun side project, I've been trying to build a tool that generates a "tonal latus", which is basically a hex grid like this one:
Just to add entertainment I want to generate this grid recursively. So basically a Node will have 6 children which are stored in an array (the 0th index being the left or westernmost child and then going clockwise).
The problem I'm having with this is the recursive function finding out if a child already exists as part of another nodes creation and if so add the existing node to the child array instead of creating a new node as the child.
I've tried is giving each node a fake "x-y" id and passing an array as part of the recursion to look up to see if something exists which works for the most part but doesn't scale, I feel like there is a clever way of generating this that I'm missing. Has anyone come across a problem like this?
Upvotes: 1
Views: 350
Reputation: 855
You can build a coordinate system like this.
So each grid (x, y) is connected to (x-1, y), (x-1, y+1), (x, y+1), (x+1, y+1), (x+1, y), (x+1, y-1) and (x, y-1).
Upvotes: 3