48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
|
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')
|