0

I am looking for a way in order to find on which hexagon I've clicked on my map with a 2D array, so I did a small program as :

def center(x,y):
   for i in range(41):
       for j in range(22):
           coords[i].insert(j,[x,y])
           draw_circle(x, y)
           y = y + 33
       x = x + 25
       if (i%2==1):
           y=33
       else:
           y=16

def position(event,x,y,flags,param):
   global mouseX, mouseY
   x_left = x-16
   x_right = x+18
   y_haut= y-18
   y_bas= y+17
   if event == cv2.EVENT_LBUTTONDOWN:
       mouseX,mouseY = x,y
       for i in range(41):
           for j in range(21):
               if not (coords[i][j][0] >= x_left and coords[i][j][0] <= x_right):
                   break
               if (coords[i][j][-1] > y_haut and coords[i][j][-1] < y_bas):
                   x = coords[i][j][0]
                   y = coords[i][j][-1]
                   draw_circle2(x,y)
                   break

So with this program I am able to get for sure the center of each hexagon, but with this architecture of getting x left/right and y left/right, the borders detected acts on the previous hexagon too, hence draws a circle on two hexagon since they feat in the condition. If someone has an idea on how to fix that please? It would help a lot, thank you!

Jay
  • 85
  • 4

0 Answers0