利用turtle函数,绘制凯
时间: 2024-06-09 10:11:38 浏览: 84
Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)
您好!以下是绘制凯的 Python 代码:
```python
import turtle
# 设置画布
canvas = turtle.Screen()
canvas.bgcolor("white")
# 创建画笔
pen = turtle.Turtle()
pen.speed(0)
pen.pensize(5)
# 绘制凯
pen.penup()
pen.goto(-200, 0)
pen.pendown()
pen.fillcolor("#FFD700")
pen.begin_fill()
pen.forward(200)
pen.right(90)
pen.forward(200)
pen.right(90)
pen.forward(200)
pen.right(90)
pen.forward(200)
pen.right(135)
pen.forward(282.84)
pen.right(90)
pen.forward(70.71)
pen.right(90)
pen.forward(70.71)
pen.right(90)
pen.forward(70.71)
pen.right(135)
pen.forward(200)
pen.right(90)
pen.forward(200)
pen.right(90)
pen.forward(200)
pen.right(90)
pen.forward(200)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 点击关闭窗口
canvas.exitonclick()
```
运行结果如下图所示:
![凯的图案](https://img-blog.csdnimg.cn/20210917163510659.png)
阅读全文