Решето

 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
from math import *
from tkinter import *
root = Tk()
canv = Canvas(root, width = 1000, height = 1000, bg = "navy")
def resheto(x1, y1, x4, y4, k):
if k == 0:
canv.create_rectangle(x1,y1, x4,y4, fill = "maroon", outline = "maroon")
return
else:
canv.create_rectangle(x1,y1, x4,y4, fill = "maroon", outline = "maroon")
xa = x4 - x1
ya = y4 - y1
x2 = x1 + int( xa/3 + 0.5)
x3 = x1 + int(2*xa/3 + 0.5)
y2 = y1 + int( ya/3 + 0.5)
y3 = y1 + int(2*ya/3 + 0.5)
resheto(x1, y1, x2, y2, k-1)
resheto(x2, y1, x3, y2, k-1)
resheto(x3, y1, x4, y2, k-1)
resheto(x1, y2, x2, y3, k-1)
resheto(x2, y2, x3, y3, k-1)
resheto(x3, y2, x4, y3, k-1)
resheto(x1, y3, x2, y4, k-1)
resheto(x2, y3, x3, y4, k-1)
resheto(x3, y3, x4, y4, k-1)
canv.create_rectangle(x2,y2, x3,y3, fill = "navy", outline = "green")
resheto(100, 50, 750, 700, 5)
canv.pack()
root.mainloop()