Esempio n. 1
0
    def pointwise_become_partial(self, mobject, a, b):
        assert (isinstance(mobject, VMobject))
        # Partial curve includes three portions:
        # - A middle section, which matches the curve exactly
        # - A start, which is some ending portion of an inner cubic
        # - An end, which is the starting portion of a later inner cubic
        if a <= 0 and b >= 1:
            self.set_points(mobject.points)
            self.mark_paths_closed = mobject.mark_paths_closed
            return self
        self.mark_paths_closed = False
        num_cubics = mobject.get_num_anchor_points() - 1
        lower_index = int(a * num_cubics)
        upper_index = int(b * num_cubics)
        points = np.array(mobject.points[3 * lower_index:3 * upper_index + 4])
        if len(points) > 1:
            a_residue = (num_cubics * a) % 1
            b_residue = (num_cubics * b) % 1
            if b == 1:
                b_residue = 1
            elif lower_index == upper_index:
                b_residue = (b_residue - a_residue) / (1 - a_residue)

            points[:4] = partial_bezier_points(points[:4], a_residue, 1)
            points[-4:] = partial_bezier_points(points[-4:], 0, b_residue)
        self.set_points(points)
        return self
    def pointwise_become_partial(self, mobject, a, b):
        assert(isinstance(mobject, VMobject))
        # Partial curve includes three portions:
        # - A middle section, which matches the curve exactly
        # - A start, which is some ending portion of an inner cubic
        # - An end, which is the starting portion of a later inner cubic
        if a <= 0 and b >= 1:
            self.set_points(mobject.points)
            self.mark_paths_closed = mobject.mark_paths_closed
            return self
        self.mark_paths_closed = False
        num_cubics = mobject.get_num_anchor_points() - 1
        lower_index = int(a * num_cubics)
        upper_index = int(b * num_cubics)
        points = np.array(
            mobject.points[3 * lower_index:3 * upper_index + 4]
        )
        if len(points) > 1:
            a_residue = (num_cubics * a) % 1
            b_residue = (num_cubics * b) % 1
            if b == 1:
                b_residue = 1
            elif lower_index == upper_index:
                b_residue = (b_residue - a_residue) / (1 - a_residue)

            points[:4] = partial_bezier_points(
                points[:4], a_residue, 1
            )
            points[-4:] = partial_bezier_points(
                points[-4:], 0, b_residue
            )
        self.set_points(points)
        return self
Esempio n. 3
0
 def insert_n_anchor_points(self, n):
     curr = self.get_num_anchor_points()
     if curr == 0:
         self.points = np.zeros((1, 3))
         n = n - 1
     if curr == 1:
         self.points = np.repeat(self.points, 3 * n + 1, axis=0)
         return self
     points = np.array([self.points[0]])
     num_curves = curr - 1
     # Curves in self are buckets, and we need to know
     # how many new anchor points to put into each one.
     # Each element of index_allocation is like a bucket,
     # and its value tells you the appropriate index of
     # the smaller curve.
     index_allocation = (np.arange(curr + n - 1) * num_curves) // (curr +
                                                                   n - 1)
     for index in range(num_curves):
         curr_bezier_points = self.points[3 * index:3 * index + 4]
         num_inter_curves = sum(index_allocation == index)
         alphas = np.linspace(0, 1, num_inter_curves + 1)
         # alphas = np.arange(0, num_inter_curves+1)/float(num_inter_curves)
         for a, b in zip(alphas, alphas[1:]):
             new_points = partial_bezier_points(curr_bezier_points, a, b)
             points = np.append(points, new_points[1:], axis=0)
     self.set_points(points)
     return self
 def insert_n_anchor_points(self, n):
     curr = self.get_num_anchor_points()
     if curr == 0:
         self.points = np.zeros((1, 3))
         n = n - 1
     if curr == 1:
         self.points = np.repeat(self.points, 3 * n + 1, axis=0)
         return self
     points = np.array([self.points[0]])
     num_curves = curr - 1
     # Curves in self are buckets, and we need to know
     # how many new anchor points to put into each one.
     # Each element of index_allocation is like a bucket,
     # and its value tells you the appropriate index of
     # the smaller curve.
     index_allocation = (np.arange(curr + n - 1) *
                         num_curves) / (curr + n - 1)
     for index in range(num_curves):
         curr_bezier_points = self.points[3 * index:3 * index + 4]
         num_inter_curves = sum(index_allocation == index)
         alphas = np.linspace(0, 1, num_inter_curves + 1)
         # alphas = np.arange(0, num_inter_curves+1)/float(num_inter_curves)
         for a, b in zip(alphas, alphas[1:]):
             new_points = partial_bezier_points(
                 curr_bezier_points, a, b
             )
             points = np.append(
                 points, new_points[1:], axis=0
             )
     self.set_points(points)
     return self