class Shadow_2d(VGroup): CONFIG = { 'shadow_color': DARK_GRAY, 'shadow_opacity': 0.6, 'blur_width': 0.25, 'layer_num': 40, 'scale_factor': 1, 'shadow_out': True, 'show_basic_shape': True, 'plot_depth':-1, 'rate_func': lambda t: t ** 0.5, } def __init__(self, mob_or_points, **kwargs): VGroup.__init__(self, **kwargs) if type(mob_or_points) == list: self.shape = Polygon(*mob_or_points, stroke_width=0, plot_depth=-1) else: self.shape = mob_or_points.set_stroke(width=0) self.shape.set_fill(color=self.shadow_color, opacity=self.shadow_opacity * (1 if self.show_basic_shape else 0)).scale(self.scale_factor) self.blur_outline = VGroup() s = (self.shape.get_height() + self.shape.get_width())/2 if self.blur_width > 1e-4: for i in range(self.layer_num): layer_i = self.shape.copy().set_stroke(color=self.shadow_color, width=100 * self.blur_width/self.layer_num, opacity=self.shadow_opacity * (1-self.rate_func(i/self.layer_num))).\ set_fill(opacity=0).scale((s + (1 if self.shadow_out else -1) * self.blur_width/self.layer_num * (i+0.5))/ s).set_plot_depth(-2) self.blur_outline.add(layer_i) self.add(self.shape, self.blur_outline)
def init_points(self) -> None: # Star by creating two of the pentagons, meeting # back to back on the positive x-axis phi = (1 + math.sqrt(5)) / 2 x, y, z = np.identity(3) pentagon1 = Polygon( [phi, 1 / phi, 0], [1, 1, 1], [1 / phi, 0, phi], [1, -1, 1], [phi, -1 / phi, 0], ) pentagon2 = pentagon1.copy().stretch(-1, 2, about_point=ORIGIN) pentagon2.reverse_points() x_pair = VGroup(pentagon1, pentagon2) z_pair = x_pair.copy().apply_matrix(np.array([z, -x, -y]).T) y_pair = x_pair.copy().apply_matrix(np.array([y, z, x]).T) self.add(*x_pair, *y_pair, *z_pair) for pentagon in list(self): pc = pentagon.copy() pc.apply_function(lambda p: -p) pc.reverse_points() self.add(pc)