def construct(self): square = Square(side_length=5, fill_color=YELLOW, fill_opacity=1) label = TextMobject("Text at an angle") label_bg = BackgroundRectangle(label, fill_opacity=1) label_group = VGroup(label_bg, label) label_group.rotate(TAU / 8) label2 = TextMobject("Boxed text", color=BLACK) label2_bg = SurroundingRectangle(label2, color=BLUE, fill_color=RED, fill_opacity=.5) label2_group = VGroup(label2, label2_bg) label2_group.next_to(label_group, DOWN) label3 = TextMobject("Rainbow") label3.scale(2) label3.set_color_by_gradient(RED, GREEN, BLUE) label3.to_edge(DOWN) self.add(square) self.play(FadeIn(label_group)) self.play(FadeIn(label2_group)) self.play(FadeIn(label3)) self.wait(2)
def construct(self): axes = Axes(x_axis_config={ "include_ticks": False }, y_axis_config={ "include_ticks": False }, number_line_config={ "color": self.axes_color }).scale(0.9) self.add(axes) ellipse = Ellipse(width=self.width, height=self.height) ellipse_x_axis = DashedLine(self.width / 2 * LEFT, self.width / 2 * RIGHT, color=BLACK) ellipse_y_axis = DashedLine(self.height / 2 * UP, self.height / 2 * DOWN, color=BLACK) elipticity_line = Line(self.width / 2 * LEFT, self.height / 2 * UP, color=BLUE) elipticity_arc = Arc(0, math.atan(self.height / self.width)).shift( self.width / 2 * LEFT) ellipse_group = VGroup(ellipse, ellipse_x_axis, ellipse_y_axis, elipticity_arc, elipticity_line) ellipse_group.rotate(self.azimuth) self.add(ellipse_group) rightest = self.get_ellipse_rightest_point(self.width / 2, self.height / 2, self.azimuth) highest = self.get_ellipse_highest_point(self.width / 2, self.height / 2, self.azimuth) vertical_line = Line(rightest * RIGHT, rightest * RIGHT + highest * UP, color=GREEN) horizontal_line = Line(highest * UP, highest * UP + rightest * RIGHT, color=GREEN) self.bring_to_back(vertical_line, horizontal_line) azimuth_arc = Arc(0, self.azimuth) self.add(azimuth_arc) self.wait()
def add_spikes(self): layers = VGroup() radii = np.linspace( self.outer_radius, self.pupil_radius, self.n_spike_layers, endpoint=False, ) radii[:2] = radii[1::-1] # Swap first two if self.n_spike_layers > 2: radii[-1] = interpolate(radii[-1], self.pupil_radius, 0.25) for radius in radii: tip_angle = self.spike_angle half_base = radius * np.tan(tip_angle) triangle, right_half_triangle = [ Polygon( radius * UP, half_base * RIGHT, vertex3, fill_opacity=1, stroke_width=0, ) for vertex3 in ( half_base * LEFT, ORIGIN, ) ] left_half_triangle = right_half_triangle.copy() left_half_triangle.flip(UP, about_point=ORIGIN) n_spikes = self.n_spikes full_spikes = [ triangle.copy().rotate(-angle, about_point=ORIGIN) for angle in np.linspace(0, TAU, n_spikes, endpoint=False) ] index = (3 * n_spikes) // 4 if radius == radii[0]: layer = VGroup(*full_spikes) layer.rotate(-TAU / n_spikes / 2, about_point=ORIGIN) layer.brown_index = index else: half_spikes = [ right_half_triangle.copy(), left_half_triangle.copy().rotate( 90 * DEGREES, about_point=ORIGIN, ), right_half_triangle.copy().rotate( 90 * DEGREES, about_point=ORIGIN, ), left_half_triangle.copy() ] layer = VGroup(*it.chain( half_spikes[:1], full_spikes[1:index], half_spikes[1:3], full_spikes[index + 1:], half_spikes[3:], )) layer.brown_index = index + 1 layers.add(layer) # Color spikes blues = self.blue_spike_colors browns = self.brown_spike_colors for layer, blue, brown in zip(layers, blues, browns): index = layer.brown_index layer[:index].set_color(blue) layer[index:].set_color(brown) self.spike_layers = layers self.add(layers)
def add_spikes(self): layers = VGroup() radii = np.linspace( self.outer_radius, self.pupil_radius, self.n_spike_layers, endpoint=False, ) radii[:2] = radii[1::-1] # Swap first two radii[-1] = interpolate( radii[-1], self.pupil_radius, 0.25 ) for radius in radii: tip_angle = self.spike_angle half_base = radius * np.tan(tip_angle) triangle, right_half_triangle = [ Polygon( radius * UP, half_base * RIGHT, vertex3, fill_opacity=1, stroke_width=0, ) for vertex3 in (half_base * LEFT, ORIGIN,) ] left_half_triangle = right_half_triangle.copy() left_half_triangle.flip(UP, about_point=ORIGIN) n_spikes = self.n_spikes full_spikes = [ triangle.copy().rotate( -angle, about_point=ORIGIN ) for angle in np.linspace( 0, TAU, n_spikes, endpoint=False ) ] index = (3 * n_spikes) // 4 if radius == radii[0]: layer = VGroup(*full_spikes) layer.rotate( -TAU / n_spikes / 2, about_point=ORIGIN ) layer.brown_index = index else: half_spikes = [ right_half_triangle.copy(), left_half_triangle.copy().rotate( 90 * DEGREES, about_point=ORIGIN, ), right_half_triangle.copy().rotate( 90 * DEGREES, about_point=ORIGIN, ), left_half_triangle.copy() ] layer = VGroup(*it.chain( half_spikes[:1], full_spikes[1:index], half_spikes[1:3], full_spikes[index + 1:], half_spikes[3:], )) layer.brown_index = index + 1 layers.add(layer) # Color spikes blues = self.blue_spike_colors browns = self.brown_spike_colors for layer, blue, brown in zip(layers, blues, browns): index = layer.brown_index layer[:index].set_color(blue) layer[index:].set_color(brown) self.spike_layers = layers self.add(layers)