python画半圆环
时间: 2024-01-17 08:19:32 浏览: 158
以下是两种Python画半圆环的例子:
1. 使用PIL库绘制半圆环:
```python
from PIL import Image, ImageDraw
# 创建一个空白图像
image = Image.new("RGB", (500, 500), "white")
draw = ImageDraw.Draw(image)
# 绘制半圆环
draw.arc((100, 100, 400, 400), 0, 180, fill="blue", width=10)
# 保存图像
image.save("half_circle.jpg")
```
2. 使用Turtle库绘制半圆环:
```python
from turtle import *
from random import *
from math import *
# 初始化
screensize(500, 500)
speed(0)
penup()
# 绘制半圆环
def draw_circle(color, radius):
pendown()
fillcolor(color)
begin_fill()
circle(radius, 180)
left(90)
forward(radius * 2)
left(90)
circle(radius, 180)
end_fill()
penup()
# 绘制多个半圆环
def draw_peacock():
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
radius = 100
for i in range(6):
draw_circle(colors[i], radius)
radius += 20
# 调用函数绘制半圆环
draw_peacock()
```
阅读全文