Пример #1
0
 def set_color(self, color=YELLOW_C, family=True):
     rgba = color_to_rgba(color)
     mobs = self.family_members_with_points() if family else [self]
     for mob in mobs:
         mob.rgbas[:, :] = rgba
     self.color = color
     return self
Пример #2
0
 def set_color(self, color=YELLOW_C, family=True):
     rgba = color_to_rgba(color)
     mobs = self.family_members_with_points() if family else [self]
     for mob in mobs:
         mob.rgbas[:, :] = rgba
     self.color = color
     return self
 def generate_rgba_array(self, color, opacity):
     """
     First arg can be either a color, or a tuple/list of colors.
     Likewise, opacity can either be a float, or a tuple of floats.
     """
     colors = listify(color)
     opacities = listify(opacity)
     return np.array([
         color_to_rgba(c, o) for c, o in zip(*make_even(colors, opacities))
     ])
Пример #4
0
 def __init__(self, ctx: moderngl.Context | None = None, **kwargs):
     digest_config(self, kwargs, locals())
     self.rgb_max_val: float = np.iinfo(self.pixel_array_dtype).max
     self.background_rgba: list[float] = list(
         color_to_rgba(self.background_color, self.background_opacity))
     self.init_frame()
     self.init_context(ctx)
     self.init_shaders()
     self.init_textures()
     self.init_light_source()
     self.refresh_perspective_uniforms()
     # A cached map from mobjects to their associated list of render groups
     # so that these render groups are not regenerated unnecessarily for static
     # mobjects
     self.mob_to_render_groups = {}
Пример #5
0
 def add_points(self, points, rgbas=None, color=None, opacity=None):
     """
     points must be a Nx3 numpy array, as must rgbas if it is not None
     """
     self.append_points(points)
     # rgbas array will have been resized with points
     if color is not None:
         if opacity is None:
             opacity = self.data["rgbas"][-1, 3]
         new_rgbas = np.repeat([color_to_rgba(color, opacity)],
                               len(points),
                               axis=0)
     elif rgbas is not None:
         new_rgbas = rgbas
     self.data["rgbas"][-len(new_rgbas):] = new_rgbas
     return self
Пример #6
0
 def add_points(self, points, rgbas=None, color=None, alpha=1):
     """
     points must be a Nx3 numpy array, as must rgbas if it is not None
     """
     if not isinstance(points, np.ndarray):
         points = np.array(points)
     num_new_points = len(points)
     self.points = np.append(self.points, points, axis=0)
     if rgbas is None:
         color = Color(color) if color else self.color
         rgbas = np.repeat([color_to_rgba(color, alpha)],
                           num_new_points,
                           axis=0)
     elif len(rgbas) != len(points):
         raise Exception("points and rgbas must have same shape")
     self.rgbas = np.append(self.rgbas, rgbas, axis=0)
     return self
Пример #7
0
 def add_points(self,
                points: npt.ArrayLike,
                rgbas: np.ndarray | None = None,
                color: ManimColor | None = None,
                opacity: float | None = None):
     """
     points must be a Nx3 numpy array, as must rgbas if it is not None
     """
     self.append_points(points)
     # rgbas array will have been resized with points
     if color is not None:
         if opacity is None:
             opacity = self.data["rgbas"][-1, 3]
         rgbas = np.repeat([color_to_rgba(color, opacity)],
                           len(points),
                           axis=0)
     if rgbas is not None:
         self.data["rgbas"][-len(rgbas):] = rgbas
     return self
Пример #8
0
 def add_points(self, points, rgbas=None, color=None, alpha=1):
     """
     points must be a Nx3 numpy array, as must rgbas if it is not None
     """
     if not isinstance(points, np.ndarray):
         points = np.array(points)
     num_new_points = len(points)
     self.points = np.append(self.points, points, axis=0)
     if rgbas is None:
         color = Color(color) if color else self.color
         rgbas = np.repeat(
             [color_to_rgba(color, alpha)],
             num_new_points,
             axis=0
         )
     elif len(rgbas) != len(points):
         raise Exception("points and rgbas must have same shape")
     self.rgbas = np.append(self.rgbas, rgbas, axis=0)
     return self
Пример #9
0
    def generate_rgbas_array(self, color, opacity):
        """
        First arg can be either a color, or a tuple/list of colors.
        Likewise, opacity can either be a float, or a tuple of floats.
        If self.sheen_factor is not zero, and only
        one color was passed in, a second slightly light color
        will automatically be added for the gradient
        """
        colors = list(tuplify(color))
        opacities = list(tuplify(opacity))
        rgbas = np.array([
            color_to_rgba(c, o) for c, o in zip(*make_even(colors, opacities))
        ])

        sheen_factor = self.get_sheen_factor()
        if sheen_factor != 0 and len(rgbas) == 1:
            light_rgbas = np.array(rgbas)
            light_rgbas[:, :3] += sheen_factor
            clip_in_place(light_rgbas, 0, 1)
            rgbas = np.append(rgbas, light_rgbas, axis=0)
        return rgbas
Пример #10
0
    def generate_rgbas_array(self, color, opacity):
        """
        First arg can be either a color, or a tuple/list of colors.
        Likewise, opacity can either be a float, or a tuple of floats.
        If self.sheen_factor is not zero, and only
        one color was passed in, a second slightly light color
        will automatically be added for the gradient
        """
        colors = list(tuplify(color))
        opacities = list(tuplify(opacity))
        rgbas = np.array([
            color_to_rgba(c, o)
            for c, o in zip(*make_even(colors, opacities))
        ])

        sheen_factor = self.get_sheen_factor()
        if sheen_factor != 0 and len(rgbas) == 1:
            light_rgbas = np.array(rgbas)
            light_rgbas[:, :3] += sheen_factor
            clip_in_place(light_rgbas, 0, 1)
            rgbas = np.append(rgbas, light_rgbas, axis=0)
        return rgbas
Пример #11
0
 def get_value(self):
     r = self.r_slider.get_value() / 255
     g = self.g_slider.get_value() / 255
     b = self.b_slider.get_value() / 255
     alpha = self.a_slider.get_value()
     return color_to_rgba(rgb_to_color((r, g, b)), alpha=alpha)
Пример #12
0
 def fade_to(self, color, alpha):
     self.rgbas = interpolate(self.rgbas, color_to_rgba(color), alpha)
     for mob in self.submobjects:
         mob.fade_to(color, alpha)
     return self
Пример #13
0
 def fade_to(self, color, alpha):
     self.rgbas = interpolate(self.rgbas, color_to_rgba(color), alpha)
     for mob in self.submobjects:
         mob.fade_to(color, alpha)
     return self