def create_eyes(self, mode=None, thing_to_look_at=None): if mode is None: mode = self.mode if thing_to_look_at is None: thing_to_look_at = self.thing_to_look_at self.thing_to_look_at = thing_to_look_at self.mode = mode looking_direction = None pi = PiCreature(mode=mode) eyes = VGroup(pi.eyes, pi.pupils) if self.submobjects: eyes.match_height(self) eyes.move_to(self, DOWN) looking_direction = self[1].get_center() - self[0].get_center() else: eyes.set_height(self.height) eyes.move_to(self.body.get_top(), DOWN) height = eyes.get_height() if thing_to_look_at is not None: pi.look_at(thing_to_look_at) elif looking_direction is not None: pi.look(looking_direction) eyes.set_height(height) return eyes
def get_eyes(self, mode=None, thing_to_look_at=None): mode = mode or self.mode if thing_to_look_at is None: thing_to_look_at = self.thing_looked_at pi = Randolph(mode=mode) eyes = VGroup(pi.eyes, pi.pupils) pi.scale(self.height / eyes.get_height()) if self.submobjects: eyes.move_to(self, DOWN) else: eyes.move_to(self.mobject.get_top(), DOWN) if thing_to_look_at is not None: pi.look_at(thing_to_look_at) return eyes
def get_secant_slope_group( self, x, graph, dx=None, dx_line_color=None, df_line_color=None, dx_label=None, df_label=None, include_secant_line=True, secant_line_color=None, secant_line_length=10, ): """ Resulting group is of the form VGroup( dx_line, df_line, dx_label, (if applicable) df_label, (if applicable) secant_line, (if applicable) ) with attributes of those names. """ kwargs = locals() kwargs.pop("self") group = VGroup() group.kwargs = kwargs dx = dx or float(self.x_max - self.x_min) / 10 dx_line_color = dx_line_color or self.default_input_color df_line_color = df_line_color or graph.get_color() p1 = self.input_to_graph_point(x, graph) p2 = self.input_to_graph_point(x + dx, graph) interim_point = p2[0] * RIGHT + p1[1] * UP group.dx_line = Line(p1, interim_point, color=dx_line_color) group.df_line = Line(interim_point, p2, color=df_line_color) group.add(group.dx_line, group.df_line) labels = VGroup() if dx_label is not None: group.dx_label = TexMobject(dx_label) labels.add(group.dx_label) group.add(group.dx_label) if df_label is not None: group.df_label = TexMobject(df_label) labels.add(group.df_label) group.add(group.df_label) if len(labels) > 0: max_width = 0.8 * group.dx_line.get_width() max_height = 0.8 * group.df_line.get_height() if labels.get_width() > max_width: labels.scale_to_fit_width(max_width) if labels.get_height() > max_height: labels.scale_to_fit_height(max_height) if dx_label is not None: group.dx_label.next_to(group.dx_line, np.sign(dx) * DOWN, buff=group.dx_label.get_height() / 2) group.dx_label.set_color(group.dx_line.get_color()) if df_label is not None: group.df_label.next_to(group.df_line, np.sign(dx) * RIGHT, buff=group.df_label.get_height() / 2) group.df_label.set_color(group.df_line.get_color()) if include_secant_line: secant_line_color = secant_line_color or self.default_derivative_color group.secant_line = Line(p1, p2, color=secant_line_color) group.secant_line.scale_in_place(secant_line_length / group.secant_line.get_length()) group.add(group.secant_line) return group
def show_the_solution(self): # Prepare for the solution pre_solve = VGroup(*self.question[::2]) self.play( ReplacementTransform(pre_solve, self.solve), FadeOut(self.question[1]), run_time = 1, ) self.wait() # Manipulate LHS old_l_part, r_part = self.equation new_l_part = ExpTower(order = self.highest_order+1, is_infinite = True) new_l_part.match_height(old_l_part) new_l_part.next_to(r_part, LEFT, aligned_edge = DOWN) old_rect, new_rect = rects = [ CoverRectangle(part, text = "2") for part in (old_l_part, new_l_part.get_exponent()) ] old_two, new_two = twos = [ rect.get_text_mob() for rect in rects ] self.play(DrawBorderThenFill(old_rect, run_time = 1)) self.wait() self.play( ReplacementTransform(old_l_part, new_l_part), ReplacementTransform(old_rect, new_rect), ) self.wait() new_equation = VGroup(new_l_part, r_part, new_rect) new_equation.generate_target() new_equation.target.scale(0.8) new_equation.target.shift(UP) self.play(MoveToTarget(new_equation)) self.wait() # A little bit clean-up source_eq = VGroup(*[ mob.copy() for mob in (new_l_part.get_base(), new_two, r_part[0], r_part[1]) ]) source_eq.generate_target() target_eq = TexMobject("x", "^2", "=", "2") target_eq.scale(3).next_to(source_eq, DOWN, buff = 1) for k, (old_part, new_part) in enumerate(zip(source_eq.target, target_eq)): old_part.move_to(new_part) if k == 1: old_part.scale(0.5) old_part.shift(RIGHT/4) self.play( FadeOut(new_rect), MoveToTarget(source_eq), ) self.wait() # Reveal the final answer result = TexMobject("x", "=", "\\sqrt", "2") result.set_height(source_eq.get_height() * 0.7) result.move_to(source_eq) self.play(*[ ReplacementTransform(source_eq[m], result[n], path_arc = angle) for m, n, angle in [(0, 0, 0), (1, 2, -TAU/3), (2, 1, 0), (3, 3, 0)] ]) self.wait() qed = QEDSymbol() qed.next_to(result, RIGHT, aligned_edge = DOWN, buff = 1.5) self.play(FadeIn(qed)) self.wait()