-
Notifications
You must be signed in to change notification settings - Fork 0
/
recursiveHeart.py
51 lines (41 loc) · 960 Bytes
/
recursiveHeart.py
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
# Draw a Recursive Heart with Turtle Module
import turtle
# Recursive function
def heart(turt, stride):
# Base case
if stride < 1:
return
# Heart drawing parameters
adjust = 1.25
turt.width(stride)
# Draw the heart
for _ in range(50):
turt.forward(stride)
turt.right(5)
for _ in range(20):
turt.forward(adjust*stride)
turt.left(3)
turt.forward(adjust*stride)
turt.right(160)
for _ in range(20):
turt.forward(adjust*stride)
turt.left(3)
for _ in range(50):
turt.forward(stride)
turt.right(5)
turt.forward(stride)
turt.left(180)
# Recursively draw smaller hearts until base case reached
heart(turt, stride-1)
# Instantiate turtle object
t = turtle.Turtle()
t.color('red')
t.speed(100)
t.hideturtle()
t.up()
# Put turtle into correct initial position
t.left(90)
t.forward(100)
t.down()
# Draw five hearts
heart(t, 5)