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)) ])
def init_data(self): super().init_data() self.data["value"] = np.array( listify(self.value), ndmin=2, dtype=self.value_type, )
def set_opacity(self, alpha, family=True): opacity = listify(alpha) diff = 4 - len(opacity) opacity += [opacity[-1]] * diff self.opacity = np.array(opacity).reshape((4, 1)) if family: for sm in self.submobjects: sm.set_opacity(alpha)
def set_stroke(self, color=None, width=None, opacity=None, background=None, family=True): if family: for sm in self.submobjects: sm.set_stroke(color, width, opacity, background, family) self.update_rgbas_array("stroke_rgbas", color, opacity) if width is not None: self.stroke_width = np.array(listify(width)) if background is not None: self.draw_stroke_behind_fill = background return self
def set_stroke(self, color=None, width=None, opacity=None, background=None, recurse=True): self.set_rgba_array_by_color(color, opacity, 'stroke_rgba', recurse) if width is not None: for mob in self.get_family(recurse): if isinstance(width, np.ndarray): arr = width.reshape((len(width), 1)) else: arr = np.array([[w] for w in listify(width)]) mob.data['stroke_width'] = arr if background is not None: for mob in self.get_family(recurse): mob.draw_stroke_behind_fill = background return self
def get_u_values_and_v_values(self): res = listify(self.resolution) if len(res) == 1: u_res = v_res = res[0] else: u_res, v_res = res u_min = self.u_min u_max = self.u_max v_min = self.v_min v_max = self.v_max u_values = np.linspace(u_min, u_max, u_res + 1) v_values = np.linspace(v_min, v_max, v_res + 1) return u_values, v_values
def __init__(self, obj: VMobject | list[VMobject], text: str | Iterable[str], brace_direction: np.ndarray = DOWN, **kwargs) -> None: VMobject.__init__(self, **kwargs) self.brace_direction = brace_direction if isinstance(obj, list): obj = VMobject(*obj) self.brace = Brace(obj, brace_direction, **kwargs) self.label = self.label_constructor(*listify(text), **kwargs) self.label.scale(self.label_scale) self.brace.put_at_tip(self.label, buff=self.label_buff) self.set_submobjects([self.brace, self.label])
def set_stroke(self, color=None, width=None, opacity=None, background=None, recurse=True): self.set_rgba_array(color, opacity, 'stroke_rgba', recurse) if width is not None: for mob in self.get_family(recurse): mob.data['stroke_width'] = np.array( [[width] for width in listify(width)]) if background is not None: for mob in self.get_family(recurse): mob.draw_stroke_behind_fill = background return self
def set_stroke(self, color: ManimColor | None = None, width: float | npt.ArrayLike | None = None, opacity: float | None = None, background: bool | None = None, recurse: bool = True): self.set_rgba_array_by_color(color, opacity, 'stroke_rgba', recurse) if width is not None: for mob in self.get_family(recurse): if isinstance(width, np.ndarray): arr = width.reshape((len(width), 1)) else: arr = np.array([[w] for w in listify(width)], dtype=float) mob.data['stroke_width'] = arr if background is not None: for mob in self.get_family(recurse): mob.draw_stroke_behind_fill = background return self
def set_opacity(self, opacity, recurse=True): for mob in self.get_family(recurse): mob.data["opacity"] = np.array([[o] for o in listify(opacity)]) return self
def complete_p_list(self, p_list: list[float]) -> list[float]: new_p_list = listify(p_list) remainder = 1.0 - sum(new_p_list) if abs(remainder) > EPSILON: new_p_list.append(remainder) return new_p_list