python - 如何在 python 中绘制圆弧(圆的一部分)

标签 python turtle-graphics

我想要360张PNG位图,每张位图都是一个弧,代表一个进度中的一个步骤。以下位图显示了第 60 步(距顶部 60 度)和第 120 步。

Step 60 Step 120

如何在代码中绘制这些位图?

编辑:我现在可以画了,但不知道如何将起点设置在顶部而不是底部

import turtle
wn = turtle.Screen
turtle.hideturtle()
turtle.hideturtle()
turtle.ht()
turtle.speed(0)

turtle.pensize(11)
turtle.color("grey")
turtle.circle(200)

turtle.color("red")
turtle.circle(200, 60, 3600)

cv = turtle.getcanvas()
cv.postscript(file="circle.ps", colormode='color')

turtle.done()

最佳答案

绘制圆弧的一些简单代码:

import matplotlib.pyplot as plt
from matplotlib.patches import Arc
plt.figure(figsize=(6, 6)) # set image size
plt.subplots_adjust(0, 0, 1, 1) # set white border size
ax = plt.subplot()
for i in range(1, 361):
    plt.cla() # clear what's drawn last time
    ax.invert_xaxis() # invert direction of x-axis since arc can only be drawn anti-clockwise
    ax.add_patch(Arc((.5, .5), .5, .5, -270, theta2=i, linewidth=5, color='red')) # draw arc
    plt.axis('off') # hide number axis
    plt.savefig(str(i)+'.png', facecolor='black') # save what's currently drawn

您可能需要添加更多代码才能获得图片效果。附上结果的样子:

enter image description here

关于python - 如何在 python 中绘制圆弧(圆的一部分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52961116/

相关文章:

python - Google Appengine 一对多并按 collection_name 查询

python - Discord.py 如何获取最后一条消息并在没有任何前缀/命令的情况下回复它

Python Turtle 比较颜色

python - 在python turtle 绘图中隐藏 turtle

python - 类型错误 : __init__() takes from 1 to 3 positional arguments but 4 were given

python - 如何使用 Tika 将 PDF 拆分为段落

python - 优化前景对象的边缘

Python时间延迟

python - 如何让 turtle 图形在绘制时不显示 turtle ?

python turtle : Draw concentric circles using circle() method