Python代码画一只懒羊羊
时间: 2023-11-21 19:07:10 浏览: 95
使用python画出一个懒羊羊代码(附详细注释)全
以下是一个简单的 Python 代码,可以画出一只懒羊羊的图形:
```python
import turtle
# 设置画布
canvas = turtle.Screen()
canvas.bgcolor("white")
# 创建画笔
pen = turtle.Turtle()
pen.speed(0)
pen.color("black")
pen.pensize(3)
# 画头部和身体
pen.penup()
pen.goto(-100, 0)
pen.pendown()
pen.circle(50)
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.circle(100)
# 画眼睛和嘴巴
pen.penup()
pen.goto(-80, 60)
pen.pendown()
pen.dot(25)
pen.penup()
pen.goto(80, 60)
pen.pendown()
pen.dot(25)
pen.penup()
pen.goto(0, 20)
pen.pendown()
pen.circle(30, 180)
# 画腿
pen.penup()
pen.goto(-60, -100)
pen.pendown()
pen.right(45)
pen.forward(80)
pen.back(80)
pen.left(90)
pen.forward(80)
pen.back(80)
pen.right(45)
pen.penup()
pen.goto(60, -100)
pen.pendown()
pen.left(45)
pen.forward(80)
pen.back(80)
pen.right(90)
pen.forward(80)
pen.back(80)
pen.left(45)
# 完成画图
pen.hideturtle()
turtle.done()
```
运行代码后,将会看到一个懒羊羊的图形。你也可以根据需要进行自定义修改,比如调整颜色、大小等。
阅读全文