Erstellen von versetzten Mustern implementiert
This commit is contained in:
parent
ee93b84ec0
commit
c7f5fa0aff
|
@ -2,10 +2,10 @@ import drawsvg as draw
|
|||
import math
|
||||
|
||||
# Veränderbare Parameter
|
||||
height = 500
|
||||
length = 500
|
||||
key_width = 80
|
||||
bridge_width = 20
|
||||
height = 50
|
||||
length = 50
|
||||
key_width = 2
|
||||
bridge_width = 0.5
|
||||
|
||||
# Feste und berechnete Parameter
|
||||
i = 1
|
||||
|
@ -18,6 +18,9 @@ distance_y = (math.sqrt(3) / 2) * distance
|
|||
|
||||
canvas = draw.Drawing(length, 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 + (2 * side_length) < height:
|
||||
while x + key_width < length:
|
||||
p1_x = x + key_width / 2
|
||||
|
@ -33,8 +36,8 @@ while y + (2 * side_length) < height:
|
|||
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)
|
||||
hexagon_shifted = 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', stroke_width=0.1)
|
||||
canvas.append(hexagon_shifted)
|
||||
|
||||
x = x + distance
|
||||
|
||||
|
@ -46,4 +49,42 @@ while y + (2 * side_length) < height:
|
|||
y = y + distance_y
|
||||
i = i + 1
|
||||
|
||||
x_shifted = distance / 2
|
||||
y_shifted = distance / (2 * math.sqrt(3))
|
||||
|
||||
canvas_shifted = draw.Drawing(length, height, origin=(0, 0))
|
||||
|
||||
canvas_shifted.append(alignment_dot)
|
||||
|
||||
while y_shifted + (2 * side_length) < height:
|
||||
while x_shifted + key_width < length:
|
||||
|
||||
p1_x_2 = x_shifted + key_width / 2
|
||||
p1_y_2 = y_shifted
|
||||
p2_x_2 = x_shifted
|
||||
p2_y_2 = y_shifted + sin_expression
|
||||
p3_x_2 = x_shifted
|
||||
p3_y_2 = y_shifted + sin_expression + side_length
|
||||
p4_x_2 = x_shifted + key_width / 2
|
||||
p4_y_2 = y_shifted + 2 * side_length
|
||||
p5_x_2 = x_shifted + key_width
|
||||
p5_y_2 = y_shifted + sin_expression + side_length
|
||||
p6_x_2 = x_shifted + key_width
|
||||
p6_y_2 = y_shifted + sin_expression
|
||||
|
||||
hexagon_shifted = draw.Lines(p1_x_2, p1_y_2, p2_x_2, p2_y_2, p3_x_2, p3_y_2, p4_x_2, p4_y_2, p5_x_2, p5_y_2, p6_x_2, p6_y_2, fill='none', stroke='black', close='true', stroke_width=0.1)
|
||||
canvas_shifted.append(hexagon_shifted)
|
||||
|
||||
x_shifted = x_shifted + distance
|
||||
|
||||
if i % 2 == 0:
|
||||
x_shifted = 0
|
||||
else:
|
||||
x_shifted = distance / 2
|
||||
|
||||
y_shifted = y_shifted + distance_y
|
||||
i = i + 1
|
||||
canvas_shifted.save_svg('hex2.svg')
|
||||
|
||||
canvas.save_svg('hex.svg')
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ class Hexagon:
|
|||
assert val >= 0, "bridge width can not be negative"
|
||||
self.__bridge_width = val
|
||||
|
||||
def hexagon_generation(self, filetype='svg'):
|
||||
def hexagon_generation(self, filetype='svg', generate_shifted_pattern=True):
|
||||
assert filetype == 'svg' or 'png', "Dateityp mus svg oder png sein"
|
||||
|
||||
i = 1
|
||||
|
@ -158,6 +158,9 @@ class Hexagon:
|
|||
|
||||
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 + (2 * side_length) < self.__height:
|
||||
while x + self.__key_width < self.__length:
|
||||
p1_x = x + self.__key_width / 2
|
||||
|
@ -187,6 +190,49 @@ class Hexagon:
|
|||
y = y + distance_y
|
||||
i = i + 1
|
||||
|
||||
if generate_shifted_pattern:
|
||||
x_shifted = distance / 2
|
||||
y_shifted = distance / (2 * math.sqrt(3))
|
||||
|
||||
canvas_shifted = draw.Drawing(self.__length, self.__height, origin=(0, 0))
|
||||
|
||||
canvas_shifted.append(alignment_dot)
|
||||
|
||||
while y_shifted + (2 * side_length) < self.__height:
|
||||
while x_shifted + self.__key_width < self.__length:
|
||||
p1_x_2 = x_shifted + self.__key_width / 2
|
||||
p1_y_2 = y_shifted
|
||||
p2_x_2 = x_shifted
|
||||
p2_y_2 = y_shifted + sin_expression
|
||||
p3_x_2 = x_shifted
|
||||
p3_y_2 = y_shifted + sin_expression + side_length
|
||||
p4_x_2 = x_shifted + self.__key_width / 2
|
||||
p4_y_2 = y_shifted + 2 * side_length
|
||||
p5_x_2 = x_shifted + self.__key_width
|
||||
p5_y_2 = y_shifted + sin_expression + side_length
|
||||
p6_x_2 = x_shifted + self.__key_width
|
||||
p6_y_2 = y_shifted + sin_expression
|
||||
|
||||
hexagon_shifted = draw.Lines(p1_x_2, p1_y_2, p2_x_2, p2_y_2, p3_x_2, p3_y_2, p4_x_2, p4_y_2, p5_x_2,
|
||||
p5_y_2, p6_x_2, p6_y_2, fill='none', stroke='black', close='true',
|
||||
stroke_width=0.1)
|
||||
canvas_shifted.append(hexagon_shifted)
|
||||
|
||||
x_shifted = x_shifted + distance
|
||||
|
||||
if i % 2 == 0:
|
||||
x_shifted = 0
|
||||
else:
|
||||
x_shifted = distance / 2
|
||||
|
||||
y_shifted = y_shifted + distance_y
|
||||
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':
|
||||
|
@ -302,6 +348,7 @@ if __name__ == '__main__':
|
|||
shape = int(input("Form (1: Kreis, 2: Hexagon, 3: Dreieck):"))
|
||||
|
||||
filetype = 'svg'
|
||||
shift = True
|
||||
|
||||
if shape == 1:
|
||||
circle = Circle(name, path)
|
||||
|
@ -341,17 +388,19 @@ if __name__ == '__main__':
|
|||
print("ungültiger Wert")
|
||||
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")
|
||||
|
||||
circle.circle_generation(filetype)
|
||||
|
||||
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. 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: True\n6. Dateityp: svg\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: Schlüsselweite, 4: Stegbreite, 5: Dateityp):"))
|
||||
parameter_selection = int(input("Parameter ändern (0: keinen Parameter ändern, 1: Höhe, 2: Länge, 3: Schlüsselweite, 4: Stegbreite, 5: Versetztes Muster, 6: Dateityp):"))
|
||||
if parameter_selection == 0:
|
||||
selection_flag = False
|
||||
elif parameter_selection == 1:
|
||||
|
@ -367,6 +416,14 @@ 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):"))
|
||||
if shift_select == 0:
|
||||
shift = False
|
||||
elif shift_select == 1:
|
||||
shift = True
|
||||
else:
|
||||
raise ValueError
|
||||
elif parameter_selection == 6:
|
||||
filetype_selection = int(input(f"1: {name}.svg, 2: {name}.png:"))
|
||||
if filetype_selection == 1:
|
||||
filetype = "svg"
|
||||
|
@ -381,7 +438,11 @@ if __name__ == '__main__':
|
|||
except AssertionError as error:
|
||||
print(error)
|
||||
|
||||
hexagon.hexagon_generation(filetype)
|
||||
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")
|
||||
|
||||
hexagon.hexagon_generation(filetype, shift)
|
||||
|
||||
elif shape == 3:
|
||||
triangle = Triangle(name, path)
|
||||
print(
|
||||
|
@ -419,6 +480,8 @@ if __name__ == '__main__':
|
|||
print("ungültiger Wert")
|
||||
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")
|
||||
|
||||
triangle.triangle_generation(filetype)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue