如何用python画一张狗头
时间: 2023-05-30 15:07:48 浏览: 739
python画柯南代码直接用
5星 · 资源好评率100%
由于狗头的形态多种多样,因此需要先确定要画的狗头种类。以下是一个简单的示例,画一只柯基犬的狗头:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔颜色和线宽
pen.color("brown")
pen.pensize(4)
# 画狗头轮廓
pen.penup()
pen.goto(0, -200)
pen.pendown()
pen.circle(200)
# 画眼睛
pen.penup()
pen.goto(-70, 80)
pen.pendown()
pen.fillcolor("white")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(70, 80)
pen.pendown()
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.fillcolor("black")
pen.penup()
pen.goto(-70, 100)
pen.pendown()
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(70, 100)
pen.pendown()
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 画嘴巴和舌头
pen.penup()
pen.goto(0, 20)
pen.pendown()
pen.fillcolor("pink")
pen.begin_fill()
pen.circle(70, 180)
pen.end_fill()
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.fillcolor("red")
pen.begin_fill()
pen.circle(30)
pen.end_fill()
# 画耳朵
pen.penup()
pen.goto(-120, 220)
pen.pendown()
pen.fillcolor("brown")
pen.begin_fill()
for i in range(2):
pen.forward(100)
pen.left(120)
pen.end_fill()
pen.penup()
pen.goto(120, 220)
pen.pendown()
pen.begin_fill()
for i in range(2):
pen.forward(100)
pen.right(120)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 显示画布
canvas.mainloop()
```
该代码使用turtle库的函数来绘制狗头的轮廓、眼睛、嘴巴、舌头和耳朵等部分,最终效果如下:
![corgi](https://i.imgur.com/1tFyJtM.png)
阅读全文