Help with Hex grid generator

I’m really struggling with hex tile grids. I’m trying to implement something similar but it’s blowing my mind!