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 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
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
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 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 = self.get_sheen() if sheen != 0 and len(rgbas) == 1: light_rgbas = np.array(rgbas) light_rgbas[:, :3] += sheen clip_in_place(light_rgbas, 0, 1) rgbas = np.append(rgbas, light_rgbas, axis=0) return rgbas
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