Esempio n. 1
0
    def _add_float_kwarg(self, arg_name: str, kwargs: dict, t: float):

        value = getattr(self, arg_name)
        if value is not None:
            kwargs[arg_name] = (
                value.at(t) if isinstance(value, FloatAnimation) else
                Rate(value)(t) if isinstance(value, str) else value)
Esempio n. 2
0
    def __init__(self,
                 colors: List[Color],
                 t: Optional[List[float]] = None,
                 rate: Optional[Union[Rate, str]] = None):

        self.colors: List[Color] = colors
        if t is not None:
            self.t: List[float] = t
        else:
            self.t = list(linspace(0, 1, len(colors)))
        self.rate: Rate = (Rate.linear() if rate is None else
                           rate if isinstance(rate, Rate) else Rate(rate))
Esempio n. 3
0
    def rotation(cls, cycles: float,
                 clockwise: bool = True,
                 phase: Optional[float] = 0.0):
        """
        Return a rotation in degrees.

        :param cycles: Number of complete rotations.
        :param clockwise: Rotate clockwise if True.
        :param phase: Starting phase between 0.0 and 1.0.
        """
        if clockwise:
            multiplier = -1
        else:
            multiplier = 1
        return FloatAnimation(rate=Rate(
            lambda t: (phase * 360) + multiplier * t * cycles * 360
        ))
Esempio n. 4
0
    def __init__(self,
                 values: Optional[List[float]] = None,
                 t: Optional[List[float]] = None,
                 rate: Optional[Union[Rate, str]] = None):

        if values is not None:
            self.values: List[float] = values
        else:
            self.values = [0, 1]
        if t is not None:
            self.t: List[float] = t
        else:
            self.t = [0, 1]
        self.rate: Rate = (
            Rate.linear() if rate is None else
            rate if isinstance(rate, Rate) else
            Rate(rate)
        )
Esempio n. 5
0
    def sine_wave(cls, min_val: float, max_val: float,
                  cycles: float, phase: float = 0.0) -> 'FloatAnimation':
        """
        Return a sine wave oscillating between min_val and max_val,
        starting at phase * 2π with cycles complete waves.

        :param min_val: Lowest value of the wave.
        :param max_val: Highest value of the wave.
        :param cycles: Number of complete oscillations.
        :param phase: Value from 0 to 1 of where to start the wave.
        """
        middle_val = (min_val + max_val) / 2
        amplitude = (max_val - min_val) / 2
        rate = Rate(lambda t: (
                middle_val +
                amplitude * sin((2 * pi * t * cycles) - (2 * pi * phase))
        ))
        return FloatAnimation(rate=rate)
Esempio n. 6
0
    def triangle_wave(cls,
                      color_1: Color,
                      color_2: Color,
                      cycles: float,
                      phase: float = 0.0) -> 'FloatAnimation':
        """
        Return a triangle wave oscillating between min_val and max_val,
        starting at phase * 2π with cycles complete waves.

        :param color_1: Lowest color of the wave.
        :param color_2: Highest color of the wave.
        :param cycles: Number of complete oscillations.
        :param phase: Value from 0 to 1 of where to start the wave.
        """
        middle_val = 0.5
        amplitude = 0.5
        rate = Rate(lambda t: (middle_val + 2 * amplitude * arcsin(
            sin((2 * pi * t * cycles) - (2 * pi * phase))) / pi))
        return ColorAnimation(colors=[color_1, color_2], rate=rate)