Python turtle.ontimer() Examples
The following are 13
code examples of turtle.ontimer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
turtle
, or try the search function
.
Example #1
Source File: spiro.py From Python-Project with Apache License 2.0 | 6 votes |
def __init__(self,N): # timer value in milliseconds self.deltaT=10 # get window dimensions self.width = turtle.window_width() self.height=turtle.window_height() # creat the Spiro objects self.spiros=[] for i in range(N): # generate random params rparams=self.genRandomParams() # set spiro params spiro=Spiro(*rparams) self.spiros.append(spiro) # call timer turtle.ontimer(self.update,self.deltaT) # restart spiro drawing
Example #2
Source File: spiro.py From Python-Project with Apache License 2.0 | 6 votes |
def update(self): # update all spiros nComplete=0 for spiro in self.spiros: # update spiro.update() # count completed ones if spiro.drawingComplete: nComplete+=1 # if all spiros are complete,restart if nComplete==len(self.spiros): self.restart() # call timer turtle.ontimer(self.update,self.deltaT) # toggle turtle on/off
Example #3
Source File: clock.py From Tools with MIT License | 5 votes |
def startTick(second_hand, minute_hand, hour_hand, printer): today = datetime.datetime.today() second = today.second + today.microsecond * 1e-6 minute = today.minute + second / 60. hour = (today.hour + minute / 60) % 12 # 设置朝向 second_hand.setheading(6 * second) minute_hand.setheading(6 * minute) hour_hand.setheading(12 * hour) turtle.tracer(False) printer.forward(65) printer.write(getWeekday(today), align='center', font=("Courier", 14, "bold")) printer.forward(120) printer.write('12', align='center', font=("Courier", 14, "bold")) printer.back(250) printer.write(getDate(today), align='center', font=("Courier", 14, "bold")) printer.back(145) printer.write('6', align='center', font=("Courier", 14, "bold")) printer.home() printer.right(92.5) printer.forward(200) printer.write('3', align='center', font=("Courier", 14, "bold")) printer.left(2.5) printer.back(400) printer.write('9', align='center', font=("Courier", 14, "bold")) printer.home() turtle.tracer(True) # 100ms调用一次 turtle.ontimer(lambda: startTick(second_hand, minute_hand, hour_hand, printer), 100)
Example #4
Source File: spgl.py From SPGL with GNU General Public License v3.0 | 5 votes |
def play_sound(self, sound_file, time = 0): # Windows if platform.system() == 'Windows': winsound.PlaySound(sound_file, winsound.SND_ASYNC) # Linux elif platform.system() == "Linux": os.system("aplay -q {}&".format(sound_file)) # Mac else: os.system("afplay {}&".format(sound_file)) if time > 0: turtle.ontimer(lambda: self.play_sound(sound_file, time), t=int(time * 1000))
Example #5
Source File: spgl.py From SPGL with GNU General Public License v3.0 | 5 votes |
def after(self, function, milliseconds): turtle.ontimer(function, milliseconds)
Example #6
Source File: spgl.py From SPGL with GNU General Public License v3.0 | 5 votes |
def play_sound(self, sound_file, time = 0): # Windows if platform.system() == 'Windows': winsound.PlaySound(sound_file, winsound.SND_ASYNC) # Linux elif platform.system() == "Linux": os.system("aplay -q {}&".format(sound_file)) # Mac else: os.system("afplay {}&".format(sound_file)) if time > 0: turtle.ontimer(lambda: self.play_sound(sound_file, time), t=int(time * 1000))
Example #7
Source File: ontimer-star.py From Learning-Python-by-building-games with MIT License | 5 votes |
def main(): if not exit: star.forward(50) star.right(144) turtle.ontimer(main,500)
Example #8
Source File: spgl.py From Projects with GNU General Public License v3.0 | 5 votes |
def play_sound(self, sound_file, time = 0): # Windows if platform.system() == 'Windows': winsound.PlaySound(sound_file, winsound.SND_ASYNC) # Linux elif platform.system() == "Linux": os.system("aplay -q {}&".format(sound_file)) # Mac else: os.system("afplay {}&".format(sound_file)) if time > 0: turtle.ontimer(lambda: self.play_sound(sound_file, time), t=int(time * 1000))
Example #9
Source File: space_arena.py From Projects with GNU General Public License v3.0 | 5 votes |
def play_sound(sound_file, time = 0): # Windows if platform.system() == 'Windows': winsound.PlaySound(sound_file, winsound.SND_ASYNC) # Linux elif platform.system() == "Linux": os.system("aplay -q {}&".format(sound_file)) # Mac else: os.system("afplay {}&".format(sound_file)) if time > 0: turtle.ontimer(lambda: play_sound(sound_file, time), t=int(time * 1000))
Example #10
Source File: space_arena.py From Projects with GNU General Public License v3.0 | 5 votes |
def timer(game=game): os.system("clear") print("FPS: {}".format(game.frame)) game.frame = 0 turtle.ontimer(timer, 1000)
Example #11
Source File: example-1.py From python-examples with MIT License | 5 votes |
def move(): if running: t.forward(15) angle = random.randint(-9, 9) * 10 t.left(angle) t.ontimer(move, 25) # 25ms
Example #12
Source File: main-2.py From python-examples with MIT License | 5 votes |
def move_t1(): # first turtle moves a little t1.left(10) t1.forward(10) # repeat it after 100ms turtle.ontimer(move_t1, 100)
Example #13
Source File: main-2.py From python-examples with MIT License | 5 votes |
def move_t2(): # second turtle moves a little t2.right(10) t2.forward(10) # repeat it after 100ms turtle.ontimer(move_t2, 100) # --- main --- # create two turtles