[Python] How do i connect all the dots on my circle so that it makes a pattern?

Discussão em 'Python' iniciado por Stack, Julho 9, 2025.

  1. Stack

    Stack Membro Participativo

    So I was trying to make a circle with a certain amount of dots on it with all the dots connected with each other. So if there are 10 dots, dot 1 would be connected with all the other ones and so is dot 2. Eventually it makes a pretty pattern. I already have a code for putting the dots on the circle, and I already succeeded in making the bottom dot connect with the rest, but I cannot think of a way to make the rest of the dots connect as well. This is my code:

    import turtle

    tur = turtle.Turtle()
    bob = turtle.Turtle()
    screen = turtle.Screen()

    screen.setup(800,800)

    stippen = int(screen.numinput("How many?" , "How many dots do you want to draw? " , minval = 1 , maxval = 25)) #the user can input a number of dots between 1 and 25

    formula = 360/stippen #this makes sure the dots are at an equal distance from the other ones

    r = 300 #radius of my circle

    def roos():
    tur.ht()
    bob.ht()
    bob.speed(0)
    tur.speed(0)
    bob.up()
    tur.up()
    tur.goto(0,-300) #this is always the bottom dot
    bob.goto(0,-300)

    for i in range(stippen): #this draws the circle with the dots
    tur.down()
    bob.down()
    tur.circle(r,formula,150) #it draws a piece of the circle
    tur.dot() #then draws a dot and this is done until the circle is full
    bob.goto(tur.pos()) #bob goes to the dot tur is at and draws a line
    bob.up()
    bob.goto(0,-300) #then bob goes back down to go to the other dots tur draws
    tur.up()

    roos()

    turtle.done()


    So I made the bottom dot connect with the rest of the dots, but how do I make it so that the rest is connected as well? I tried getting the coordinates of all the dots drawn, but I couldn't figure it out and I also thought there would be an easier way to do this.

    Continue reading...

Compartilhe esta Página