python海龟绘图画狗狗
时间: 2023-11-20 15:07:59 浏览: 123
python-海龟绘图
以下是使用Turtle库在Python中绘制狗狗的代码:
```python
import turtle
# 设置画笔
pen = turtle.Turtle()
pen.speed(10)
pen.pensize(5)
# 画头
pen.fillcolor("#F5DEB3")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 画耳朵
pen.fillcolor("#F5DEB3")
pen.begin_fill()
pen.right(90)
pen.forward(150)
pen.left(120)
pen.forward(150)
pen.left(120)
pen.forward(150)
pen.end_fill()
pen.fillcolor("#F5DEB3")
pen.begin_fill()
pen.right(60)
pen.forward(150)
pen.left(120)
pen.forward(150)
pen.left(120)
pen.forward(150)
pen.end_fill()
# 画眼睛
pen.penup()
pen.goto(-50, 200)
pen.pendown()
pen.fillcolor("#FFFFFF")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(50, 200)
pen.pendown()
pen.fillcolor("#FFFFFF")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(-50, 220)
pen.pendown()
pen.fillcolor("#000000")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(50, 220)
pen.pendown()
pen.fillcolor("#000000")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 画鼻子
pen.penup()
pen.goto(0, 150)
pen.pendown()
pen.fillcolor("#000000")
pen.begin_fill()
pen.circle(30)
pen.end_fill()
# 画嘴巴
pen.penup()
pen.goto(-50, 100)
pen.pendown()
pen.right(90)
pen.circle(50, 180)
# 画身体
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.fillcolor("#F5DEB3")
pen.begin_fill()
pen.circle(150)
pen.end_fill()
# 画腿
pen.penup()
pen.goto(-70, -200)
pen.pendown()
pen.fillcolor("#F5DEB3")
pen.begin_fill()
pen.right(30)
pen.forward(100)
pen.left(120)
pen.forward(100)
pen.left(120)
pen.forward(100)
pen.end_fill()
pen.penup()
pen.goto(70, -200)
pen.pendown()
pen.fillcolor("#F5DEB3")
pen.begin_fill()
pen.right(30)
pen.forward(100)
pen.left(120)
pen.forward(100)
pen.left(120)
pen.forward(100)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
阅读全文