from math import from tkinter import x1 x2 y1 y2 map int input split r

 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
from math import *
from tkinter import *
x1, x2, y1, y2, k = map(int, input().split())
root = Tk()
I1 = 0
J1 = 0
I2 = 500
J2 = 500
canv = Canvas(root, width = I2, height = J2, bg = 'lightblue')
def II(x):
return I1 + int((x - X1)*(I2 - I1)/(X2 - X1))
def JJ(y):
return J2 + int((y - Y1)*(J1 - J2)/(Y2 - Y1))
def koh(x1, x2, y1, y2, k):
if k >= 1:
x3 = x1 + int((x2 - x1) / 3 + 0.5)
y3 = y1 + int((y2 - y1) / 3 + 0.5)
x4 = x1 + int(2 * (x2 - x1) / 3 + 0.5)
y4 = y1 + int(2 * (y2 - y1) / 3 + 0.5)
x5 = (x3 + x4) / 2 + (y4 - y3) / 2 * sqrt(3)
y5 = (y3 + y4) / 2 - (x4 - x3) / 2 * sqrt(3)
canv.create_line(x1, y1, x3, y3, width = 2)
canv.create_line(x3, y3, x5, y5, width = 2)
canv.create_line(x5, y5, x4, y4, width = 2)
canv.create_line(x4, y4, x2, y2, width = 2)
canv.create_line(x4, y4, x3, y3, width = 3, fill = 'lightblue')
koh(x1, x3, y1, y3, k - 1)
koh(x3, x5, y3, y5, k - 1)
koh(x5, x4, y5, y4, k - 1)
koh(x4, x2, y4, y2, k - 1)
x6 = (x1 + x2) / 2 - (y2 - y1) / 2 * sqrt(3)
y6 = (y1 + y2) / 2 + (x2 - x1) / 2 * sqrt(3)
koh(x1, x2, y1, y2, k)
koh(x6, x1, y6, y1, k)
koh(x2, x6, y2, y6, k)
canv.pack()
root.mainloop()