from tkinter import from math import def square xa ya xb yb xc yc xd y

 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from tkinter import *
from math import *
def square(xa, ya, xb, yb, xc, yc, xd, yd, N):
if N == 1:
return
line = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5
canvas.create_line(xa, ya, xb, yb, width=3, fill='black')
canvas.create_line(xb, yb, xc, yc, width=3, fill='black')
canvas.create_line(xc, yc, xd, xd, width=3, fill='black')
canvas.create_line(xd, yd, xa, ya, width=3, fill='black')
xe1 = (xa + k * xb) / (1 + k)
ye1 = (ya + k * yb) / (1 + k)
xe2 = (xb + k * xc) / (1 + k)
ye2 = (yb + k * yc) / (1 + k)
xe3 = (xc + k * xd) / (1 + k)
ye3 = (yc + k * yd) / (1 + k)
xe4 = (xd + k * xa) / (1 + k)
ye4 = (yd + k * ya) / (1 + k)
square(xe1, ye1, xe2, ye2, xe3, ye3, xe4, ye4, N - 1)
root = Tk()
N = int(input())
k = 0.08
X1 = 200
Y1 = 200
X2 = 500
Y2 = 200
L = ((X1 - X2) ** 2 + (Y1 - Y2) ** 2) ** 0.5
Xe1 = (X1 + k * X2) / (1 + k)
Ye1 = (Y1 + k * Y2) / (1 + k)
Xe2 = (X2 + k * X2) / (1 + k)
Ye2 = (Y2 + k * (Y2 + L)) / (1 + k)
Xe3 = (X2 + k * X1) / (1 + k)
Ye3 = (Y2 + L + k * (Y1 + L)) / (1 + k)
Xe4 = (X1 + k * X1) / (1 + k)
Ye4 = (Y1 + L + k * Y1) / (1 + k)
canvas = Canvas(root, width=750, height=750, bg='white')
canvas.create_line(X1, Y1, X2, Y2, width=3, fill='black')
canvas.create_line(X1, Y1, X1, Y1 + L, width=3, fill='black')
canvas.create_line(X2, Y2, X2, Y2 + L, width=3, fill='black')
canvas.create_line(X1, Y1 + L, X2, Y2 + L, width=3, fill='black')
square(Xe1, Ye1, Xe2, Ye2, Xe3, Ye3, Xe4, Ye4, N)
canvas.pack()
root.mainloop()