import matplotlib.pyplot as plt
import numpy as np
import matplotlib.patches as patches
def draw_hexagonal_pattern(rows, cols, hex_size=1):
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_xlim(-1, cols * 1.5)
ax.set_ylim(-1, rows * np.sqrt(3))
ax.set_aspect('equal')
for row in range(rows):
for col in range(cols):
x = col * 1.5 * hex_size
y = row * np.sqrt(3) * hex_size
if col % 2 == 1:
y += np.sqrt(3) / 2 * hex_size
hexagon = patches.RegularPolygon((x, y), numVertices=6, radius=hex_size, edgecolor='black', facecolor='lightblue')
ax.add_patch(hexagon)
plt.axis('off')
plt.show()
draw_hexagonal_pattern(6,6)
#source code --> clcoding.com
0 Comments:
Post a Comment