From 828936269f8ae8f84efead36608a6493c9bae21f Mon Sep 17 00:00:00 2001 From: Mika Date: Wed, 1 Nov 2023 15:16:23 +0100 Subject: [PATCH] =?UTF-8?q?Kreisgenerator=20mit=20optional=20ver=C3=A4nder?= =?UTF-8?q?baren=20Parametern=20fertig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mustergenerator.py | 97 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 8 deletions(-) diff --git a/mustergenerator.py b/mustergenerator.py index 7d62b84..de427c3 100644 --- a/mustergenerator.py +++ b/mustergenerator.py @@ -1,21 +1,65 @@ import drawsvg as draw +import os import math -import random class Circle: - def __init__(self, length=1000, height=1000, radius=10, distance=60, offset=30): + def __init__(self, name: str, filepath: str, length=1234, height=1234, radius=10, distance=60, offset=50): # run validations assert length >= 0, "length can not be negative" assert radius >= 0, "radius can not be negative" assert distance >= 2*radius, "distance must be grater den two times the radius" + assert offset >= 0, "offset can only be 0 - 100 %" + assert offset <= 100, "offset can only be 0 - 100 %" # Assign to self object self.__length = length self.__height = height self.__radius = radius self.__distance = distance - self.__offset = offset + self.__offset = (distance / 100) * offset + self.__name = name + self.__filepath = filepath + + @property + def length(self): + return self.__length + + @length.setter + def length(self, val): + self.__length = val + + @property + def height(self): + return self.__height + + @height.setter + def height(self, val): + self.__height = val + + @property + def radius(self): + return self.__radius + + @radius.setter + def radius(self, val): + self.__radius = val + @property + def distance(self): + return self.__distance + + @distance.setter + def distance(self, val): + self.__distance = val + + @property + def offset(self): + return self.__offset + + @offset.setter + def offset(self, val): + self.__offset = (self.__distance / 100) * val + def circle_generation(self): @@ -30,17 +74,54 @@ class Circle: while y <= self.__height: x = x1 + self.__offset * v while x <= self.__length: - canvas.append(draw.Circle(x, y, self.__radius, - fill='none', stroke_width=1, stroke='black')) + canvas.append(draw.Circle(x, y, self.__radius, fill='none', stroke_width=1, stroke='black')) x = x + self.__distance y = y + self.__distance v = -((1 - g) / 2) g = -g - canvas.save_svg('example.svg') + canvas.save_svg(f'{self.__filepath}/{self.__name}.svg') if __name__ == '__main__': - circle = Circle() - circle.circle_generation() + name = input("Dateinamen:") + path = input("Dateipfad (0 für aktuelles Verzeichnis):") + if path == "0": + path = os.getcwd() + + shape = int(input("Form (1: Kreis, 2: Hexagon, 3: Dreieck)")) + + if shape == 1: + circle = Circle(name, path) + + selection_flag = True + while selection_flag: + parameter_selection = int(input("Parameter wählen (0: keinen Parameter ändern, 1: Höhe, 2: Länge, 3: Radius, 4: Abstand, 5: Offste):")) + if parameter_selection == 0: + selection_flag = False + elif parameter_selection == 1: + height = int(input("Höhe in Pixeln eingeben:")) + circle.height = height + elif parameter_selection == 2: + length = int(input("Länge in Pixeln:")) + circle.length = length + elif parameter_selection == 3: + radius = int(input("Radius in Pixeln:")) + circle.radius = radius + elif parameter_selection == 4: + distance = int(input("Abstand in Pixeln:")) + circle.distance = distance + elif parameter_selection == 5: + offset = int(input("Offset in %:")) + circle.offset = offset + else: + print("ungültiger Wert") + + circle.circle_generation() + elif shape == 2: + print("noch nicht implementiert") + elif shape == 3: + print("noch nicht implementiert") + else: + print("ungültiger Wert") \ No newline at end of file