Python | 使用turtle库画笑脸滑稽表情

  代码如下:

from turtle import *

speed(0)  # 最快的画笔速度

# 画圆脸
setup(600, 600, 0, 0)
penup()
fd(-200)
pendown()
color('yellow', 'yellow')
begin_fill()
seth(-90)
circle(200)
end_fill()

# 画嘴巴
penup()
seth(0)
fd(10)
pendown()
pensize(3)  # 调整画笔大小
color('red')
seth(-90)
circle(190, 180)

# 画眼睛
penup()
fd(100)
seth(180)
fd(573)
for i in range(2):  # 给画两只眼睛制造相同代码,才可以使用for循环,绘制两只眼睛
    penup()
    seth(0)
    fd(200)
    pendown()
    pensize(2)
    seth(20)
    color('black', 'white')
    begin_fill()
    circle(-230, 40)
    circle(-10, 180)
    circle(210, 40)
    circle(-10, 180)
    end_fill()
    color('black', 'black')
    begin_fill()
    circle(-10)
    end_fill()

# #画左眉毛
penup()
home()
fd(-160)
seth(90)
fd(120)
pendown()
color('black')
begin_fill()
seth(53)
circle(-200, 15)
seth(10)
circle(-50, 50)
seth(120)
circle(42, 150)
end_fill()

# #画右眉毛
penup()
home()
fd(160)
seth(90)
fd(120)
pendown()
color('black')
begin_fill()
seth(127)
circle(200, 15)
seth(170)
circle(50, 50)
seth(60)
circle(-42, 150)
end_fill()

# 笔回到中心点
penup()
home()

# 不关闭画布页面
done()

打印结果如下:

其中,第10行代码控制圆脸的颜色:

color('yellow', 'yellow')

若改为:

color('green', 'green')

打印结果为:

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值