2023-10-30 21:51:28 +00:00
|
|
|
import drawsvg as draw
|
2023-11-01 14:16:23 +00:00
|
|
|
import os
|
2023-10-30 21:51:28 +00:00
|
|
|
import math
|
|
|
|
|
|
|
|
|
2023-11-01 12:26:38 +00:00
|
|
|
class Circle:
|
2023-11-01 14:29:24 +00:00
|
|
|
def __init__(self, name: str, filepath: str, length=1000, height=1000, radius=10, distance=60, offset=50):
|
2023-11-01 12:26:38 +00:00
|
|
|
assert length >= 0, "length can not be negative"
|
2023-11-01 14:37:01 +00:00
|
|
|
assert height >= 0, "height can not be negative"
|
2023-11-01 12:26:38 +00:00
|
|
|
assert radius >= 0, "radius can not be negative"
|
2023-11-02 13:10:41 +00:00
|
|
|
assert distance >= 2*radius, "distance must be grater then two times the radius"
|
2023-11-01 14:16:23 +00:00
|
|
|
assert offset >= 0, "offset can only be 0 - 100 %"
|
|
|
|
assert offset <= 100, "offset can only be 0 - 100 %"
|
2023-11-01 12:26:38 +00:00
|
|
|
|
|
|
|
self.__length = length
|
|
|
|
self.__height = height
|
|
|
|
self.__radius = radius
|
|
|
|
self.__distance = distance
|
2023-11-01 14:29:24 +00:00
|
|
|
self.__offset_percentage = offset
|
2023-11-01 14:16:23 +00:00
|
|
|
self.__offset = (distance / 100) * offset
|
|
|
|
self.__name = name
|
|
|
|
self.__filepath = filepath
|
|
|
|
|
|
|
|
@property
|
|
|
|
def length(self):
|
|
|
|
return self.__length
|
|
|
|
|
|
|
|
@length.setter
|
|
|
|
def length(self, val):
|
2023-11-01 14:37:01 +00:00
|
|
|
assert length >= 0, "length can not be negative"
|
2023-11-01 14:16:23 +00:00
|
|
|
self.__length = val
|
|
|
|
|
|
|
|
@property
|
|
|
|
def height(self):
|
|
|
|
return self.__height
|
|
|
|
|
|
|
|
@height.setter
|
|
|
|
def height(self, val):
|
2023-11-01 14:37:01 +00:00
|
|
|
assert height >= 0, "height can not be negative"
|
2023-11-01 14:16:23 +00:00
|
|
|
self.__height = val
|
|
|
|
|
|
|
|
@property
|
|
|
|
def radius(self):
|
|
|
|
return self.__radius
|
|
|
|
|
|
|
|
@radius.setter
|
|
|
|
def radius(self, val):
|
2023-11-01 14:37:01 +00:00
|
|
|
assert radius >= 0, "radius can not be negative"
|
2023-11-01 14:16:23 +00:00
|
|
|
self.__radius = val
|
|
|
|
@property
|
|
|
|
def distance(self):
|
|
|
|
return self.__distance
|
|
|
|
|
|
|
|
@distance.setter
|
|
|
|
def distance(self, val):
|
2023-11-02 13:10:41 +00:00
|
|
|
assert distance >= 2 * radius, "distance must be grater then two times the radius"
|
2023-11-01 14:16:23 +00:00
|
|
|
self.__distance = val
|
|
|
|
|
2023-11-01 14:29:24 +00:00
|
|
|
@property
|
|
|
|
def offset_percentage(self):
|
|
|
|
return self.__offset_percentage
|
|
|
|
|
2023-11-01 14:16:23 +00:00
|
|
|
@property
|
|
|
|
def offset(self):
|
|
|
|
return self.__offset
|
|
|
|
|
|
|
|
@offset.setter
|
|
|
|
def offset(self, val):
|
2023-11-01 14:37:01 +00:00
|
|
|
assert offset >= 0, "offset can only be 0 - 100 %"
|
|
|
|
assert offset <= 100, "offset can only be 0 - 100 %"
|
2023-11-01 14:16:23 +00:00
|
|
|
self.__offset = (self.__distance / 100) * val
|
|
|
|
|
2023-11-01 12:26:38 +00:00
|
|
|
def circle_generation(self):
|
|
|
|
|
|
|
|
x1 = 10
|
|
|
|
y1 = 10
|
|
|
|
y = y1
|
|
|
|
v = 1
|
|
|
|
g = 1
|
|
|
|
|
|
|
|
canvas = draw.Drawing(self.__length, self.__height, origin=(0, 0))
|
|
|
|
|
|
|
|
while y <= self.__height:
|
|
|
|
x = x1 + self.__offset * v
|
|
|
|
while x <= self.__length:
|
2023-11-01 14:16:23 +00:00
|
|
|
canvas.append(draw.Circle(x, y, self.__radius, fill='none', stroke_width=1, stroke='black'))
|
2023-11-01 12:26:38 +00:00
|
|
|
x = x + self.__distance
|
|
|
|
y = y + self.__distance
|
|
|
|
v = -((1 - g) / 2)
|
|
|
|
g = -g
|
|
|
|
|
2023-11-01 14:16:23 +00:00
|
|
|
canvas.save_svg(f'{self.__filepath}/{self.__name}.svg')
|
2023-10-30 21:51:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-11-01 14:16:23 +00:00
|
|
|
name = input("Dateinamen:")
|
|
|
|
|
|
|
|
path = input("Dateipfad (0 für aktuelles Verzeichnis):")
|
|
|
|
if path == "0":
|
|
|
|
path = os.getcwd()
|
|
|
|
|
2023-11-01 14:29:24 +00:00
|
|
|
shape = int(input("Form (1: Kreis, 2: Hexagon, 3: Dreieck):"))
|
2023-11-01 14:16:23 +00:00
|
|
|
|
|
|
|
if shape == 1:
|
|
|
|
circle = Circle(name, path)
|
2023-11-01 14:29:24 +00:00
|
|
|
print(f"\nStandardwerte\nHöhe: {circle.height} px\nLänge: {circle.length} px\nRadius: {circle.radius} px\nAbstand: {circle.distance} px\nOffset: {circle.offset_percentage} %\n")
|
2023-11-01 14:16:23 +00:00
|
|
|
selection_flag = True
|
|
|
|
while selection_flag:
|
2023-11-02 12:56:12 +00:00
|
|
|
try:
|
|
|
|
parameter_selection = int(input("Parameter ändern (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")
|
|
|
|
except ValueError:
|
2023-11-01 14:16:23 +00:00
|
|
|
print("ungültiger Wert")
|
2023-11-02 12:56:12 +00:00
|
|
|
except AssertionError as error:
|
|
|
|
print(error)
|
2023-11-01 12:26:38 +00:00
|
|
|
|
2023-11-01 14:16:23 +00:00
|
|
|
circle.circle_generation()
|
|
|
|
elif shape == 2:
|
|
|
|
print("noch nicht implementiert")
|
|
|
|
elif shape == 3:
|
|
|
|
print("noch nicht implementiert")
|
|
|
|
else:
|
|
|
|
print("ungültiger Wert")
|