使用python的非turtle库画一个笑脸
时间: 2024-04-20 07:16:03 浏览: 96
可以使用Python的matplotlib库来画一个笑脸。以下是代码示例:
```python
import matplotlib.pyplot as plt
# 画圆形
circle = plt.Circle((0, 0), 1, color='yellow')
# 画眼睛
left_eye = plt.Circle((-0.4, 0.4), 0.15, color='black')
right_eye = plt.Circle((0.4, 0.4), 0.15, color='black')
# 画嘴巴
mouth = plt.Rectangle((-0.4, -0.6), 0.8, 0.3, color='black', angle=15)
# 将所有元素放在一起
fig, ax = plt.subplots()
ax.add_artist(circle)
ax.add_artist(left_eye)
ax.add_artist(right_eye)
ax.add_artist(mouth)
# 调整坐标轴范围和显示效果
plt.axis('scaled')
plt.axis([-1.2, 1.2, -1.2, 1.2])
plt.axis('off')
# 显示笑脸
plt.show()
```
输出结果如下所示:

相关问题
Python调用turtle库画一个五边形
好的,这里是使用Python调用turtle库画一个五边形的代码:
```python
import turtle
# 创建一个Turtle实例
t = turtle.Turtle()
# 设置画笔颜色和画笔宽度
t.color("red")
t.pensize(3)
# 循环画五边形的五条边
for i in range(5):
t.forward(100) # 向前走100个单位长度
t.right(72) # 向右转72度
# 隐藏画笔
t.hideturtle()
# 显示画布
turtle.done()
```
运行这段代码,就可以在画布上看到一个红色的五边形了。
使用Python的turtle库画出一个奥特曼打怪兽
好的,以下是使用Python的turtle库画出一个奥特曼打怪兽的代码示例:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 画奥特曼
def draw_ultraman():
pen.penup()
pen.goto(-100, 0)
pen.pendown()
pen.color('red', 'red')
pen.begin_fill()
pen.left(45)
pen.forward(100)
pen.circle(50, 180)
pen.forward(100)
pen.left(90)
pen.circle(50, 180)
pen.forward(100)
pen.end_fill()
# 画怪兽
def draw_monster():
pen.penup()
pen.goto(100, 0)
pen.pendown()
pen.color('green', 'green')
pen.begin_fill()
pen.right(45)
pen.forward(100)
for i in range(4):
pen.circle(-50, 90)
pen.end_fill()
# 奥特曼打怪兽
def ultraman_vs_monster():
pen.penup()
pen.goto(-50, 50)
pen.pendown()
pen.color('blue')
pen.write('奥特曼\nVS\n怪兽', font=('Arial', 20, 'normal'))
pen.penup()
pen.goto(-80, -50)
pen.pendown()
pen.color('white')
pen.write('攻击!', font=('Arial', 20, 'normal'))
pen.penup()
pen.goto(-100, -100)
pen.pendown()
pen.color('yellow')
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 调用函数画图
draw_ultraman()
draw_monster()
ultraman_vs_monster()
# 隐藏画笔并保持画面不关闭
pen.hideturtle()
turtle.done()
```
运行该程序,即可在屏幕上看到一个奥特曼打怪兽的画面。
阅读全文
相关推荐
















