Example #1
0
    def test_limit_fps(self):
        """
        Test that the clock effectively limits the
        frames per second to 60 Hz when set to.

        Because the fps are bounded, we expect a small error (1%)
        from the expected value.
        """
        ticks = 20
        fps_limit = 60
        expected_delta_time = ticks*1./fps_limit

        clock.set_fps_limit(fps_limit)

        pyclock = clock.get_default()
        t1 = pyclock.time()
        # Initializes the timer state.
        clock.tick()
        for i in range(ticks):
            clock.tick()

        t2 = pyclock.time()

        computed_time_delta = t2 - t1

        self.assertAlmostEqual(computed_time_delta,
                               expected_delta_time,
                               delta=0.01*expected_delta_time)
Example #2
0
 def __init__(self, window_config=None, fullscreen=False):
     super().__init__(
         width=window_config['width'],
         height=window_config['height'],
         vsync=False,
         fullscreen=fullscreen,
         screen=window.get_platform().get_default_display().get_screens()
         [2])
     self.__config = window_config
     self.clock = clock.get_default()
     self.fps_display = pyglet.window.FPSDisplay(self)
     self.fps_display.label = pyglet.text.Label(font_size=18,
                                                x=14,
                                                y=35,
                                                anchor_x='left',
                                                anchor_y='bottom')
     self._set_fps(window_config['fps'])
     self.fps_display.update()
     self.reset_keys()
     self.mouse_pressed = False
     self.mouse = (0, 0)
     self.label = None
     self.particle_batch = None
Example #3
0
 def __init__(self):
     self._has_exit_condition = threading.Condition()
     self.clock = clock.get_default()
     self.is_running = False
Example #4
0
 def __init__(self):
     self._has_exit_condition = threading.Condition()
     self.clock = clock.get_default()
     self.is_running = False
Example #5
0
def sleep(seconds):
    """Busy sleep on the CPU which is very precise"""
    pyclock = clock.get_default()
    start = pyclock.time()
    while pyclock.time() - start < seconds:
        pass
Example #6
0
        cover.fX.set(x)
        covers.append(cover)
        tracks.append(x)
    covers[0].focus()

    advance = covergl.mk_advance(tracks, covers)

    @w.event
    def on_key_press(symbol, modifiers):
        if symbol == window.key.LEFT: advance(True)
        elif symbol == window.key.RIGHT: advance(False)

    @w.event
    def on_mouse_motion(x, y, dx, dy, tmp_dx=[0]):
        tmp_dx[0] += dx
        if tmp_dx[0] > 20:
            tmp_dx[0] = 0
            advance(False)
        elif tmp_dx[0] < -20:
            tmp_dx[0] = 0
            advance(True)

    clock = clock.get_default()
    clock.set_fps_limit(40)
    clock.schedule(anim.add_time)
    while not w.has_exit:
        dt = clock.tick()
        w.dispatch_events()
        covergl.display(w.width, w.height, covers)
        w.flip()
Example #7
0
 def __init__(self):
     self._has_exit_condition = threading.Condition()
     self.clock = clock.get_default()
     self.is_running = False
     self._redraw_window_func = self._redraw_window