# -*- coding: utf-8 -*- import sys, os, math sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from manim import * from tiktok import * Y0, Y1 = -3.25, 4.20 # ends of the log axis L0, L1 = -1.0, 11.8 # log10 of the thickness in mm BAR_X, BAR_W = -3.15, 1.0 MOON_MM = 3.844e11 def ypos(mm): L = max(min(math.log10(mm), L1), L0) return Y0 + (L - L0) / (L1 - L0) * (Y1 - Y0) def thickness(n): return 0.1 * (2 ** n) def human(mm): if mm < 10: return f"{mm:.1f} mm".replace(".", ",") if mm < 1e4: return f"{mm/10:.0f} cm" if mm < 1e7: return f"{mm/1000:,.0f} m".replace(",", ".") return f"{mm/1e6:,.0f} km".replace(",", ".") class Moon(TikTok): NAME = "luna" def moon(self, r=0.62): m = Circle(radius=r, stroke_width=0, fill_color="#D9DEE8", fill_opacity=1) cr = VGroup( Dot(m.get_center() + LEFT * 0.2 * r + UP * 0.3 * r, radius=0.16 * r, color="#AEB6C6"), Dot(m.get_center() + RIGHT * 0.35 * r + DOWN * 0.1 * r, radius=0.11 * r, color="#AEB6C6"), Dot(m.get_center() + LEFT * 0.1 * r + DOWN * 0.42 * r, radius=0.09 * r, color="#AEB6C6"), ) return VGroup(m, cr) def construct(self): self.prepare() chip = self.chip("Crecimiento exponencial", C_SKY) # ---------- hook ---------- with self.beat(0) as b: sheet = Rectangle(width=1.9, height=2.5, stroke_color="#C9D2E3", stroke_width=5, fill_color="#1A2440", fill_opacity=1).move_to(LEFT * 2.3 + UP * 2.6) fold = Line(sheet.get_corner(UL) + RIGHT * 0.55, sheet.get_corner(DL) + RIGHT * 0.55, stroke_width=3, color="#5E6B87") moon_m = self.moon(0.95).move_to(RIGHT * 2.4 + UP * 2.6) ar = Arrow(sheet.get_right() + RIGHT * 0.15, moon_m.get_left() + LEFT * 0.15, buff=0, color=AMBER, stroke_width=9) tag = self.fit(Text("42 dobleces", font=FONT, font_size=46, weight=BOLD, color=AMBER), 7.5).next_to(ar, UP, buff=0.3) b.play(FadeIn(chip, shift=DOWN * 0.3), run_time=0.45) b.play(FadeIn(sheet), Create(fold), run_time=0.5) b.play(GrowArrow(ar), FadeIn(tag), run_time=0.6) b.play(FadeIn(moon_m, scale=0.6), run_time=0.6) hook = VGroup(sheet, fold, moon_m, ar, tag) # ---------- the axis -------- axis = Line([BAR_X, Y0, 0], [BAR_X, Y1 + 0.3, 0], stroke_width=5, color="#3A4766") base = Line([BAR_X - 0.75, Y0, 0], [4.2, Y0, 0], stroke_width=5, color="#3A4766") milestones = [(1e2, "10 cm"), (1e5, "100 m"), (1e8, "100 km")] marks = VGroup() for mm, txt in milestones: y = ypos(mm) ln = DashedLine([BAR_X - 0.5, y, 0], [3.9, y, 0], stroke_width=3, color="#33405C", dash_length=0.12) lb = Text(txt, font=FONT, font_size=30, color=C_GRAY) lb.next_to(ln, UP, buff=0.08).align_to(ln, RIGHT) marks.add(VGroup(ln, lb)) ym = ypos(MOON_MM) moon_line = DashedLine([BAR_X - 0.5, ym, 0], [3.4, ym, 0], stroke_width=4, color="#D9DEE8", dash_length=0.14) moon_ic = self.moon(0.42).move_to([3.85, ym, 0]) moon_lb = Text("LUNA 384.000 km", font=FONT, font_size=30, weight=BOLD, color="#D9DEE8") moon_lb.next_to(moon_line, UP, buff=0.1).align_to(moon_line, RIGHT).shift(LEFT * 0.1) readout = VGroup( Text("0", font=FONT, font_size=68, weight=BOLD, color=AMBER), Text("dobleces", font=FONT, font_size=28, color=C_GRAY), Text("0,1 mm", font=FONT, font_size=44, weight=BOLD, color=WHITE), ) readout[0:2].arrange(RIGHT, buff=0.25, aligned_edge=DOWN) readout.arrange(RIGHT, buff=0.5, aligned_edge=DOWN).move_to(UP * 5.6) bar = Rectangle(width=BAR_W, height=0.02, stroke_width=0, fill_color=AMBER, fill_opacity=1) bar.move_to([BAR_X + BAR_W / 2 + 0.06, Y0, 0], DOWN + LEFT) with self.beat(1) as b: b.play(FadeOut(hook), run_time=0.4) b.play(Create(axis), Create(base), run_time=0.5) b.play(LaggedStart(*[FadeIn(m) for m in marks], lag_ratio=0.2), run_time=0.8) b.play(Create(moon_line), FadeIn(moon_ic), FadeIn(moon_lb), run_time=0.6) state = {"n": 0} def goto(bt, n, rt=0.9, extra=None): mm = thickness(n) h = max(ypos(mm) - Y0, 0.02) new_bar = bar.copy().stretch_to_fit_height(h).move_to( [BAR_X + BAR_W / 2 + 0.06, Y0, 0], DOWN + LEFT) nr = VGroup( Text(str(n), font=FONT, font_size=68, weight=BOLD, color=AMBER), Text("dobleces" if n != 1 else "doblez", font=FONT, font_size=28, color=C_GRAY), Text(human(mm), font=FONT, font_size=44, weight=BOLD, color=WHITE), ) nr[0:2].arrange(RIGHT, buff=0.25, aligned_edge=DOWN) nr.arrange(RIGHT, buff=0.5, aligned_edge=DOWN).move_to(UP * 5.6) self.fit(nr, 8.2) anims = [Transform(bar, new_bar), Transform(readout, nr)] if extra: anims += extra bt.play(*anims, run_time=rt) state["n"] = n with self.beat(2) as b: b.play(FadeIn(readout), FadeIn(bar), run_time=0.5) b.play(Indicate(readout[2], color=AMBER, scale_factor=1.3), run_time=0.7) with self.beat(3) as b: goto(b, 1, 0.7) goto(b, 2, 0.7) with self.beat(4) as b: goto(b, 10, 1.1, [Flash(marks[0][1], color=AMBER, line_length=0.3, num_lines=12, flash_radius=0.8)]) with self.beat(5) as b: goto(b, 20, 1.1, [Flash(marks[1][1], color=AMBER, line_length=0.3, num_lines=12, flash_radius=0.8)]) with self.beat(6) as b: goto(b, 30, 1.1, [Flash(marks[2][1], color=AMBER, line_length=0.3, num_lines=12, flash_radius=0.8)]) atm = Text("fuera de la atmósfera", font=FONT, font_size=32, weight=BOLD, color=C_SKY).move_to([0.9, ypos(1e8) - 0.6, 0]) b.play(FadeIn(atm, shift=UP * 0.1), run_time=0.5) with self.beat(7) as b: b.play(FadeOut(atm), run_time=0.25) goto(b, 40, 1.2) with self.beat(8) as b: goto(b, 42, 1.3) b.play(Flash(moon_ic, color="#D9DEE8", line_length=0.55, num_lines=18, flash_radius=1.1), run_time=0.8) with self.beat(9) as b: over = Text("te pasaste de largo", font=FONT, font_size=44, weight=BOLD, color=C_GREEN) over.move_to([0.75, ym - 0.95, 0]) self.fit(over, 5.6) b.play(FadeIn(over, shift=UP * 0.15), run_time=0.6) b.play(Circumscribe(over, color=C_GREEN, buff=0.22, stroke_width=6), run_time=0.9) with self.beat(10) as b: b.play(FadeOut(VGroup(axis, base, marks, moon_line, moon_ic, moon_lb, bar, over, readout)), run_time=0.6) t1 = self.fit(Text("crecimiento", font=FONT, font_size=74, weight=BOLD, color=WHITE), 8.0) t2 = self.fit(Text("EXPONENCIAL", font=FONT, font_size=90, weight=BOLD, color=AMBER), 8.2) g = VGroup(t1, t2).arrange(DOWN, buff=0.3).move_to(UP * 1.6) t3 = self.fit(Text("por eso nadie lo ve venir", font=FONT, font_size=40, color=C_GRAY), 7.6).next_to(g, DOWN, buff=0.7) b.play(FadeIn(t1, shift=UP * 0.2), run_time=0.5) b.play(FadeIn(t2, scale=0.7), run_time=0.6) b.play(FadeIn(t3), run_time=0.5) self.finish()