-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion_street.py
More file actions
89 lines (72 loc) · 1.67 KB
/
recursion_street.py
File metadata and controls
89 lines (72 loc) · 1.67 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
##############################################################################
# The program do not nothing special, only shows paint a street homes via
# recursion with turtle
##############################################################################
import turtle
import time
import random
turtle.tracer(2, 1)
t = turtle.Turtle()
def home():
t.pu()
t.home()
t.pd()
def wall(length, color_wall="red"):
t.pencolor(color_wall)
t.pensize(2)
t.lt(90)
t.pu()
t.setx(x)
t.sety(y)
t.pd()
def wall_r(n, length):
if n == 0:
return 0
else:
t.fd(length)
t.rt(90)
wall_r(n - 1, length)
wall_r(4, length)
home()
def top(length, color_top="brown"):
t.pencolor(color_top)
t.pensize(2)
t.pu()
t.setx(x)
t.sety(y + length)
t.pd()
def top_r(n, length):
if n == 0:
pass
else:
t.fd(length)
t.lt(120)
top_r(n - 1, length)
top_r(3, length)
home()
def house(length, color_top, color_wall):
wall(length, color_wall)
top(length, color_top)
def street(n):
global x
# for i in range(10,80,2):
# length = i
# house(length,color_top,color_wall)
# x += length
if n < 20:
pass
else:
length = n
house(length, color_top, color_wall)
x += length
street(n - 5)
house(length, color_top, color_wall)
x += length
x, y = -700, 50
length = 80
color_wall, color_top = "blue", "red"
# house(length, color_top, color_wall)
# top(length, color_top)
# street([10,20,50,20,80,100,55,68,30])
street(80)
time.sleep(3)