Advertisement
Ulabael

hexes

Dec 23rd, 2022
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. from turtle import *
  2. import math
  3.  
  4. hexSize = 24
  5. hexWidth = hexSize * 2
  6. hexHeight = hexSize * (3 ** 0.5)
  7.  
  8. def hex_corner(coord, i, xcoord):
  9. global hexSize
  10. angle_deg = 60 * i
  11. angle_rad = math.pi / 180 * angle_deg
  12. if xcoord == True:
  13. return coord + hexSize * math.cos(angle_rad)
  14. else:
  15. return coord + hexSize * math.sin(angle_rad)
  16.  
  17. # Принимает координаты x и y гекса
  18. def hex(x, y):
  19. up()
  20. goto(x, y)
  21. fx = hex_corner(x, 0, True)
  22. fy = hex_corner(y, 0, False)
  23. goto(fx, fy)
  24. down()
  25. sx = hex_corner(x, 1, True)
  26. sy = hex_corner(y, 1, False)
  27. goto(sx, sy)
  28. tx = hex_corner(x, 2, True)
  29. ty = hex_corner(y, 2, False)
  30. goto(tx, ty)
  31. frx = hex_corner(x, 3, True)
  32. fry = hex_corner(y, 3, False)
  33. goto(frx, fry)
  34. fvx = hex_corner(x, 4, True)
  35. fvy = hex_corner(y, 4, False)
  36. goto(fvx, fvy)
  37. sxx = hex_corner(x, 5, True)
  38. sxy = hex_corner(y, 5, False)
  39. goto(sxx, sxy)
  40. goto(fx, fy)
  41.  
  42. x = 0
  43. y = 0
  44. hex(x,y)
  45. x = hexWidth * 3 / 4
  46. y = -(hexHeight*0.5)
  47. hex(x, y)
  48. x += hexWidth * 3 / 4
  49. y += (hexHeight * 0.5)
  50. hex(x, y)
  51. x += hexWidth * 3 / 4
  52. y -= (hexHeight * 0.5)
  53. hex(x, y)
  54. x += hexWidth * 3 / 4
  55. y += (hexHeight * 0.5)
  56. hex(x, y)
  57. x = 0
  58. y = -hexHeight
  59. hex(x, y)
  60. x += hexWidth * 3 / 4
  61. y -= (hexHeight * 0.5)
  62. hex(x, y)
  63. x += hexWidth * 3 / 4
  64. y += (hexHeight * 0.5)
  65. hex(x, y)
  66. x += hexWidth * 3 / 4
  67. y -= (hexHeight * 0.5)
  68. hex(x, y)
  69. x += hexWidth * 3 / 4
  70. y += (hexHeight * 0.5)
  71. hex(x, y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement