用python的turtle库画QQ表情

前言

phthon海龟绘图官方文档(中文版):https://docs.python.org/zh-cn/3.7/library/turtle.html
RGB配色表:http://www.wahart.com.hk/rgb.htm
很好玩,有些可能不是特别像哈哈哈
2019-5-13 微笑
2019-5-14 难过
2019-5-19 滑稽
2019-5-28 撇嘴

QQ表情

微笑

效果:

代码:

import turtle as t
#t.speed(20)
t.pensize(5)
#脸
t.pencolor("orange")
t.begin_fill()
t.penup()
t.goto(0,-200)
t.pendown()
t.fillcolor("yellow")
t.circle(200)
t.end_fill()
#嘴
t.pencolor("brown")
t.penup()
t.goto(0,-140)
t.pendown()
t.circle(120,60)
t.left(180)
t.circle(-120,120)
t.seth(0)
#眼睛
t.pensize(3)
 #右眼
t.penup()
t.goto(80,75)
t.pendown()
t.begin_fill()
t.circle(35)
t.fillcolor("white")
t.end_fill()
t.pencolor("black")
t.begin_fill()
t.circle(23)
t.fillcolor("black")
t.end_fill()
 #左眼
t.pencolor("brown")
t.penup()
t.goto(-80,75)
t.pendown()
t.begin_fill()
t.circle(35)
t.fillcolor("white")
t.end_fill()
t.pencolor("black")
t.begin_fill()
t.circle(23)
t.fillcolor("black")
t.end_fill()
t.hideturtle()
t.done()

难过

改一下微笑的嘴部部分就行啦
效果:

代码:

import turtle as t
t.speed(20)
t.pensize(5)
#脸
t.pencolor("orange")
t.begin_fill()
t.penup()
t.goto(0,-200)
t.pendown()
t.fillcolor("Yellow1")
t.circle(200)
t.end_fill()
#嘴
t.pencolor("brown")
t.penup()
t.goto(0,-90)
t.pendown()
t.circle(-120,60)
t.left(180)
t.circle(120,120)
t.seth(0)
#眼睛
t.pensize(3)
 #右眼
t.penup()
t.goto(80,75)
t.pendown()
t.begin_fill()
t.circle(35)
t.fillcolor("white")
t.end_fill()
t.pencolor("black")
t.begin_fill()
t.circle(23)
t.fillcolor("black")
t.end_fill()
 #左眼
t.pencolor("brown")
t.penup()
t.goto(-80,75)
t.pendown()
t.begin_fill()
t.circle(35)
t.fillcolor("white")
t.end_fill()
t.pencolor("black")
t.begin_fill()
t.circle(23)
t.fillcolor("black")
t.end_fill()
t.hideturtle()
t.done()

滑稽

啊!!我的眼睛!!
效果:

代码:

import turtle as t
t.speed(20)
t.pensize(5)
#脸
t.pencolor("orange")
t.begin_fill()
t.penup()
t.goto(0,-200)
t.pendown()
t.fillcolor("Yellow1")
t.circle(200)
t.end_fill()
#嘴
t.pencolor("brown")
t.penup()
t.goto(0,-175)
t.pendown()
t.circle(170,80)
t.left(180)
t.circle(-170,160)
t.seth(0)
#眼睛
t.pensize(3)
 #右眼框
t.penup()
t.goto(30,75)
t.pendown()
t.seth(40)
t.fillcolor("white")
t.begin_fill()
t.circle(-110,95)
pos1=t.pos()
#print(pos1)
t.penup()
t.goto(30,75)
t.pendown()
t.seth(-140)
t.circle(18,180)
t.circle(-80,80)
t.goto(pos1)
t.end_fill()
 #右眼珠
t.pencolor("black")
t.penup()
t.goto(45,60)
t.pendown()
t.begin_fill()
t.fillcolor("black")
t.circle(8)
t.end_fill()

 #左眼框
t.pencolor("brown")
t.penup()
t.goto(-170,75)
t.pendown()
t.begin_fill()
t.fillcolor("white")
t.seth(40)
t.circle(-110,95)
pos2=t.pos()
t.penup()
t.goto(-170,75)
t.pendown()
t.seth(-140)
t.circle(18,180)
t.circle(-80,80)
t.goto(pos2)
t.end_fill()
 #左眼珠
t.pencolor("black")
t.penup()
t.goto(-155,60)
t.pendown()
t.begin_fill()
t.fillcolor("black")
t.circle(8)
t.end_fill()

#腮红
t.penup()
t.goto(150,-20)
t.pencolor("pink")
t.pendown()
t.begin_fill()
t.fillcolor("pink")
t.circle(30)
t.end_fill()

t.penup()
t.goto(-180,-20)
t.pencolor("pink")
t.pendown()
t.begin_fill()
t.fillcolor("pink")
t.circle(30)
t.end_fill()

t.hideturtle()
t.done()

撇嘴

在微笑的基础上改
效果:

代码:

import turtle as t
t.speed(20)
t.pensize(5)
#脸
t.pencolor("orange")
t.begin_fill()
t.penup()
t.goto(0,-200)
t.pendown()
t.fillcolor("Yellow1")
t.circle(200)
t.end_fill()
#嘴
t.pencolor("brown")
t.penup()
t.goto(-70,-100)
t.pendown()
t.seth(-40)
t.circle(30,80)
t.circle(-30,80)
t.circle(30,80)
t.circle(-30,80)
t.seth(0)
#眉毛
t.penup()
t.goto(-115,140)
t.pendown()
t.circle(50,90)
t.penup()
t.goto(120,160)
t.pendown()
t.seth(-180)
t.circle(-50,90)
#眼睛
t.seth(0)
t.pensize(3)
 #右眼
t.penup()
t.goto(80,75)
t.pendown()
t.begin_fill()
t.circle(35)
t.fillcolor("white")
t.end_fill()
t.pencolor("black")
t.begin_fill()
t.circle(23)
t.fillcolor("black")
t.end_fill()
 #左眼
t.pencolor("brown")
t.penup()
t.goto(-80,75)
t.pendown()
t.begin_fill()
t.circle(35)
t.fillcolor("white")
t.end_fill()
t.pencolor("black")
t.begin_fill()
t.circle(23)
t.fillcolor("black")
t.end_fill()

t.hideturtle()
t.done()
### 使用 Python Turtle 绘制哪吒 尽管 `turtle` 庿主要用于简单的绘图操作,但它可以通过组合基本形状和颜色来创建复杂的图案。要使用 `turtle` 绘制类似于哪吒这样的复杂图形,可以将其拆解为多个部分并逐步实现。 以下是基于 `turtle` 的示例代码,用于绘制一个简化版的哪吒形象: #### 示例代码 ```python import turtle # 初始化布 t = turtle.Turtle() screen = turtle.Screen() screen.setup(800, 600) # 设置速度 t.speed(10) # 提笔移动到起始位置 def move_to(x, y): t.penup() t.goto(x, y) t.pendown() # 绘制头部 move_to(0, -50) t.begin_fill() t.color("orange") t.circle(50) t.end_fill() # 绘制眼睛 move_to(-20, 30) t.begin_fill() t.color("white") t.circle(10) t.end_fill() move_to(20, 30) t.begin_fill() t.color("white") t.circle(10) t.end_fill() # 绘制眼珠 move_to(-20, 35) t.begin_fill() t.color("black") t.circle(5) t.end_fill() move_to(20, 35) t.begin_fill() t.color("black") t.circle(5) t.end_fill() # 绘制嘴巴 move_to(0, 10) t.width(3) t.color("red") t.right(90) t.forward(20) # 绘制头发 move_to(-70, 80) t.color("brown") t.left(45) for _ in range(3): t.forward(50) t.backward(50) t.right(30) # 绘制莲花宝座 move_to(0, -100) t.width(5) t.color("green") t.circle(100, steps=6) # 完成绘制 t.hideturtle() turtle.done() ``` 此代码实现了以下功能: - **头部**:通过圆圈函数完成[^1]。 - **眼睛与眼珠**:分别用白色和黑色的小圆表示。 - **嘴巴**:一条红色线段作为嘴部轮廓。 - **头发**:通过多次重复线条绘制简单发型。 - **莲花宝座**:六边形近似于莲花底座的效果。 #### 进一步优化建议 为了使图像更加生动,可考虑引入更多细节或动态效果: - 利用 `Pillow` 或其他高级加载外部 PNG 图像资源[^2]。 - 结合光影变化提升视觉体验。 - 添加动支持(如眨眼动作)以增加趣味性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值