用Python 半径从键盘读取,可调 五角星是内接的,用三角函数计算 。使用循环把底层的四个同心圆画出来,要求边框和填充颜色一致: 内接五角星在最上层: 海龟画图法完成。
时间: 2023-12-10 17:38:31 浏览: 93
好的,我可以为您提供代码实现。代码如下:
```python
import turtle
import math
# 读取半径
r = float(input("请输入半径:"))
# 初始化海龟画布
t = turtle.Turtle()
t.speed(0)
# 循环绘制同心圆
colors = ["red", "orange", "yellow", "green"]
for i in range(4):
t.penup()
t.goto(0, -r*i*0.4)
t.pendown()
t.pencolor(colors[i])
t.fillcolor(colors[i])
t.begin_fill()
t.circle(r*i*0.4)
t.end_fill()
# 计算五角星的顶点坐标
x1, y1 = 0, r
x2, y2 = math.sin(math.radians(18))*r, math.cos(math.radians(18))*r
x3, y3 = math.sin(math.radians(54))*r, -math.cos(math.radians(54))*r
x4, y4 = -x3, y3
x5, y5 = -x2, y2
# 绘制五角星
t.penup()
t.goto(x1, y1)
t.pencolor("blue")
t.fillcolor("blue")
t.pendown()
t.begin_fill()
t.goto(x3, y3)
t.goto(x5, y5)
t.goto(x2, y2)
t.goto(x4, y4)
t.goto(x1, y1)
t.end_fill()
turtle.done()
```
运行代码,就可以看到绘制出的五角星和同心圆了。您可以根据需要修改代码中的参数,调整绘制出的图形大小和颜色。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)