截图:
代码:
import turtle
# 开始坐标 x,y 默认方向往左 心的下边长度len 画上边时距离length 转的次数num
def paint_heart(x, y, len, length, num):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color('red', 'red')
turtle.begin_fill()
turtle.right(60)
turtle.forward(len)
curve_move(length,num)
turtle.left(120)
curve_move(length,num)
turtle.forward(len)
turtle.end_fill()
def curve_move(length,num):
for i in range(num):
turtle.right(1)
turtle.forward(length)
def main():
# 小人的 设置画笔
turtle.pensize(3)
turtle.pencolor('black')
# 头 圆圈
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
turtle.circle(50)
# 左眼睛
turtle.penup()
turtle.goto(20, -8)
turtle.pendown()
turtle.circle(1)
# 右眼睛
turtle.penup()
turtle.goto(60, -8)
turtle.pendown()
turtle.circle(1)
# 嘴
turtle.penup()
turtle.goto(40, -30)
turtle.pendown()
turtle.circle(1)
# 上半截腿
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
turtle.right(90)
turtle.forward(70)
last_pos=turtle.pos() # 腿关节
# 下半截腿 右
turtle.left(45)
turtle.forward(70)
# 下半截腿 左
turtle.penup()
turtle.goto(last_pos)
turtle.pendown()
turtle.right(135)
turtle.forward(60)
turtle.left(90)
turtle.forward(60)
# 胳膊 上
turtle.penup()
turtle.goto(50, -75)
turtle.pendown()
turtle.right(110)
turtle.forward(70)
# 胳膊 下
turtle.penup()
turtle.goto(50, -75)
turtle.pendown()
turtle.left(40)
turtle.forward(70)
# 设置速度
turtle.delay(0)
# 心
paint_heart(-40, -85, 10.56, 0.1, 200)
turtle.right(20)
paint_heart(-85, -85, 10.56, 0.1, 200)
turtle.right(20)
paint_heart(-140, -85, 17, 0.15, 200)
# 写字
turtle.pencolor('black')
turtle.penup()
turtle.goto(130, -175)
turtle.pendown()
turtle.write('shmily')
# 隐藏箭头
turtle.hideturtle()
turtle.done()
if __name__ == '__main__':
main()