参考博客1
参考博客2
参考博客3
import turtle
def draw_heart():
#画心形
t = turtle.Turtle()
t.pencolor("pink") #定义画笔颜色
t.fillcolor("pink") #绘制图形的填充颜色
t.pensize(1) #设置画笔的宽度
t.penup() #移动时不绘制图形,提起笔,用于另起一个地方绘制时用
t.begin_fill() #准备开始填充图形
t.goto(0,0) #将画笔移动到坐标为(x, y)的位置
t.pendown() #移动时绘制图形,缺省时也为绘制
t.left(90) #逆时针移动degree°
t.circle(120,180) #画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆
t.circle(360,70)
t.left(38)
t.circle(360,70)
t.circle(120,180)
t.end_fill()
import turtle
def initialization():
'''
初始化画布和画笔
'''
turtle.setup(width=0.9, height=0.9)
turtle.speed(10)
def flower():
'''
勾勒出花蕊
'''
turtle.goto(0, 200) #将画笔移动到坐标为(x, y)的位置
turtle.fillcolor("red") #绘制图形的填充颜色
turtle.begin_fill() #准备开始填充图形
turtle.circle(10, 180) #画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆,第一个为半径大小,第二个为度数
turtle.circle(25, 110)
turtle.left(50) #逆时针移动degree°
turtle.circle(60, 45)
turtle.circle(20, 170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30, 110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90, 70)
turtle.circle(30, 150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80, 90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()
def peta1():
'''
勾勒花瓣1
'''
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)
def peta2():
'''
勾勒花瓣2
'''
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)
def leaf1():
'''
勾勒叶子1
'''
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80, 90)
turtle.right(90)
turtle.circle(-80, 90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
def leaf2():
'''
勾勒叶子2
'''
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80, 90)
turtle.left(90)
turtle.circle(80, 90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200, 60)
if __name__ == '__main__':
initialization() #初始化画布和画笔
flower()
peta1()
peta2()
leaf1()
leaf2()
import turtle
import time
t = turtle.Turtle()
t.pensize(10) # 定义画笔的宽度
t.pencolor("yellow") # 定义画笔颜色
t.fillcolor("red") # 定义填充颜色
t.begin_fill() # 开始填充图像
for i in range(5): # 五角星循环五次
t.forward(500)
t.right(144) # 右转144°
t.end_fill() # 停止填充
time.sleep(2) # 阻塞两秒
t.penup() # 提起笔,移动时不绘制图形
t.goto(-150, 120) # 将画笔移动到某坐标点
t.color("violet")
t.write("Done", font=('Arial', 40, 'normal')) # 设置文字和字体
time.sleep(5)