Hexagongenerierung in mustergenerator.py impementiert

This commit is contained in:
Mika 2023-11-03 01:31:59 +01:00
parent d0df1796e2
commit 4148826c43

View File

@ -94,18 +94,18 @@ class Circle:
class Hexagon:
def __init__(self, name: str, filepath: str, length=1000, height=1000, key_width=10, distance=60):
def __init__(self, name: str, filepath: str, length=1000, height=1000, key_width=50, bridge_width=10):
assert length >= 0, "length can not be negative"
assert height >= 0, "height can not be negative"
assert key_width >= 0, "radius can not be negative"
assert distance >= 2 * key_width, "distance must be grater then two times the radius"
assert bridge_width >= 0, "bridge width can not be negative"
self.__name = name
self.__filepath = filepath
self.__length = length
self.__height = height
self.__key_width = key_width
self.__distance = distance
self.__bridge_width = bridge_width
@property
def length(self):
@ -135,16 +135,56 @@ class Hexagon:
self.__key_width = val
@property
def distance(self):
return self.__distance
def bridge_width(self):
return self.__bridge_width
@distance.setter
def distance(self, val):
assert val >= 0, "distance can not be negative"
self.__distance = val
@bridge_width.setter
def bridge_width(self, val):
assert val >= 0, "bridge width can not be negative"
self.__bridge_width = val
def hexagon_generation(self):
pass
i = 1
x = 0
y = 0
side_length = self.__key_width / math.sqrt(3)
sin_expression = math.sin(math.radians(30)) * side_length
distance = self.__key_width + self.__bridge_width
distance_y = (math.sqrt(3) / 2) * distance
canvas = draw.Drawing(self.__length, self.__height, origin=(0, 0))
while y + (2 * side_length) < self.__height:
while x + self.__key_width < self.__length:
p1_x = x + self.__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 + self.__key_width / 2
p4_y = y + 2 * side_length
p5_x = x + self.__key_width
p5_y = y + sin_expression + side_length
p6_x = x + self.__key_width
p6_y = y + sin_expression
hexagon = 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')
canvas.append(hexagon)
x = x + distance
if i % 2 == 0:
x = 0
else:
x = distance / 2
y = y + distance_y
i = i + 1
canvas.save_svg(f'{self.__filepath}/{self.__name}.svg')
if __name__ == '__main__':
name = input("Dateinamen:")
@ -189,7 +229,35 @@ if __name__ == '__main__':
circle.circle_generation()
elif shape == 2:
print("noch nicht implementiert")
hexagon = Hexagon(name, path)
print(
f"\nStandardwerte\nHöhe: {hexagon.height} px\nLänge: {hexagon.length} px\nSchlüsselweite: {hexagon.key_width} px\nStegbreite: {hexagon.bridge_width} px\n")
selection_flag = True
while selection_flag:
try:
parameter_selection = int(input("Parameter ändern (0: keinen Parameter ändern, 1: Höhe, 2: Länge, 3: Schlüsselweite, 4: Stegbreite):"))
if parameter_selection == 0:
selection_flag = False
elif parameter_selection == 1:
height = int(input("Höhe in Pixeln eingeben:"))
hexagon.height = height
elif parameter_selection == 2:
length = int(input("Länge in Pixeln:"))
hexagon.length = length
elif parameter_selection == 3:
key_width = int(input("Schlüsselweite in Pixeln:"))
hexagon.key_width = key_width
elif parameter_selection == 4:
bridge_width = int(input("Stegbreite in Pixeln:"))
hexagon.bridge_width = bridge_width
else:
print("ungültiger Wert")
except ValueError:
print("ungültiger Wert")
except AssertionError as error:
print(error)
hexagon.hexagon_generation()
elif shape == 3:
print("noch nicht implementiert")
else: