Пример #1
0
    def set_style(self,
                  fill_color: ManimColor | Iterable[ManimColor] | None = None,
                  fill_opacity: float | Iterable[float] | None = None,
                  fill_rgba: npt.ArrayLike | None = None,
                  stroke_color: ManimColor | Iterable[ManimColor]
                  | None = None,
                  stroke_opacity: float | Iterable[float] | None = None,
                  stroke_rgba: npt.ArrayLike | None = None,
                  stroke_width: float | Iterable[float] | None = None,
                  stroke_background: bool = True,
                  reflectiveness: float | None = None,
                  gloss: float | None = None,
                  shadow: float | None = None,
                  recurse: bool = True):
        for mob in self.get_family(recurse):
            if fill_rgba is not None:
                mob.data['fill_rgba'] = resize_with_interpolation(
                    fill_rgba, len(fill_rgba))
            else:
                mob.set_fill(color=fill_color,
                             opacity=fill_opacity,
                             recurse=False)

            if stroke_rgba is not None:
                mob.data['stroke_rgba'] = resize_with_interpolation(
                    stroke_rgba, len(fill_rgba))
                mob.set_stroke(
                    width=stroke_width,
                    background=stroke_background,
                    recurse=False,
                )
            else:
                mob.set_stroke(
                    color=stroke_color,
                    width=stroke_width,
                    opacity=stroke_opacity,
                    recurse=False,
                    background=stroke_background,
                )

            if reflectiveness is not None:
                mob.set_reflectiveness(reflectiveness, recurse=False)
            if gloss is not None:
                mob.set_gloss(gloss, recurse=False)
            if shadow is not None:
                mob.set_shadow(shadow, recurse=False)
        return self
Пример #2
0
    def set_style(self,
                  fill_color=None,
                  fill_opacity=None,
                  fill_rgba=None,
                  stroke_color=None,
                  stroke_opacity=None,
                  stroke_rgba=None,
                  stroke_width=None,
                  stroke_background=True,
                  reflectiveness=None,
                  gloss=None,
                  shadow=None,
                  recurse=True):
        if fill_rgba is not None:
            self.data['fill_rgba'] = resize_with_interpolation(fill_rgba, len(fill_rgba))
        else:
            self.set_fill(
                color=fill_color,
                opacity=fill_opacity,
                recurse=recurse
            )

        if stroke_rgba is not None:
            self.data['stroke_rgba'] = resize_with_interpolation(stroke_rgba, len(fill_rgba))
            self.set_stroke(
                width=stroke_width,
                background=stroke_background,
            )
        else:
            self.set_stroke(
                color=stroke_color,
                width=stroke_width,
                opacity=stroke_opacity,
                recurse=recurse,
                background=stroke_background,
            )

        if reflectiveness is not None:
            self.set_reflectiveness(reflectiveness, recurse=recurse)
        if gloss is not None:
            self.set_gloss(gloss, recurse=recurse)
        if shadow is not None:
            self.set_shadow(shadow, recurse=recurse)
        return self
Пример #3
0
    def set_style(
        self,
        fill_color=None,
        fill_opacity=None,
        fill_rgba=None,
        stroke_color=None,
        stroke_opacity=None,
        stroke_rgba=None,
        stroke_width=None,
        gloss=None,
        shadow=None,
        recurse=True,
    ):
        if fill_rgba is not None:
            self.data["fill_rgba"] = resize_with_interpolation(
                fill_rgba, len(fill_rgba)
            )
        else:
            self.set_fill(color=fill_color, opacity=fill_opacity, recurse=recurse)

        if stroke_rgba is not None:
            self.data["stroke_rgba"] = resize_with_interpolation(
                stroke_rgba, len(fill_rgba)
            )
            self.set_stroke(width=stroke_width)
        else:
            self.set_stroke(
                color=stroke_color,
                width=stroke_width,
                opacity=stroke_opacity,
                recurse=recurse,
            )

        if gloss is not None:
            self.set_gloss(gloss, recurse=recurse)
        if shadow is not None:
            self.set_shadow(shadow, recurse=recurse)
        return self
Пример #4
0
def get_colormap_list(map_name="viridis", n_colors=9):
    """
    Options for map_name:
    3b1b_colormap
    magma
    inferno
    plasma
    viridis
    cividis
    twilight
    twilight_shifted
    turbo
    """
    from matplotlib.cm import get_cmap

    if map_name == "3b1b_colormap":
        rgbs = [color_to_rgb(color) for color in COLORMAP_3B1B]
    else:
        rgbs = get_cmap(map_name).colors  # Make more general?
    return resize_with_interpolation(np.array(rgbs), n_colors)
Пример #5
0
 def align_stroke_width_data_to_points(self, recurse=True):
     for mob in self.get_family(recurse):
         mob.data["stroke_width"] = resize_with_interpolation(
             mob.data["stroke_width"], len(mob.get_points()))
Пример #6
0
 def match_colors(self, pmobject):
     self.data["rgbas"][:] = resize_with_interpolation(
         pmobject.data["rgbas"], self.get_num_points())
     return self