DreickeGen2.py erstellt

This commit is contained in:
Mika 2023-11-03 16:07:39 +01:00
parent f4bf49c6d4
commit a140a86424

48
DreickeGen2.py Normal file
View File

@ -0,0 +1,48 @@
import drawsvg as draw
import math
height = 1000
length = 1000
side_length = 80
bridge_width = 5
distance = bridge_width / math.sin(math.radians(60))
x = 0
y = 0
i = 1
canvas = draw.Drawing(length, height, origin=(0, 0))
while y + math.sqrt(3) / 2 * side_length <= height:
while x + 1.5 * side_length + distance <= length:
triangle1_p1_x = x
triangle1_p1_y = y
triangle1_p2_x = x + side_length
triangle1_p2_y = y
triangle1_p3_x = x + math.sin(math.radians(30)) * side_length
triangle1_p3_y = y + math.cos(math.radians(30)) * side_length
triangle = draw.Lines(triangle1_p1_x, triangle1_p1_y, triangle1_p2_x, triangle1_p2_y, triangle1_p3_x, triangle1_p3_y, close='true', stroke='black', fill='none')
canvas.append(triangle)
x = x + side_length + distance
triangle2_p1_x = x
triangle2_p1_y = y
triangle2_p2_x = x - side_length / 2
triangle2_p2_y = y + math.sqrt(3) / 2 * side_length
triangle2_p3_x = x + side_length / 2
triangle2_p3_y = triangle2_p2_y
triangle2 = draw.Lines(triangle2_p1_x, triangle2_p1_y, triangle2_p2_x, triangle2_p2_y, triangle2_p3_x, triangle2_p3_y, close='true', stroke='black', fill='none')
canvas.append(triangle2)
x = x + distance
if i % 2 == 0:
x = 0
else:
x = side_length / 2 + distance
y = y + bridge_width + math.sqrt(3) / 2 * side_length
i = i + 1
canvas.save_svg('dreieck.svg')