使用turtle库绘制八角星形(八角形每个角为45度)
时间: 2023-08-03 16:05:44 浏览: 163
下面是使用turtle库绘制八角星形的代码:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔的颜色和粗细
pen.color("red")
pen.pensize(2)
# 绘制八角星形
for i in range(8):
pen.forward(100)
pen.right(135)
# 关闭画布
canvas.exitonclick()
```
运行以上代码,即可在画布上绘制出八角星形,如下图所示:
![八角星形](https://cdn.jsdelivr.net/gh/YuxingXie/image-repo//python-turtle-octagon-star.png)
阅读全文