def construct(self): quote = TextMobject("Imagination is more important than knowledge") quote.set_color(RED) quote.to_edge(UP) quote2 = TextMobject( "A person who never made a mistake never tried anything new") quote2.set_color(YELLOW) author = TextMobject("- Albert Einstein") author.scale(0.75) corner = quote.get_corner(DOWN + RIGHT) print("corner", corner) author.next_to(corner, ORIGIN) self.add(quote, author) self.wait(2) self.play( Transform(quote, quote2), ApplyMethod(author.move_to, quote2.get_corner(DOWN + RIGHT) + DOWN + 2 * LEFT)) self.play(ApplyMethod(author.scale, 1.5)) author.match_color(quote2) self.play(FadeOut(quote), FadeOut(author)) self.wait()
def _main_title(self): paper_name_a = TextMobject( "Simulating human interactions in supermarkets to") paper_name_b = TextMobject( "measure the risk of COVID-19 contagion at scale") author_list_a = TextMobject( "Serge Plata\\quad Sumanas Sarma\\quad Melvin Lancelot") author_list_b = TextMobject( "Kristine Bagrova\\quad David Romano-Critchley") arxiv = TextMobject("arXiv:2006.15213") paper_name_a.shift(UP) paper_name_b.next_to(paper_name_a, DOWN) author_list_a.scale(0.8) author_list_b.scale(0.8) author_list_a.next_to(paper_name_b, DOWN + DOWN) author_list_b.next_to(author_list_a, DOWN) arxiv.scale(0.6) arxiv.next_to(author_list_b, DOWN + DOWN) self.play(FadeIn(paper_name_a), FadeIn(paper_name_b)) self.wait() self.play(FadeIn(author_list_a), FadeIn(author_list_b)) self.play(FadeIn(arxiv)) self.wait(4) self.play(FadeOut(paper_name_a), FadeOut(paper_name_b), FadeOut(author_list_a), FadeOut(author_list_b), ApplyMethod(arxiv.move_to, BOTTOM + (UP * 0.5)))
def get_quote(self, max_width=FRAME_WIDTH - 1): text_mobject_kwargs = { "alignment": "", "arg_separator": self.quote_arg_separator, } if isinstance(self.quote, str): if self.use_quotation_marks: quote = TextMobject("``%s''" % self.quote.strip(), **text_mobject_kwargs) else: quote = TextMobject("%s" % self.quote.strip(), **text_mobject_kwargs) else: if self.use_quotation_marks: words = [self.text_size + " ``"] + list(self.quote) + ["''"] else: words = [self.text_size] + list(self.quote) quote = TextMobject(*words, **text_mobject_kwargs) # TODO, make less hacky if self.quote_arg_separator == " ": quote[0].shift(0.2 * RIGHT) quote[-1].shift(0.2 * LEFT) for term, color in self.highlighted_quote_terms: quote.set_color_by_tex(term, color) quote.to_edge(UP, buff=self.top_buff) if quote.get_width() > max_width: quote.set_width(max_width) return quote
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): number_line = NumberLine(x_min=-2, x_max=2) text_1 = TextMobject("Theorem of") \ .next_to(number_line, DOWN) text_2 = TextMobject("Beethoven") \ .next_to(number_line, DOWN) dashed_line = DashedLine( number_line.get_left(), number_line.get_right(), color=YELLOW, ).set_stroke(width=11) self.add(number_line, text_1) self.play( LaggedStart(*[ ShowCreationThenDestruction(dashed_segment) for dashed_segment in dashed_line ], run_time=5), AnimationGroup(Animation(Mobject(), run_time=2.1), ReplacementTransform(text_1, text_2), lag_ratio=1)) self.wait()
def __init__(self, mobject_or_chars): TextMobject.__init__(self) if mobject_or_chars == None or (isinstance(mobject_or_chars, Mobject) and mobject_or_chars.name == "Mobject"): mobject = Mobject() elif isinstance(mobject_or_chars, (list)): mobject = ImageMobject(mobject_or_chars[0]) self.add(mobject) self = mobject.copy() elif isinstance(mobject_or_chars, Mobject) and mobject_or_chars.name == "ImageMobject": mobject = mobject_or_chars self.add(mobject) self = mobject_or_chars[0].copy() else: if isinstance(mobject_or_chars, str): #mobject =MTex(mobject_or_chars) mobject = TextMobject(mobject_or_chars) elif isinstance(mobject_or_chars, int): mobject = Integer(mobject_or_chars) elif isinstance(mobject_or_chars, float): mobject = DecimalNumber(mobject_or_chars) elif isinstance(mobject_or_chars, (tuple)): mobject = TextMobject(*mobject_or_chars) else: mobject = mobject_or_chars self.become(mobject) self.name = mobject.name self.__class__ = mobject.__class__
def construct(self): line1 = TextMobject(r"The vector $\vec{F}_{net}$ is the net ", "force", " on object of mass ") line1.set_color_by_tex("force", BLUE) line2 = TextMobject("$m$", " and acceleration ", r"$\vec{a}$", ".") line2.set_color_by_tex_to_color_map({"m": YELLOW, "{a}": RED}) sentence = VGroup(line1, line2) sentence.arrange_submobjects(DOWN, buff=MED_LARGE_BUFF) self.play(Write(sentence)) self.wait(3)
def add_labels(self): numeral_labels = VGroup(*[ TextMobject(str(i+1)).next_to(self.get_square("a"+str(i+1)), LEFT) for i in range(8) ]) alphabetical_labels = TextMobject(*[chr(97+i) for i in range(8)]) alphabetical_labels.next_to(self.border, DOWN, buff = 0.15) for i, label in enumerate(alphabetical_labels): label.next_to(self.get_square(chr(97+i)+"1"), DOWN, coor_mask = [1, 0, 0]) self.add(numeral_labels, alphabetical_labels) self.numeral_labels = numeral_labels self.alphabetical_labels = alphabetical_labels
def construct(self): my_first_text = TextMobject("Writing with manim is fun") second_line = TextMobject("and easy to do!") second_line.next_to(my_first_text, DOWN) third_line = TextMobject("for me and you!") third_line.next_to(my_first_text, DOWN) self.add(my_first_text, second_line) self.wait(2) self.play(Transform(second_line, third_line)) self.wait(2) second_line.shift(3 * DOWN) self.play(ApplyMethod(my_first_text.shift, 3 * UP)) self.wait()
def initialize_texts(self): geom_text = TextMobject("一个边长为$n$的正六边形", "和一些边长为1的菱形") eqtri_text = TextMobject("它们都是由若干正三角形组成的") three_types_text = TextMobject("因为朝向不同,菱形被分成三种") try_tiling_text = TextMobject("现在用这些菱形", "镶嵌", "正六边形...") remark = TextMobject("(无间隙且不重叠地覆盖)") claim_text = TextMobject("最终的图案中", "每种菱形的数量一定都是$n^2$") twist_text = TextMobject("改变菱形的摆放方式", "或者改变正六边形的大小", "这个结论依然成立") how_to_prove_text = TextMobject("如何证明?", "") for text in (geom_text, claim_text, twist_text): text.arrange_submobjects(DOWN, aligned_edge=LEFT) try_tiling_text[1].set_color(GREEN) remark.scale(0.5) remark.set_color(GREEN) remark.next_to(try_tiling_text[1], DOWN, buff=0.1) how_to_prove_text.set_color(YELLOW) bg_texts = VGroup( geom_text, eqtri_text, three_types_text, VGroup(try_tiling_text, remark), ) q_texts = VGroup( claim_text, twist_text, ) for texts in (bg_texts, q_texts, how_to_prove_text): texts.arrange_submobjects(DOWN, aligned_edge=LEFT, buff=1) texts.to_corner(LEFT + UP) self.bg_texts = bg_texts self.q_texts = q_texts self.how_to_prove_text = how_to_prove_text
def construct(self): my_first_text = TextMobject("Writing with manim is fun") second_line = TextMobject("and easy to do!") second_line.next_to(my_first_text, DOWN) third_line = TextMobject("for me and you!") third_line.next_to(my_first_text, DOWN) self.play(FadeIn(my_first_text), FadeIn(second_line)) self.wait(2) self.play(Transform(second_line, third_line)) self.wait(2) self.play(ApplyMethod(my_first_text.shift, 3 * UP)) self.play(Rotating(second_line), radians=PI, run_time=2) self.wait()
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 build_text_and_circles(value, location): text_obj = TextMobject(str(value)) text_obj.move_to(location) circle_obj = Circle() circle_obj.surround(text_obj) circle_obj.scale(1.5) return Node(text_obj, circle_obj, value)
def tex(self, latex): eq = TextMobject(latex) anims = [] anims.append(Write(eq)) for mobject in self.mobjects: anims.append(ApplyMethod(mobject.shift, 2 * UP)) self.play(*anims)
def add_size(self, text, scale=1, buff=0.1, **moreargs): linea_referencia = Line(self[0][0].get_start(), self[0][-1].get_end()) texto = TextMobject(text, **moreargs) ancho = texto.get_height() / 2 texto.rotate(linea_referencia.get_angle()) texto.shift(self.direccion * (buff + 1) * ancho) return self.add(texto)
def get_text(self, text, scale=1, buff=0.1, invert_dir=False, invert_texto=False, remove_rot=False, **moreargs): linea_referencia = Line(self[0][0].get_start(), self[0][-1].get_end()) texto = TextMobject(text, **moreargs) ancho = texto.get_height() / 2 if invert_texto: inv = PI else: inv = 0 if remove_rot: texto.scale(scale).move_to(self) else: texto.rotate( linea_referencia.get_angle()).scale(scale).move_to(self) texto.rotate(inv) if invert_dir: inv = -1 else: inv = 1 texto.shift(self.direccion * (buff + 1) * ancho * inv) return texto
def finished(self): sorted_text = TextMobject("Sorted") sorted_text.move_to(2 * UP) self.add(sorted_text) for node in self.nodes: node.circle.set_color(GREEN)
def construct(self): # Generate transformation animations of the twin dragon curve anims = list() fractal = VMobject() fractal.shift(UP) for order in range(-1, self.max_order+1): new_fractal = TwinDragon(order = order) new_fractal.shift(UP) run_time = 0.5 if order >= 0 else 0 anims.append( Transform( fractal, new_fractal, submobject_mode = "all_at_once", run_time = run_time, ) ) fractal = new_fractal # Add the channel name text = TextMobject("Solara570") text.scale(2).to_edge(DOWN, buff = 1.2) # Now sit back and watch self.play( Succession(*anims, rate_func = smooth), Write(text, lag_factor = 2.5, rate_func = squish_rate_func(smooth, 0.1, 0.9)), run_time = 4.5, )
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) numbers = VGroup( *[TextMobject("%s" % i) \ .next_to(number_line.get_tick(i - 2), DOWN) for i in range(1, 5)] ) self.add(number_line) self.play(ShowCreation(triangle)) self.wait(0.3) self.play( ApplyMethod(triangle.shift, RIGHT * 4, rate_func=linear, run_time=4), *[ AnimationGroup(Animation(Mobject(), run_time=i + 1), Write(numbers[i]), lag_ratio=1) for i in range(4) ], ) self.wait()
def add_title(self, title, scale_factor=1.5, animate=False): """ Adds a title, after scaling it, adding a background rectangle, moving it to the top and adding it to foreground_mobjects adding it as a local variable of self. Returns the Scene. Parameters ---------- title (str,TexMobject,TextMobject) What the title should be. scale_factor (int,float=1.5) How much the title should be scaled by. animate (bool=False) Whether or not to animate the addition. Returns ------- LinearTransformationScene The scene with the title added to it. """ if not isinstance(title, Mobject): title = TextMobject(title).scale(scale_factor) title.to_edge(UP) title.add_background_rectangle() if animate: self.play(Write(title)) self.add_foreground_mobject(title) self.title = title return self
def add_label(self): self.id_to_label = [ "0", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og" ] self.label_to_id = {} for i, label in enumerate(self.id_to_label): self.label_to_id[label] = i labels = VGroup() for i in range(0, 119): label = TextMobject(self.id_to_label[i], color=BLACK, background_stroke_width=0) label.scale(0.5).move_to(self[0][i][1].get_center()).set_shade_in_3d(z_index_as_group=True).shift(OUT * 1e-3) labels.add(label) labels[0].set_fill(opacity=0) for i in [43, 61, *list(range(84, 119))]: labels[i].set_color(RED) self.add(labels) return self
def get_probabalistic_message(self): return TextMobject( "New video every", "Sunday", "(with probability 0.3)", tex_to_color_map={"Sunday": YELLOW}, )
def add_title(self, title="Sample space", buff=MED_SMALL_BUFF): # TODO, should this really exist in SampleSpaceScene title_mob = TextMobject(title) if title_mob.get_width() > self.get_width(): title_mob.set_width(self.get_width()) title_mob.next_to(self, UP, buff=buff) self.title = title_mob self.add(title_mob)
def construct(self): dot = Dot() text = TextMobject("Label") \ .next_to(dot, RIGHT, buff=SMALL_BUFF) self.add(dot, text) self.play(dot.shift, UP * 2) self.wait()
def construct(self): theorem_sc = TextMobject("可利颂镶嵌定理") theorem_sc.scale(1.8) theorem_eng = TextMobject("(Calisson Tiling Theorem)") theorem_eng.set_width(theorem_sc.get_width()) theorem = VGroup(theorem_sc, theorem_eng) theorem.arrange_submobjects(DOWN) theorem.to_edge(RIGHT).shift(UP) self.play(FadeIn(theorem), run_time=1) author = TextMobject("@Solara570") author.scale(1.5) support = TextMobject("(Powered by @3Blue1Brown)") support.set_width(author.get_width()) names = VGroup(author, support) names.arrange_submobjects(DOWN) names.to_corner(RIGHT + DOWN) self.play(FadeIn(names), run_time=1) self.wait(3)
def construct(self): eq1 = TextMobject(r"$ \vec{X}_0 \cdot \vec{Y}_1 = 3 $") eq1.shift(2 * UP) eq2 = TexMobject(r"\vec{F}_{net} = \sum_i \vec{F}_i") eq2.shift(2 * DOWN) self.play(Write(eq1)) self.play(Write(eq2)) self.wait()
def add_title(self, title, scale_factor=1.5, animate=False): if not isinstance(title, Mobject): title = TextMobject(title).scale(scale_factor) title.to_edge(UP) title.add_background_rectangle() if animate: self.play(Write(title)) self.add(title) self.title = title return self
def construct(self): if 1 == 1: try: self.add_sound( "sidewayoutput\\basicmanim\\functions001a_01_01_01_01_01.wav", time_offset=19) except: pass self.play(StartScreens01( [], [], [[r"\textbf{\textit{Basic-Manim from }\{Sideway\}}"], [r"\textbf{\textit{Functions}}\\{{Part\ \textspA{I}a}"], [r"\tiny{\textrm{basic-manim.210300151v0\_functions001a}}"], [], [r"\scriptsize{\textbf{Warning:\ The\ content\ may\ contain\ errors,\ mistakes\ and\ inaccuracies.\ Information\ must\ be\ verified\ and\ evaluated\ before\ use.}}"]],)) if 1 == 1: self.grow(r"\titleA{Functions}", shift=[0, 3.6, 0]) rows, cols = (4, 3) x0, y0 = axes_point([1.1, 4.5, cols-1, -4.2], [2.5, -1.8, rows]) txty = [r"ParametricCurve \\\tiny(replacing ParametricFunction)", "ParametricFunction", "FunctionGraph", "FunctionsGraph"] strs = ["\\parbox{25em}{"+txty[i].split(" ", 1)[0]+"("+each+")" for i, each in enumerate([r"\bR{lambda t:[t,t**2,0],\bR{(-1,1,0.01)", r"\bR{lambda t:[t,t**2,0],\bR{t\_min=-1, t\_max=1", r"\bR{lambda t:t**2,\bR{(-1,1,0.01)", r"\bR{'lambda t:t, (-1,0,0.01)',\bR{'lambda t:0, (0,1,0.01)'"])] self.fadein( *[TextMobject(txty[i]).move_to(each) for i, each in enumerate(coord_grid(x0[0:1], y0))], run_time=5) self.grow(*[TextMobject(strs[i]).move_to(each) for i, each in enumerate(coord_grid(x0[1:2], y0))], *[GeomPoint().move_to(each) for i, each in enumerate(coord_grid(x0[2:3], y0))], ) strs = [strs[i].replace("\\bR{", "").replace("\\parbox{25em}{", "").replace( "\\", "")+".shift(["+','.join(map(str, each))+"])" for i, each in enumerate(coord_grid(x0[2:3], y0))] exec("self.create(" + ','.join(strs) + ", run_time=48, lag_ratio=0)") self.fadeout() if 1 == 1: self.play(EndScreen01()) self.wait(5)
def countdown(self): countdown_texts = VGroup( *[TextMobject(str(k)) for k in range(5, -1, -1)]) countdown_texts.set_color(YELLOW) for text in countdown_texts: text.scale(1.5) text.next_to(self.how_to_prove_text[0], RIGHT, buff=3) self.add(text) self.wait() self.remove(text)
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)