如何在椭圆路径上放置等间距的圆?

2024-10-05 10:06:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个小(大)任务要处理,我想知道是否有人能帮我解决这个问题。我找过几次答案,但都没有成功

http://s24.postimg.org/89r1zmgl1/Untitled.png)<;---椭圆

我想让一个任意数量的圆出现在椭圆上,你可以看到上面的链接。椭圆和圆都是用Tkinter定义的。在

class NetworkFrame:
    def __init__(self, master, number_of_people):

       DisplayFrame = Canvas(master, bg="white", width=720, height=300)
       DisplayFrame.grid(row=0, columnspan=7, column=0, sticky='W', padx=5, pady=5)
       DisplayFrame.create_oval(20, 20, 700, 280, width=1)

所以我的想法是-用户输入一个特定的数字(人的数量),它使一定数量的圆圈出现在由椭圆定义的路径上,均匀分布,对称放置。在

理想情况下,这就是我想要的,这样我就可以把它调整成我之前定义的任何形状,但是如果有其他方法可以使它们看起来像是沿着椭圆路径运动,这也是可以接受的。在

感谢您抽出时间!在


Tags: 答案orglt路径masterhttp数量定义
1条回答
网友
1楼 · 发布于 2024-10-05 10:06:14

如果有人需要这个,我已经设法做到这多亏了凯文发布的链接!在

下面是它的工作原理

def __init__(self, master, number_of_people, node_size):
    a = 350
    b = 140
    ellipsePoints = [(a * cos(theta), b * sin(theta))
                     for theta in (pi*2 * i/number_of_people for i in range(number_of_people))]
    DisplayFrame = Canvas(root, bg="white", width=725, height=320)
    DisplayFrame.grid(row=0, columnspan=7, column=0, sticky='W', padx=5, pady=5)
    for i in range(number_of_people):
            DisplayFrame.create_oval(ellipsePoints[i][0]+355, ellipsePoints[i][1]+155,
                                     ellipsePoints[i][0]+355+node_size, ellipsePoints[i][1]+155+node_size, fill="red")

相关问题 更多 >

    热门问题