from math import from tkinter import int input root Tk canv Canvas roo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from math import *
from tkinter import *
k = int(input())
root = Tk()
canv = Canvas(root, width = 600,height = 600, bg = 'green')
x = 30;y = 30;x2 = 570;y2 = 570
points1 = [(x,y),(x2,y2)]
for i in range(k):
points2 = []
for j in range(len(points1)):
if j%2 == 0:
x = round(points1[j][0])
y = round(points1[j][1])
x2 = round(points1[j+1][0])
y2 = round(points1[j+1][1])
l = round(sqrt((x2-x)**2+(y2-y)**2)+0.51)
p01 = x;p02 = y;p03 = x2;p04 = y2
p = x + round((x2-x)/3+0.51)
p2 = y + round((y2-y)/3+0.51)
p3 = x + round(2*(x2-x)/3+0.51)
p4 = y + round(2*(y2-y)/3+0.51)
p5 = round((x2+x)/2+(l/(2*sqrt(3)))*sin((y2-y)/l)+0.51)
p6 = round((y2+y)/2-(l/(2*sqrt(3)))*cos((x2-x)/l)+0.51)
points2.append((p01,p02))
points2.append((p, p2))
points2.append((p, p2))
points2.append((p5, p6))
points2.append((p5, p6))
points2.append((p3, p4))
points2.append((p3, p4))
points2.append((p03, p04))
points1 = points2
print(points1)
canv.create_line(points1,width = 1,fill = 'yellow',smooth = 1)
canv.pack()
root.mainloop()