задача Серпинского

 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
from math import *
from tkinter import *
root = Tk()
canv = Canvas(root, width = 1000, height = 1000, bg = "maroon")
def triangle(x1,y1,x2,y2,x3,y3,k):
if k==0:
canv.create_line(x1,y1,x2,y2, width =2)
canv.create_line(x3,y3,x2,y2, width =2)
canv.create_line(x1,y1,x3,y3, width =2)
return
else:
x6=(x1+x2)//2
y6=(y1+y2)//2
x4=(x1+x3)//2
y4=(y1+y3)//2
y5=(y2+y3)//2
x5=(x2+x3)//2
triangle(x1, y1, x6,y6, x4,y4, k-1)
triangle(x2, y2, x6,y6, x5,y5, k-1)
triangle(x3, y3, x5,y5, x4,y4, k-1)
triangle(450, 110, 690, 550, 210, 550, 7)
canv.pack()
root.mainloop()