def test_anim_heaviside(clock): animation = anim(1, 3, 0, clock, delay=1) assert animation == 1 clock.advance_sync(1) assert animation == 3 clock.advance_sync(1) assert animation == 3
def test_anim_strength(clock, n): animation = anim(1, 3, 2, clock, strength=n) assert animation == 1 clock.advance_sync(1) assert animation == 1 + n clock.advance_sync(1) assert animation == 1 + n * 2
def test_anim_basic_vector(clock): animation = anim((1, 2), (3, 4), 2, clock) assert all(animation == (1, 2)) clock.advance_sync(1) assert all(animation == (2, 3)) clock.advance_sync(1) assert all(animation == (3, 4))
def test_anim_negative_duration(clock): animation = anim(1, 3, -2, clock, delay=2) assert animation == 3 clock.advance_sync(1) assert animation == 2 clock.advance_sync(1) assert animation == 1 clock.advance_sync(1) assert animation == 1
def test_easing_name(clock): animation = anim(1, 3, 2, clock, easing='quad') assert animation == 1 clock.advance_sync(1) assert animation == 1.5 clock.advance_sync(1) assert animation == 3 clock.advance_sync(1) assert animation == 3
def test_anim_basic(clock): animation = anim(1, 3, 2, clock) assert animation == 1 clock.advance_sync(1) assert animation == 2 clock.advance_sync(1) assert animation == 3 clock.advance_sync(1) assert animation == 3
def test_anim_infinite(clock): animation = anim(1, 3, 2, clock, infinite=True) assert animation == 1 clock.advance_sync(1) assert animation == 2 clock.advance_sync(1) assert animation == 3 clock.advance_sync(1) assert animation == 4 clock.advance_sync(1) assert animation == 5
def test_anim_delay(clock): animation = anim(1, 3, 2, clock, delay=1) assert animation == 1 clock.advance_sync(1) assert animation == 1 clock.advance_sync(1) assert animation == 2 clock.advance_sync(1) assert animation == 3 clock.advance_sync(1) assert animation == 3
def test_done(clock): lst = [] animation = anim(1, 3, 2, clock) animation.done.add_done_callback(lambda fut: lst.append('done')) assert lst == [] clock.advance_sync(1) assert lst == [] clock.advance_sync(1) assert lst == ['done'] clock.advance_sync(1) assert lst == ['done'] clock.advance_sync(1) assert lst == ['done']
def test_easing_func_infinite(clock): animation = anim(1, 3, 2, clock, easing=math.sin, infinite=True) assert abs(float(animation) - 1) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - (1 + 2 / math.sqrt(2))) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - 3) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - (1 + 2 / math.sqrt(2))) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - 1) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - (1 - 2 / math.sqrt(2))) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - -1) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - (1 - 2 / math.sqrt(2))) < ε clock.advance_sync(τ / 4) assert abs(float(animation) - 1) < ε
def anim(self, target, duration=0, clock=None, *, delay=0, easing=None, infinite=False, strength=1): """Animate this property Causes this property's value to gradually become *target* in *duration* time units. for convenience, if *clock* is not given, the ``clock`` attribute from the object this property is on is used as the clock. A :exc:`TypeError` is raised if that attribute doesn't exist. See the :ref:`Animation <property-anim>` section of the documentation for a discussion. For detailed description of the arguments, see :func:`gillcup.animations.anim`. Returns a :class:`~asyncio.Future`-like object that is done when the animation is finished. """ instance = self._instance if clock is None: try: clock = instance.clock except AttributeError: raise TypeError('{} does not have a clock. ' 'Pass a clock to anim() explicitly.'.format( instance)) animation = anim( start=self.replacement, end=target, duration=duration, clock=clock, delay=delay, easing=easing, infinite=infinite, strength=strength, ) self._parent_property.__set__(instance, animation) return animation.done
def test_anim_negative_duration_past(clock): animation = anim(1, 3, -2, clock) assert animation == 1 clock.advance_sync(1) assert animation == 1
def test_anim_heaviside_infinite(clock): with pytest.raises(ValueError): anim(1, 3, 0, clock, infinite=True)