Search code examples
pythonbioinformaticsturtle-graphicspython-turtle

Infinite loop (?) and overlapped drawings in turtle python


I need help with my program, here is the link: https://onlinegdb.com/L0dCYLf6X . I'm trying to make a drawing for every main-key in the nested dictionary. To be precise, main-keys are proteins and I'm trying to draw them with their domains. The problem is that all of the drawings are made in one window and are overlapped. The second problem is that when I run the program it doesn't stop - turtle is all the time drawing - so I guess it might be an infinite loop?

I don't know how to fix it so I would be very grateful if someone could help me.


Solution

  • sorry for deleting the comments, I thought this might be an actual answer.

    First for the overlapping :

    you are using in your loop the same values for your x_point_to_start and y_point_to_start.

    What does this mean? Everytime you draw something you're starting from the same position so things are overlapping. you probably wanna calculate how much width and height is taken by a drawing and add this to your variables so next drawing is next to it.

    For the "infinite loop" :

    It is not infinite, just very very slow.

    First thing the outer-most loop is looping through data, let's say it has a length of N. The next loop inside of it is looping through data, again! O(N^2) so far. then you have a for loop with calue of segments iterations let's call segment =k) we have O(k*N^2). now sequential to this is another loop looping through data[key] which has a loop looping through data[key] so that's M^2 followed by a few more loops...

    Conclusion: Your for loops need more work. try to do as much work as you can in a loop to not repeat it, looping a square amount of time in your use case is not normal, I believe you may want to recheck your indentations (the instructions in your loops).