HexagonGen2 erstellt

This commit is contained in:
Mika 2023-11-03 00:59:41 +01:00
parent 2173419612
commit d0df1796e2
2 changed files with 111 additions and 8 deletions

49
HexagonGen2.py Normal file
View File

@ -0,0 +1,49 @@
import drawsvg as draw
import math
# Veränderbare Parameter
height = 500
length = 500
key_width = 80
bridge_width = 20
# Feste und berechnete Parameter
i = 1
x = 0
y = 0
side_length = key_width / math.sqrt(3)
sin_expression = math.sin(math.radians(30))*side_length
distance = key_width + bridge_width
distance_y = (math.sqrt(3) / 2) * distance
canvas = draw.Drawing(length, height, origin=(0, 0))
while y + (2 * side_length) < height:
while x + key_width < length:
p1_x = x + 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 + key_width / 2
p4_y = y + 2 * side_length
p5_x = x + key_width
p5_y = y + sin_expression + side_length
p6_x = x + 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('hex.svg')

View File

@ -12,14 +12,14 @@ class Circle:
assert offset >= 0, "offset can only be 0 - 100 %"
assert offset <= 100, "offset can only be 0 - 100 %"
self.__name = name
self.__filepath = filepath
self.__length = length
self.__height = height
self.__radius = radius
self.__distance = distance
self.__offset_percentage = offset
self.__offset = (distance / 100) * offset
self.__name = name
self.__filepath = filepath
@property
def length(self):
@ -27,7 +27,7 @@ class Circle:
@length.setter
def length(self, val):
assert length >= 0, "length can not be negative"
assert val >= 0, "length can not be negative"
self.__length = val
@property
@ -36,7 +36,7 @@ class Circle:
@height.setter
def height(self, val):
assert height >= 0, "height can not be negative"
assert val >= 0, "height can not be negative"
self.__height = val
@property
@ -45,7 +45,7 @@ class Circle:
@radius.setter
def radius(self, val):
assert radius >= 0, "radius can not be negative"
assert val >= 0, "radius can not be negative"
self.__radius = val
@property
@ -54,7 +54,7 @@ class Circle:
@distance.setter
def distance(self, val):
assert distance >= 2 * radius, "distance must be grater then two times the radius"
assert val >= 2 * radius, "distance must be grater then two times the radius"
self.__distance = val
@property
@ -67,8 +67,8 @@ class Circle:
@offset.setter
def offset(self, val):
assert offset >= 0, "offset can only be 0 - 100 %"
assert offset <= 100, "offset can only be 0 - 100 %"
assert val >= 0, "offset can only be 0 - 100 %"
assert val <= 100, "offset can only be 0 - 100 %"
self.__offset = (self.__distance / 100) * val
def circle_generation(self):
@ -93,6 +93,59 @@ class Circle:
canvas.save_svg(f'{self.__filepath}/{self.__name}.svg')
class Hexagon:
def __init__(self, name: str, filepath: str, length=1000, height=1000, key_width=10, distance=60):
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"
self.__name = name
self.__filepath = filepath
self.__length = length
self.__height = height
self.__key_width = key_width
self.__distance = distance
@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 key_width(self):
return self.__key_width
@key_width.setter
def key_width(self, val):
assert val >= 0, "length can not be negative"
self.__key_width = val
@property
def distance(self):
return self.__distance
@distance.setter
def distance(self, val):
assert val >= 0, "distance can not be negative"
self.__distance = val
def hexagon_generation(self):
pass
if __name__ == '__main__':
name = input("Dateinamen:")
@ -134,6 +187,7 @@ if __name__ == '__main__':
print(error)
circle.circle_generation()
elif shape == 2:
print("noch nicht implementiert")
elif shape == 3: