задача Кантора

 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
from math import *
from tkinter import *
root = Tk()
canv = Canvas(root, width = 1000, height = 1000, bg = "navy")
def kantor(x1, y1, x2, y2, k):
if k == 0:
canv.create_rectangle(x1,y1, x2,y2, width = 1, fill="maroon", outline="black")
return
else:
x3 = x1 - (x2-x1)//4
y3 = y1 - (y2-y1)//4
x4 = x1 + (x2-x1)//4
y4 = y1 + (y2-y1)//4
kantor(x3, y3, x4, y4, k-1)
x5 = x2 - (x2-x1)//4
y5 = y3
x6 = x2 + (x2-x1)//4
y6 = y4
kantor(x5, y5, x6, y6, k-1)
x7 = x3
y7 = y2 - (y2-y1)//4
x8 = x4
y8 = y2 + (y2-y1)//4
kantor(x7, y7, x8, y8, k-1)
x9 = x5
y9 = y2 - (y2-y1)//4
x10 = x6
y10 = y2 + (y2-y1)//4
kantor(x9, y9, x10, y10, k-1)
canv.create_rectangle(x1, y1, x2, y2, width = 1, fill = "maroon", outline = "black")
kantor(200, 200, 500, 500, 7)
canv.pack()
root.mainloop()