Mustergenerator/HexagonGen2.py

91 lines
2.5 KiB
Python

import drawsvg as draw
import math
# Veränderbare Parameter
height = 50
length = 50
key_width = 2
bridge_width = 0.5
# Feste und berechnete Parameter
i = 1
x = 0
y = 0
side_length = key_width / math.sqrt(3)
sin_expression = math.sin(math.radians(30))*side_length
distance = key_width + bridge_width
distance_y = (math.sqrt(3) / 2) * distance
canvas = draw.Drawing(length, height, origin=(0, 0))
alignment_dot = draw.Circle(0.1, 0.1, 0.1, stroke='black', stroke_width=0.05)
canvas.append(alignment_dot)
while y + (2 * side_length) < height:
while x + key_width < length:
p1_x = x + key_width / 2
p1_y = y
p2_x = x
p2_y = y + sin_expression
p3_x = x
p3_y = y + sin_expression + side_length
p4_x = x + key_width / 2
p4_y = y + 2 * side_length
p5_x = x + key_width
p5_y = y + sin_expression + side_length
p6_x = x + key_width
p6_y = y + sin_expression
hexagon_shifted = draw.Lines(p1_x, p1_y, p2_x, p2_y, p3_x, p3_y, p4_x, p4_y, p5_x, p5_y, p6_x, p6_y, fill='none', stroke='black', close='true', stroke_width=0.1)
canvas.append(hexagon_shifted)
x = x + distance
if i % 2 == 0:
x = 0
else:
x = distance / 2
y = y + distance_y
i = i + 1
x_shifted = distance / 2
y_shifted = distance / (2 * math.sqrt(3))
canvas_shifted = draw.Drawing(length, height, origin=(0, 0))
canvas_shifted.append(alignment_dot)
while y_shifted + (2 * side_length) < height:
while x_shifted + key_width < length:
p1_x_2 = x_shifted + key_width / 2
p1_y_2 = y_shifted
p2_x_2 = x_shifted
p2_y_2 = y_shifted + sin_expression
p3_x_2 = x_shifted
p3_y_2 = y_shifted + sin_expression + side_length
p4_x_2 = x_shifted + key_width / 2
p4_y_2 = y_shifted + 2 * side_length
p5_x_2 = x_shifted + key_width
p5_y_2 = y_shifted + sin_expression + side_length
p6_x_2 = x_shifted + key_width
p6_y_2 = y_shifted + sin_expression
hexagon_shifted = draw.Lines(p1_x_2, p1_y_2, p2_x_2, p2_y_2, p3_x_2, p3_y_2, p4_x_2, p4_y_2, p5_x_2, p5_y_2, p6_x_2, p6_y_2, fill='none', stroke='black', close='true', stroke_width=0.1)
canvas_shifted.append(hexagon_shifted)
x_shifted = x_shifted + distance
if i % 2 == 0:
x_shifted = 0
else:
x_shifted = distance / 2
y_shifted = y_shifted + distance_y
i = i + 1
canvas_shifted.save_svg('hex2.svg')
canvas.save_svg('hex.svg')