python画五角星外接正五边形
时间: 2023-11-13 15:57:34 浏览: 103
star.rar_五角星
好的,以下是Python代码实现五角星外接正五边形的过程:
```python
import turtle
# 设置画笔
pen = turtle.Turtle()
pen.speed(10)
pen.color('red')
# 画五角星
def draw_star(size):
for i in range(5):
pen.forward(size)
pen.right(144)
pen.forward(size)
pen.left(72)
# 画正五边形
def draw_pentagon(size):
for i in range(5):
pen.forward(size)
pen.right(72)
# 计算正五边形的边长
def calc_size(radius):
return radius * 2 * (3 ** 0.5) / 5
# 设置起始位置
pen.penup()
pen.goto(-100, 0)
pen.pendown()
# 画五角星外接正五边形
radius = 100
size = calc_size(radius)
draw_star(size)
draw_pentagon(size)
turtle.done()
```
阅读全文