python海龟绘图画小狗
时间: 2023-12-07 09:39:49 浏览: 128
python-海龟绘图
以下是使用Turtle库在Python中绘制小狗的代码示例:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("white")
# 画小狗的头部
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.fillcolor("#F5DEB3")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画小狗的耳朵
turtle.penup()
turtle.goto(-150, 150)
turtle.pendown()
turtle.fillcolor("#F5DEB3")
turtle.begin_fill()
turtle.right(45)
turtle.forward(70)
turtle.right(180)
turtle.circle(-30, -180)
turtle.right(180)
turtle.forward(70)
turtle.end_fill()
turtle.penup()
turtle.goto(-50, 150)
turtle.pendown()
turtle.fillcolor("#F5DEB3")
turtle.begin_fill()
turtle.left(90)
turtle.forward(70)
turtle.right(180)
turtle.circle(30, -180)
turtle.right(180)
turtle.forward(70)
turtle.end_fill()
# 画小狗的眼睛
turtle.penup()
turtle.goto(-80, 120)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-20, 120)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画小狗的鼻子
turtle.penup()
turtle.goto(-50, 80)
turtle.pendown()
turtle.fillcolor("#FFA07A")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画小狗的嘴巴
turtle.penup()
turtle.goto(-70, 60)
turtle.pendown()
turtle.right(90)
turtle.circle(20, 180)
# 画小狗的身体
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.fillcolor("#F5DEB3")
turtle.begin_fill()
turtle.right(45)
turtle.forward(150)
turtle.right(180)
turtle.circle(-30, -180)
turtle.right(180)
turtle.forward(150)
turtle.right(180)
turtle.right(45)
turtle.forward(100)
turtle.right(90)
turtle.circle(50, -180)
turtle.right(90)
turtle.forward(100)
turtle.end_fill()
# 画小狗的腿
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
turtle.fillcolor("#F5DEB3")
turtle.begin_fill()
turtle.right(45)
turtle.forward(70)
turtle.right(180)
turtle.circle(-30, -180)
turtle.right(180)
turtle.forward(70)
turtle.end_fill()
turtle.penup()
turtle.goto(-50, -50)
turtle.pendown()
turtle.fillcolor("#F5DEB3")
turtle.begin_fill()
turtle.right(180)
turtle.forward(70)
turtle.right(180)
turtle.circle(30, -180)
turtle.right(180)
turtle.forward(70)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
阅读全文