Erstellen von versetzten Mustern für Kreise implementiert

This commit is contained in:
Mika 2023-11-10 15:23:11 +01:00
parent c7f5fa0aff
commit 76f00b46cb

View File

@ -4,13 +4,13 @@ import math
class Circle:
def __init__(self, name: str, filepath: str, length=50, height=50, radius=2, distance=4.5, offset=50):
def __init__(self, name: str, filepath: str, length=50, height=50, radius=2, distance=4.5, offset_percentage=50):
assert length >= 0, "length can not be negative"
assert height >= 0, "height can not be negative"
assert radius >= 0, "radius can not be negative"
assert distance >= 2*radius, "distance must be grater then two times the radius"
assert offset >= 0, "offset can only be 0 - 100 %"
assert offset <= 100, "offset can only be 0 - 100 %"
assert offset_percentage >= 0, "offset can only be 0 - 100 %"
assert offset_percentage <= 100, "offset can only be 0 - 100 %"
self.__name = name
self.__filepath = filepath
@ -18,8 +18,8 @@ class Circle:
self.__height = height
self.__radius = radius
self.__distance = distance
self.__offset_percentage = offset
self.__offset = (distance / 100) * offset
self.__offset_percentage = offset_percentage
self.__offset = (distance / 100) * offset_percentage
@property
def length(self):
@ -68,7 +68,7 @@ class Circle:
self.__offset_percentage = val
self.__offset = (self.__distance / 100) * val
def circle_generation(self, filetype='svg'):
def circle_generation(self, filetype='svg', generate_shifted_pattern=True):
assert filetype == 'svg' or 'png', "Dateityp mus svg oder png sein"
x = self.__radius
y = self.__radius
@ -76,6 +76,9 @@ class Circle:
canvas = draw.Drawing(self.__length, self.__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 + self.__radius <= self.__height:
while x + self.__radius <= self.__length:
canvas.append(draw.Circle(x, y, self.__radius, fill='none', stroke_width=0.1, stroke='black'))
@ -89,6 +92,32 @@ class Circle:
y = y + self.__distance
i = i + 1
if generate_shifted_pattern:
i = 1
x_shifted = self.__radius + self.__distance / 2
y_shifted = self.__radius + self.__distance / 2
canvas_shifted = draw.Drawing(self.__length, self.__height, origin=(0, 0))
canvas_shifted.append(alignment_dot)
while y_shifted + self.__radius <= self.__height:
while x_shifted + self.__radius <= self.__length:
canvas_shifted.append(draw.Circle(x_shifted, y_shifted, self.__radius, fill='none', stroke_width=0.1, stroke='black'))
x_shifted = x_shifted + self.__distance
if i % 2 == 0:
x_shifted = self.__radius + self.__distance / 2
else:
x_shifted = self.__radius + self.__distance / 2 + self.__offset
y_shifted = y_shifted + self.__distance
i = i + 1
if filetype == 'svg':
canvas_shifted.save_svg(f'{self.__filepath}/{self.__name}_versetzt.svg')
if filetype == 'png':
canvas_shifted.save_png(f'{self.__filepath}/{self.__name}_versetzt.png')
if filetype == 'svg':
canvas.save_svg(f'{self.__filepath}/{self.__name}.svg')
if filetype == 'png':
@ -352,11 +381,11 @@ if __name__ == '__main__':
if shape == 1:
circle = Circle(name, path)
print(f"\nStandardwerte\n1. Höhe: {circle.height} mm\n2. Länge: {circle.length} mm\n3. Radius: {circle.radius} mm\n4. Abstand: {circle.distance} mm\n5. Offset: {circle.offset_percentage} %\n6. Dateityp: svg\n")
print(f"\nStandardwerte\n1. Höhe: {circle.height} mm\n2. Länge: {circle.length} mm\n3. Radius: {circle.radius} mm\n4. Abstand: {circle.distance} mm\n5. Offset: {circle.offset_percentage} %\n6. Versetztes Muster generiren: {shift}\n7. Dateityp: {filetype}\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: Radius, 4: Abstand, 5: Offste, 6: Dateityp):"))
parameter_selection = int(input("Parameter ändern (0: keinen Parameter ändern, 1: Höhe, 2: Länge, 3: Radius, 4: Abstand, 5: Offste, 6: Versetztes Muster, 7: Dateityp):"))
if parameter_selection == 0:
selection_flag = False
elif parameter_selection == 1:
@ -375,6 +404,14 @@ if __name__ == '__main__':
offset = float(input("Offset in %:"))
circle.offset_percentage = offset
elif parameter_selection == 6:
shift_select = int(input("Versetztes muster generieren (0: nein, 1: ja):"))
if shift_select == 0:
shift = False
elif shift_select == 1:
shift = True
else:
raise ValueError
elif parameter_selection == 7:
filetype_selection = int(input(f"1: {name}.svg, 2: {name}.png:"))
if filetype_selection == 1:
filetype = "svg"
@ -389,14 +426,14 @@ if __name__ == '__main__':
except AssertionError as error:
print(error)
print(
f"\nAktuelle Werte\n1. Höhe: {circle.height} mm\n2. Länge: {circle.length} mm\n3. Radius: {circle.radius} mm\n4. Abstand: {circle.distance} mm\n5. Offset: {circle.offset_percentage} %\n6. Dateityp: svg\n")
f"\nAktuelle Werte\n1. Höhe: {circle.height} mm\n2. Länge: {circle.length} mm\n3. Radius: {circle.radius} mm\n4. Abstand: {circle.distance} mm\n5. Offset: {circle.offset_percentage} %\n6. Versetztes Muster generiren: {shift}\n7. Dateityp: {filetype}\n>")
circle.circle_generation(filetype)
circle.circle_generation(filetype, shift)
elif shape == 2:
hexagon = Hexagon(name, path)
print(
f"\nStandardwerte\n1. Höhe: {hexagon.height} mm\n2. Länge: {hexagon.length} mm\n3. Schlüsselweite: {hexagon.key_width} mm\n4. Stegbreite: {hexagon.bridge_width} mm\n5. Versetztes Muster generiren: True\n6. Dateityp: svg\n")
f"\nStandardwerte\n1. Höhe: {hexagon.height} mm\n2. Länge: {hexagon.length} mm\n3. Schlüsselweite: {hexagon.key_width} mm\n4. Stegbreite: {hexagon.bridge_width} mm\n5. Versetztes Muster generiren: {shift}\n6. Dateityp: Dateityp: {filetype}\n")
selection_flag = True
while selection_flag:
try:
@ -416,7 +453,7 @@ if __name__ == '__main__':
bridge_width = float(input("Stegbreite in mm:"))
hexagon.bridge_width = bridge_width
elif parameter_selection == 5:
shift_select = int(input("Versetztes muster generieren (0: nein, 1: ja):"))
shift_select = int(input("Versetztes Muster generieren (0: nein, 1: ja):"))
if shift_select == 0:
shift = False
elif shift_select == 1:
@ -439,14 +476,14 @@ if __name__ == '__main__':
print(error)
print(
f"\nAktuelle Werte\n1. Höhe: {hexagon.height} mm\n2. Länge: {hexagon.length} mm\n3. Schlüsselweite: {hexagon.key_width} mm\n4. Stegbreite: {hexagon.bridge_width} mm\n5. Versetztes Muster generiren: {shift}\n6. Dateityp: svg\n")
f"\nAktuelle Werte\n1. Höhe: {hexagon.height} mm\n2. Länge: {hexagon.length} mm\n3. Schlüsselweite: {hexagon.key_width} mm\n4. Stegbreite: {hexagon.bridge_width} mm\n5. Versetztes Muster generiren: {shift}\n6.Dateityp: {filetype}\n")
hexagon.hexagon_generation(filetype, shift)
elif shape == 3:
triangle = Triangle(name, path)
print(
f"\nStandardwerte\n1. Höhe: {triangle.height} mm\n2. Länge: {triangle.length} mm\n3. Seitenlänge: {triangle.side_length} mm\n4. Stegbreite: {triangle.bridge_width} mm\n5. Dateityp: svg\n")
f"\nStandardwerte\n1. Höhe: {triangle.height} mm\n2. Länge: {triangle.length} mm\n3. Seitenlänge: {triangle.side_length} mm\n4. Stegbreite: {triangle.bridge_width} mm\n5. Dateityp: {filetype}\n")
selection_flag = True
while selection_flag:
try:
@ -481,7 +518,7 @@ if __name__ == '__main__':
except AssertionError as error:
print(error)
print(
f"\nAktuelle Werte\n1. Höhe: {triangle.height} mm\n2. Länge: {triangle.length} mm\n3. Seitenlänge: {triangle.side_length} mm\n4. Stegbreite: {triangle.bridge_width} mm\n5. Dateityp: svg\n")
f"\nAktuelle Werte\n1. Höhe: {triangle.height} mm\n2. Länge: {triangle.length} mm\n3. Seitenlänge: {triangle.side_length} mm\n4. Stegbreite: {triangle.bridge_width} mm\n5. Dateityp: {filetype}\n")
triangle.triangle_generation(filetype)
else: