def construct(self): circle = Circle(color=PURPLE_A) square = Square(fill_color=GOLD_B, fill_opacity=1, color=GOLD_A) square.move_to(UP + LEFT) circle.surround(square) rectangle = Rectangle(height=2, width=3) ellipse = Ellipse(width=3, height=1, color=RED) ellipse.shift(2 * DOWN + 2 * RIGHT) pointer = CurvedArrow(2 * RIGHT, 5 * RIGHT, color=MAROON_C) arrow = Arrow(LEFT, UP) arrow.next_to(circle, DOWN + LEFT) rectangle.next_to(arrow, DOWN + LEFT) circle2 = Circle() circle2.surround(rectangle, buffer_factor=1) ring = Annulus(inner_radius=.5, outer_radius=1, color=BLUE) ring.next_to(ellipse, RIGHT) self.add(pointer) self.add(circle2) self.play(FadeIn(square)) self.play(Rotating(square), FadeIn(circle)) self.play(GrowArrow(arrow)) self.play(GrowFromCenter(rectangle), GrowFromCenter(ellipse), GrowFromCenter(ring)) self.wait()
def __init__(self, text, texmob=None, **kwargs): digest_config(self, kwargs) VGroup.__init__(self, **kwargs) pre_coord_dl = text.get_corner(DL) pre_coord_ur = text.get_corner(UR) reference_line = Line(pre_coord_dl, pre_coord_ur) reference_unit_vector = reference_line.get_unit_vector() coord_dl = text.get_corner( DL) - text.get_center() - reference_unit_vector * self.buff_line coord_ur = text.get_corner( UR) - text.get_center() + reference_unit_vector * self.buff_line if texmob == None: line = Line(coord_dl, coord_ur, **self.line_kwargs) self.add(line) else: arrow = Arrow(coord_dl, coord_ur, **self.line_kwargs) unit_vector = arrow.get_unit_vector() if self.buff_text == None: self.buff_text = get_norm( (texmob.get_center() - texmob.get_critical_point(unit_vector)) / 2) * 2 texmob.move_to(arrow.get_end() + unit_vector * self.buff_text) self.add(arrow, texmob)
def sort(self): nodes_length = len(self.nodes) swapped = True nb_iterations = 1 nb_iterations_text = None while swapped: self.remove(nb_iterations_text) nb_iterations_text = TextMobject("Iteration " + str(nb_iterations)) nb_iterations_text.move_to(2 * UP) self.add(nb_iterations_text) swapped = False arrow = Arrow(UP + RIGHT) # I don't get it arrow.scale(1) arrow.move_to(UP + 3 * LEFT) self.add(arrow) for i in range(nodes_length - 1): arrow.generate_target() arrow.target.move_to(self.nodes[i].circle.get_arc_center() + UP) self.play(MoveToTarget(arrow)) if self.nodes[i + 1].value < self.nodes[i].value: self.swap_nodes(i, i + 1) swapped = True self.remove(arrow) nb_iterations = nb_iterations + 1 self.wait(0.1) self.remove(nb_iterations_text)
def get_vector(self, coords, **kwargs): kwargs["buff"] = 0 return Arrow( self.coords_to_point(0, 0), self.coords_to_point(*coords), **kwargs )
def get_vector(self, numerical_vector, **kwargs): return Arrow( self.plane.coords_to_point(0, 0), self.plane.coords_to_point(*numerical_vector[:2]), buff=0, **kwargs )
def add_tip(self): start, end = self.main_line.get_start_and_end() vect = (end - start) / get_norm(end - start) arrow = Arrow(start, end + MED_SMALL_BUFF * vect, buff=0) tip = arrow.tip tip.set_stroke(width=self.get_stroke_width()) tip.set_color(self.color) self.tip = tip self.add(tip)
def find_index_minimum(self, from_index): arrow = Arrow(DOWN + RIGHT) # I don't get it arrow.scale(0.5) arrow.move_to(self.nodes[from_index].circle.get_arc_center() + DOWN) arrow.set_color(BLUE) self.add(arrow) index_min = from_index self.nodes[index_min].circle.set_color(BLUE) for i in range(from_index + 1, len(self.nodes)): arrow.generate_target() arrow.target.move_to(self.nodes[i].circle.get_arc_center() + DOWN) self.play(MoveToTarget(arrow)) if self.nodes[i].value < self.nodes[index_min].value: self.nodes[index_min].circle.set_color(RED) index_min = i self.nodes[index_min].circle.set_color(BLUE) self.remove(arrow) return index_min
def sort(self): nodes_length = len(self.nodes) arrow = Arrow(UP + RIGHT) # I don't get it arrow.scale(1) arrow.move_to(UP + 3 * LEFT) self.add(arrow) for i in range(nodes_length): arrow.generate_target() arrow.target.move_to(self.nodes[i].circle.get_arc_center() + UP) self.play(MoveToTarget(arrow)) index_min = self.find_index_minimum(i) if i != index_min: self.swap_nodes(i, index_min) self.nodes[i].circle.set_color(GREEN)
def sort(self): nodes_length = len(self.nodes) arrow = Arrow(UP + RIGHT) # I don't get it arrow.scale(1) arrow.move_to(UP + 3 * LEFT) self.add(arrow) for i in range(1, nodes_length): arrow.generate_target() arrow.target.move_to(self.nodes[i].circle.get_arc_center() + UP) self.play(MoveToTarget(arrow)) j = i while j > 0 and self.nodes[j].value < self.nodes[j - 1].value: self.swap_nodes(j, j - 1) j = j - 1 self.wait(0.1)
def add_remark(self): nl_text = TextMobject("数轴") nl_arrow = Arrow(ORIGIN, UP).match_height(nl_text) nl_remark = VGroup(nl_arrow, nl_text) nl_remark.scale(0.8) nl_remark.set_color(LIGHT_GREY) nl_remark.arrange_submobjects(RIGHT, buff = 0.1) nl_remark.next_to(self.axes.coords_to_point(0, 0), DOWN, buff = 0.1) nl_remark.to_edge(LEFT, buff = 0.15) frac_remark = TextMobject("圆内分数为圆心横坐标") frac_remark.scale(0.6) frac_remark.to_corner(DL, buff = 0.15) farey_sum_remark = TexMobject( "\\text{Farey Sum: }", "\\dfrac{a}{b} \\oplus \\dfrac{c}{d}", "=", "\\dfrac{a+c}{b+d}" ) farey_sum_remark[1].set_color(YELLOW) farey_sum_remark[-1].set_color(PINK) farey_sum_remark.to_corner(DR, buff = 0.15) self.add(nl_remark, frac_remark, farey_sum_remark)
def get_digit_increment_animations(self): result = [] self.number += 1 is_next_digit = self.is_next_digit() if is_next_digit: self.max_place += 1 new_number_mob = self.get_number_mob(self.number) new_number_mob.move_to(self.number_mob, RIGHT) if is_next_digit: self.add_configuration() place = len(new_number_mob.split()) - 1 result.append(FadeIn(self.dot_templates[place])) arrow = Arrow(new_number_mob[place].get_top(), self.dot_templates[place].get_bottom(), color=self.digit_place_colors[place]) self.arrows.add(arrow) result.append(ShowCreation(arrow)) result.append(Transform(self.number_mob, new_number_mob, lag_ratio=0.5)) return result
def get_vector(self, numerical_vector, **kwargs): """ Returns an arrow on the Plane given an input numerical vector. Parameters ---------- numerical_vector : Union(np.ndarray, list, tuple) The Vector to plot. **kwargs Any valid keyword argument of Arrow. Returns ------- Arrow The Arrow representing the Vector. """ return Arrow(self.plane.coords_to_point(0, 0), self.plane.coords_to_point(*numerical_vector[:2]), buff=0, **kwargs)
def get_vector(self, coords, **kwargs): vector_config = merge_dicts_recursively(self.vector_config, kwargs) output = np.array(self.func(*coords)) norm = get_norm(output) if norm > 0: output *= self.length_func(norm) / norm origin = self.coordinate_system.get_origin() _input = self.coordinate_system.c2p(*coords) _output = self.coordinate_system.c2p(*output) vect = Arrow(origin, _output, buff=0, **vector_config) vect.shift(_input - origin) vect.set_rgba_array([[*self.value_to_rgb(norm), self.opacity]]) return vect
def get_vector(self, coords, **kwargs): point = coords[0] * RIGHT + coords[1] * UP arrow = Arrow(ORIGIN, point, **kwargs) return arrow
def get_complete_vector(self, coords, **kwargs): kwargs["buff"] = 0 return Arrow(self.coords_to_point(coords[0], coords[1]), self.coords_to_point(*coords[2:]), **kwargs)
def get_vector(self, coords: Iterable[float], **kwargs) -> Arrow: kwargs["buff"] = 0 return Arrow(self.c2p(0, 0), self.c2p(*coords), **kwargs)
def __init__(self, arrow: Arrow, **kwargs): point = arrow.get_start() super().__init__(arrow, point, **kwargs)