Dreieckgeneration in mustergenerator.py implementiert
This commit is contained in:
parent
00ebd4656d
commit
b6d99796d1
|
@ -97,7 +97,7 @@ class Hexagon:
|
|||
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 key_width >= 0, "key width can not be negative"
|
||||
assert bridge_width >= 0, "bridge width can not be negative"
|
||||
|
||||
self.__name = name
|
||||
|
@ -186,6 +186,101 @@ class Hexagon:
|
|||
canvas.save_svg(f'{self.__filepath}/{self.__name}.svg')
|
||||
|
||||
|
||||
class Triangle:
|
||||
def __init__(self, name: str, filepath: str, length=1000, height=1000, side_length=50, bridge_width=10):
|
||||
assert length >= 0, "length can not be negative"
|
||||
assert height >= 0, "height can not be negative"
|
||||
assert side_length >= 0, "side length can not be negative"
|
||||
assert bridge_width >= 0, "bridge width can not be negative"
|
||||
|
||||
self.__name = name
|
||||
self.__filepath = filepath
|
||||
self.__length = length
|
||||
self.__height = height
|
||||
self.__side_length = side_length
|
||||
self.__bridge_width = bridge_width
|
||||
|
||||
@property
|
||||
def length(self):
|
||||
return self.__length
|
||||
|
||||
@length.setter
|
||||
def length(self, val):
|
||||
assert val >= 0, "length can not be negative"
|
||||
self.__length = val
|
||||
|
||||
@property
|
||||
def height(self):
|
||||
return self.__height
|
||||
|
||||
@height.setter
|
||||
def height(self, val):
|
||||
assert val >= 0, "height can not be negative"
|
||||
self.__height = val
|
||||
|
||||
@property
|
||||
def side_length(self):
|
||||
return self.__side_length
|
||||
|
||||
@side_length.setter
|
||||
def side_length(self, val):
|
||||
assert val >= 0, "length can not be negative"
|
||||
self.__side_length = val
|
||||
|
||||
@property
|
||||
def bridge_width(self):
|
||||
return self.__bridge_width
|
||||
|
||||
@bridge_width.setter
|
||||
def bridge_width(self, val):
|
||||
assert val >= 0, "bridge width can not be negative"
|
||||
self.__bridge_width = val
|
||||
|
||||
def triangle_generation(self):
|
||||
x = 0
|
||||
y = 0
|
||||
i = 1
|
||||
distance = self.__bridge_width / math.sin(math.radians(60))
|
||||
|
||||
canvas = draw.Drawing(self.__length, self.__height, origin=(0, 0))
|
||||
|
||||
while y + math.sqrt(3) / 2 * self.__side_length <= self.__height:
|
||||
while x + 1.5 * self.__side_length + distance <= self.__length:
|
||||
triangle1_p1_x = x
|
||||
triangle1_p1_y = y
|
||||
triangle1_p2_x = x + self.__side_length
|
||||
triangle1_p2_y = y
|
||||
triangle1_p3_x = x + math.sin(math.radians(30)) * self.__side_length
|
||||
triangle1_p3_y = y + math.cos(math.radians(30)) * self.__side_length
|
||||
|
||||
triangle = draw.Lines(triangle1_p1_x, triangle1_p1_y, triangle1_p2_x, triangle1_p2_y, triangle1_p3_x,
|
||||
triangle1_p3_y, close='true', stroke='black', fill='none')
|
||||
canvas.append(triangle)
|
||||
|
||||
x = x + self.__side_length + distance
|
||||
|
||||
triangle2_p1_x = x
|
||||
triangle2_p1_y = y
|
||||
triangle2_p2_x = x - self.__side_length / 2
|
||||
triangle2_p2_y = y + math.sqrt(3) / 2 * self.__side_length
|
||||
triangle2_p3_x = x + self.__side_length / 2
|
||||
triangle2_p3_y = triangle2_p2_y
|
||||
|
||||
triangle2 = draw.Lines(triangle2_p1_x, triangle2_p1_y, triangle2_p2_x, triangle2_p2_y, triangle2_p3_x,
|
||||
triangle2_p3_y, close='true', stroke='black', fill='none')
|
||||
canvas.append(triangle2)
|
||||
|
||||
x = x + distance
|
||||
if i % 2 == 0:
|
||||
x = 0
|
||||
else:
|
||||
x = self.__side_length / 2 + distance
|
||||
y = y + self.__bridge_width + math.sqrt(3) / 2 * self.__side_length
|
||||
i = i + 1
|
||||
|
||||
canvas.save_svg(f'{self.__filepath}/{self.__name}.svg')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
name = input("Dateinamen:")
|
||||
|
||||
|
@ -259,6 +354,35 @@ if __name__ == '__main__':
|
|||
|
||||
hexagon.hexagon_generation()
|
||||
elif shape == 3:
|
||||
print("noch nicht implementiert")
|
||||
triangle = Triangle(name, path)
|
||||
print(
|
||||
f"\nStandardwerte\nHöhe: {triangle.height} px\nLänge: {triangle.length} px\nSeitenlänge: {triangle.side_length} px\nStegbreite: {triangle.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: Seitenlänge, 4: Stegbreite):"))
|
||||
if parameter_selection == 0:
|
||||
selection_flag = False
|
||||
elif parameter_selection == 1:
|
||||
height = int(input("Höhe in Pixeln eingeben:"))
|
||||
triangle.height = height
|
||||
elif parameter_selection == 2:
|
||||
length = int(input("Länge in Pixeln:"))
|
||||
triangle.length = length
|
||||
elif parameter_selection == 3:
|
||||
side_length = int(input("Seitenlänge in Pixeln:"))
|
||||
triangle.side_length = side_length
|
||||
elif parameter_selection == 4:
|
||||
bridge_width = int(input("Stegbreite in Pixeln:"))
|
||||
triangle.bridge_width = bridge_width
|
||||
else:
|
||||
print("ungültiger Wert")
|
||||
except ValueError:
|
||||
print("ungültiger Wert")
|
||||
except AssertionError as error:
|
||||
print(error)
|
||||
|
||||
triangle.triangle_generation()
|
||||
else:
|
||||
print("ungültiger Wert")
|
||||
print("ungültiger Wert")
|
||||
|
|
Loading…
Reference in New Issue