Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_schedule_interval(self):
self.clear()
clock.set_default(clock.Clock())
clock.schedule_interval(self.callback_1, 0.1)
clock.schedule_interval(self.callback_2, 0.35)
clock.schedule_interval(self.callback_3, 0.07)
t = 0
while t < 2.04: # number chosen to avoid +/- 1 errors in div
t += clock.tick()
self.assertTrue(self.callback_1_count == int(t / 0.1))
self.assertTrue(self.callback_2_count == int(t / 0.35))
self.assertTrue(self.callback_3_count == int(t / 0.07))
y = -image.height
sprite = Sprite(image, x=x, y=y, batch=image_batch)
images.append(sprite)
window_size = window.get_size()
if __name__ == '__main__':
init()
display = TableclothDisplay(window, '../images/seamless-montage.png', '.')
pyglet.clock.set_fps_limit(120)
pyglet.clock.schedule(scroll)
pyglet.clock.schedule_interval(new_photo, NEW_PHOTO_INTERVAL)
pyglet.clock.schedule_interval(check_queue, 1)
new_photo()
pyglet.app.run()
window.push_handlers(on_text)
def on_key_press(symbol, modifiers):
if symbol == key.BACKSPACE:
interp.backspace()
else:
return True
window.push_handlers(on_key_press)
def blink_cursor(dt):
cursor = layout.document.get_element('cursor')
if cursor.style['background-color']:
del cursor.style['background-color']
else:
cursor.style['background-color'] = 'black'
clock.schedule_interval(blink_cursor, 0.5)
glClearColor(1, 1, 1, 1)
window.set_visible()
while not window.has_exit:
window.dispatch_events()
clock.tick()
glClear(GL_COLOR_BUFFER_BIT)
layout.draw()
window.flip()
dx=random.randint(-10, 10), dy=random.randint(-10, 10))
def update(dt):
for s in batch: s.update()
pyglet.clock.schedule(update)
numframes = 0
sum_numframes = 0
best_fps = 0
def update_stats(dt):
global numframes, sum_numframes, best_fps
fps = numframes / dt
best_fps = max(best_fps, fps)
sum_numframes += numframes
numframes = 0
pyglet.clock.schedule_interval(update_stats, 0.5)
@w.event
def on_draw():
global numframes
numframes += 1
w.clear()
batch.draw()
t = time.time()
pyglet.app.run()
print 'best FPS:', best_fps
print 'best us per sprite:', (1. / best_fps) * 1000000 / numsprites
print 'avg us per sprite:', float(time.time()-t) / (numsprites * sum_numframes) * 1000000
glTranslatef(0, 0, -5)
glRotatef(r, 0, 0, 1)
glRectf(-1, -1, 1, 1)
r = 0
def update(dt):
global r
r += 1
if r > 360:
r = 0
pyglet.clock.schedule_interval(update, 1 / 20.)
w1 = pyglet.window.Window(200, 200, caption='First window', resizable=True)
w1.on_resize = on_resize
w1.on_draw = on_draw
w1.switch_to()
setup()
w2 = pyglet.window.Window(300, 300, caption='Second window', resizable=True)
w2.on_resize = on_resize
w2.on_draw = on_draw
w2.switch_to()
setup()
# On some platforms the actual framebuffer size is bigger than the window.
pixel_ratio = w1.get_pixel_ratio()
window = PlayerWindow(player)
source = pyglet.media.load(filename)
player.queue(source)
have_video = have_video or bool(source.video_format)
window.gui_update_source()
window.set_default_video_size()
window.set_visible(True)
player.play()
window.gui_update_state()
if not have_video:
pyglet.clock.schedule_interval(lambda dt: None, 0.2)
pyglet.app.run()
def _set_visible(self, visible):
self._visible = visible
clock.unschedule(self._blink)
if visible and self._active and self.PERIOD:
clock.schedule_interval(self._blink, self.PERIOD)
self._blink_visible = False # flipped immediately by next blink
self._blink(0)
self.color_scheme = color_scheme
self.show_images = show_images
self.levelset_supersampling = levelset_supersampling
self.show_grid = show_grid
self.quit_pressed = False
self.output_directory = os.path.join(get_output_directory(), self.task_id)
self.cpu_time = 0
self.show_stat = show_stat
os.mkdir(self.output_directory)
self.substep = substep
self.video_output = video_output
self.video_manager = VideoManager(
self.output_directory, automatic_build=self.video_output)
self.need_press = need_press
self.pressed = False
pyglet.clock.schedule_interval(self.update, 1 / 120.0)
pyglet.app.run()
ent.angle+=rates[i]
polygon_domain1.update()
render_domain.draw()
fps_display.draw()
def delete(trash):
print "delete"
global ents, rates
ent = ents.pop(5)
rates.pop(5)
del ent
pyglet.clock.schedule(lambda _: None)
pyglet.clock.schedule_interval(delete, 1)
pyglet.app.run()
def __init__(self, gw, window):
self.gw = gw
self.window = window
self.img = pyglet.resource.image("data/credits.png")
self.window.set_handler('on_draw', self.on_draw)
self.window.set_handler('on_mouse_press', self.on_mouse_press)
pyglet.clock.schedule_interval(self.update, 1/game_fps)