-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiag2.py
50 lines (44 loc) · 1004 Bytes
/
diag2.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
import turtle
import time
# create a turtle object
t = turtle.Turtle()
t.screen.bgcolor('black')
# set the turtle speed and color
t.speed(0)
t.color('red')
# define a function to draw the heart
def draw_heart(size):
t.penup()
t.goto(0, -size)
t.pendown()
t.begin_fill()
t.left(45)
t.forward(size)
t.circle(size/2, 180)
t.right(90)
t.circle(size/2, 180)
t.forward(size)
t.end_fill()
t.right(135)
# define a function to morph the heart
def morph_heart(size):
t.clear()
for i in range(20):
t.penup()
t.goto(0, -size)
t.pendown()
t.begin_fill()
t.left(45)
t.forward(size)
t.circle(size/2 + i*5, 180)
t.right(90)
t.circle(size/2 + i*5, 180)
t.forward(size)
t.end_fill()
t.right(135)
time.sleep(0.1)
t.clear()
# draw the heart and morph it
size = 100
draw_heart(size)
morph_heart(size)