from math import from tkinter import root Tk canv Canvas root width 10

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