1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Python | 使用turtle库画笑脸滑稽表情

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

时间:2023-01-02 09:08:20

相关推荐

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')

则打印结果为:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。