from math import from Tkinter import def Koh x1 y1 x2 y2 if canv creat

 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
from math import *
from Tkinter import *
def Koh(x1,y1,x2,y2,k):
if k == 0:
canv.create_line(x1, y1, x2, y2, width = 2)
return
else:
x3=int((x1+2*x2)/3)
y3=int((y1+2*y2)/3)
x4=int((2*x1+x2)/3)
y4=int((2*y1+y2)/3)
x5=int(x3+(y2-y1)/(12**0.5))
y5=int(y3-(x2-x1)/(12**0.5))
x6=int(x4+(y2-y1)/(12**0.5))
y6=int(y4-(x2-x1)/(12**0.5))
Koh(x1,y1,x3,y3,k-1)
Koh(x3,y3,x5,y5,k-1)
Koh(x5,y5,x6,y6,k-1)
Koh(x6,y6,x4,y4,k-1)
Koh(x4,y4,x2,y2,k-1)
a1 = 150; b1 = 250
a2 = 350; b2 = 250
a3 = 350; b3 = 250
I1 = 0; J1 = 0
I2 = 500; J2 = 500
root = Tk()
root.title('Коh')
canv = Canvas(root, width = I2 + 50, height = J2 + 50, bg = 'red')
Koh(a1, b1, a2, b2, 1)
Koh(a2, b2, a3, b3, 1)
Koh(a1, a1, a3, b3, 1)
canv.pack()
root.mainloop()