Квадрат в квадрате

 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
from math import *
from tkinter import *
root = Tk()
canv = Canvas(root, width = 1000, height = 1000, bg = "maroon")
def cvadrat(x1,y1, x2,y2, x3,y3, x4,y4, k):
if k==0:
canv.create_line(x1,y1, x2,y2, width = 2)
canv.create_line(x2,y2, x3,y3, width = 2)
canv.create_line(x3,y3, x4,y4, width = 2)
canv.create_line(x4,y4, x1,y1, width = 2)
return
else:
x5 = int((x1 + x2)/2 + 0.5)
y5 = int((y1 + y2)/2 + 0.5)
x6 = int((x2 + x3)/2 + 0.5)
y6 = int((y2 + y3)/2 + 0.5)
x7 = int((x3 + x4)/2 + 0.5)
y7 = int((y3 + y4)/2 + 0.5)
x8 = int((x4 + x1)/2 + 0.5)
y8 = int((y4 + y1)/2 + 0.5)
canv.create_line(x1,y1, x2,y2, width = 2)
canv.create_line(x2,y2, x3,y3, width = 2)
canv.create_line(x3,y3, x4,y4, width = 2)
canv.create_line(x4,y4, x1,y1, width = 2)
cvadrat(x5,y5, x6,y6, x7,y7, x8,y8, k-1)
cvadrat(100,500, 100,100, 500,100, 500,500, 10)
canv.pack()
root.mainloop()