How to use the slider.curve.Curve function in slider

To help you get started, we’ve selected a few slider examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github llllllllll / slider / slider / curve.py View on Github external
Parameters
    ----------
    points : list[Position]
        The positions of the control points.
    req_length : float
        The pixel length of the curve.
    """
    def __init__(self, points, req_length):
        super().__init__(points, req_length)

        self._curves = [
            Bezier(subpoints, None) for subpoints in sliding_window(2, points)
        ]


class Perfect(Curve):
    """Perfect curves traverse the circumference of the circle that passes
    through the given points.

    Parameters
    ----------
    points : list[Position]
        The positions of the control points.
    req_length : float
        The pixel length of the curve.
    """
    def __init__(self, points, req_length, *, _center=None):
        # NOTE: _center exists as an optimization to not recompute the center
        # of the circle when calling ``Curve.from_kind_and_points``.
        self.points = points
        self.req_length = req_length
github llllllllll / slider / slider / curve.py View on Github external
position : Position
            The position of the curve.
        """
        raise NotImplementedError('__call__')

    @lazyval
    def hard_rock(self):
        """This curve when played with hard rock.
        """
        return type(self)(
            [Position(p.x, 384 - p.y) for p in self.points],
            self.req_length,
        )


class Bezier(Curve):
    """Bezier curves of degree ``len(points)``.

    Parameters
    ----------
    points : list[Position]
        The positions of the control points.
    req_length : float
        The pixel length of the curve.
    """
    def __init__(self, points, req_length):
        super().__init__(points, req_length)
        self._coordinates = np.array(points).T

    def __call__(self, t):
        coordinates = self.at(t * (self.req_length / self.length))
        return Position(coordinates[0, 0], coordinates[0, 1])
github llllllllll / slider / slider / beatmap.py View on Github external
ticks = int(
            (
                (np.ceil((num_beats - 0.1) / repeat * slider_tick_rate) - 1)
            ) *
            repeat +
            repeat +
            1
        )

        return cls(
            position,
            time,
            time + duration,
            hitsound,
            Curve.from_kind_and_points(slider_type, points, pixel_length),
            repeat,
            pixel_length,
            ticks,
            num_beats,
            slider_tick_rate,
            ms_per_beat,
            edge_sounds,
            edge_additions,
            *rest,
        )
github llllllllll / slider / slider / curve.py View on Github external
------
        group : list[any]
            The groups split on duplicates.
        """
        old_ix = 0
        for n, (a, b) in enumerate(sliding_window(2, input_), 1):
            if a == b:
                yield input_[old_ix:n]
                old_ix = n

        tail = input_[old_ix:]
        if tail:
            yield tail


class Linear(_MetaCurveMixin, Curve):
    """Linear curves traverse the line segments between the given points.

    Parameters
    ----------
    points : list[Position]
        The positions of the control points.
    req_length : float
        The pixel length of the curve.
    """
    def __init__(self, points, req_length):
        super().__init__(points, req_length)

        self._curves = [
            Bezier(subpoints, None) for subpoints in sliding_window(2, points)
        ]
github llllllllll / slider / slider / curve.py View on Github external
ortho_a_to_c = np.array((a_to_c[1], -a_to_c[0]))
        if np.dot(ortho_a_to_c, coordinates[1] - coordinates[0]) < 0:
            self._angle = -(2 * math.pi - self._angle)

        length = abs(
            self._angle *
            math.sqrt(coordinates[0][0] ** 2 + coordinates[0][1] ** 2),
        )
        if length > req_length:
            self._angle *= req_length / length

    def __call__(self, t):
        return rotate(self.points[0], self._center, self._angle * t)


class Catmull(Curve):
    """Catmull curves implement the Catmull-Rom spline algorithm for defining
    the path.
    """
    def __call__(self, t):
        raise NotImplementedError('catmull positions not supported yet')


def get_center(a, b, c):
    """Returns the Position of the center of the circle described by the 3
    points

    Parameters
    ----------
    a, b, c : Position
        The three positions.
github llllllllll / slider / slider / curve.py View on Github external
if len(self._curves) == 1:
            # Special case where we only have one curve
            return self._curves[0](t)

        bi = bisect.bisect_left(ts, t)
        if bi == 0:
            pre_t = 0
        else:
            pre_t = ts[bi - 1]

        post_t = ts[bi]

        return self._curves[bi]((t - pre_t) / (post_t - pre_t))


class MultiBezier(_MetaCurveMixin, Curve):
    """MultiBezier is a collection of `:class:~slider.curve.Bezier` curves
    stitched together at the ends.

    Parameters
    ----------
    points : list[Position]
        The positions of the control points.
    req_length : float
        The pixel length of the curve.
    """
    def __init__(self, points, req_length):
        super().__init__(points, req_length)

        self._curves = [
            Bezier(subpoints, None)
            for subpoints in self._split_at_dupes(points)