-1

I have a small (big actually) assignment to take care of, and I would like to know if anyone can help me out with this. I've searched for answers a few times but with no success

(http://s24.postimg.org/89r1zmgl1/Untitled.png)<--- The ellipse

I would like to make an arbitrary number of circles appear on the ellipse that you can see on the link above. Both the ellipse and the circles are defined with 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)

So my idea is - The user enters a certain number (number_of_people), and it makes that certain number of circles appear on the path defined by the ellipse, evenly spaced and symmetrically placed.

Ideally, that's what I want to happen so I can adapt it to any shape I have defined earlier, but if there is another way to make them appear to follow an elliptical path, it's also acceptable.

Thank you for your time!

user1118321
  • 25,567
  • 4
  • 55
  • 86
Iocust
  • 105
  • 1
  • 14
  • This may be helpful to you: [How can I generate as set of uniform points around an ellipse?](http://stackoverflow.com/q/6972331/953482). Generate the points, then use each point as the center of a circle. The diameter of each circle would be the smallest straight-line distance between any two neighboring points. – Kevin Feb 18 '15 at 13:41
  • Thank you for your answer! I am a bit confused as Tkinter requires circles to be defined as "enclosed in a rectangle" so I have to define a rectangle around every point. Anyway, thanks. – Iocust Feb 18 '15 at 14:21

1 Answers1

1

In case anyone needs this, I have managed to do this thanks to the link Kevin posted!

Here is how it works

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")
Iocust
  • 105
  • 1
  • 14