hiltali.blogg.se

Rhinoceros drawing python 2 turtle graphic
Rhinoceros drawing python 2 turtle graphic










Mercury_thread = threading.Thread(target=lambda: mercury.circle(58)) # Now create a thread for each planet and start them """simulates motion of Mercury, Venus, Earth, and Mars""" But then you can do this: import threading The module have any installer you'll have to copy it into the same directory as planets.py. It doesn't work with Python 3, but I've ported it, and you can get it as mttkinter on GitHub. Taylor's clever mtTkinter library wraps all of the magic up for you. I'd definitely not recommend using threads here, but it's worth seeing how it would work.Īllen B. tkinter is thread-safe, it just doesn't have any kind of dispatching mechanism to post events on the main loop from a background thread, so you have to add a queue or some other way to do it. In my other answer, I said that you have to do some kind of cooperative scheduling, because tkinter isn't thread-safe. Of course this means Mercury will end up orbiting the sun 7.5 times, while Mars will only orbit once… but that's exactly what you want, right? So I think what you really want to do here is leave all the speeds at 0 (no animation delay), but move the faster planets by a larger extent each step: mercury.speed(0) It doesn't affect how quickly they orbit around the sun, it just affects how long each step takes to draw. That causes each move to animate more slowly. Of course the smaller you make that extent value, the more "steps" each turtle is taking, so the slower they will take to orbit.Īlso, I'm not sure you really want to use speed the way you're using it.

rhinoceros drawing python 2 turtle graphic

So, you can do this: for i in range(360): So, how do you do that? The circle method has an optional extent parameter, which is an angle (in degrees) to draw. (Well, you might want the first, but you can't have it tkinter, and therefore turtle, can only run on the main thread.) Draw, say, the first 1° of each circle, then the next 1° of each circle, and so on. In this case, it's the second one that you want. Cooperative scheduling: you do a small piece of work for one thing, then a small piece for the next, and so on, then come back to the first one.

Rhinoceros drawing python 2 turtle graphic how to#

  • Preemptive multithreading, where you just create a thread for each thing and they all try to work at full speed and the computer figures out how to interleave that work.
  • rhinoceros drawing python 2 turtle graphic

    In general, if you want to do multiple things at the same time, there are two options:










    Rhinoceros drawing python 2 turtle graphic