# -*- coding: utf-8 -*- import sys, os, math sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from manim import * from tiktok import * BAR_X0, BAR_MAX = -2.35, 3.3 # bar proportional to the years class RuleOf72(TikTok): NAME = "regla72" def row(self, rate, years, y, color, maxa=12.0): t = Text(f"{rate}%", font=FONT, font_size=46, weight=BOLD, color=color) t.move_to([-3.95, y, 0], LEFT) w = max(years / maxa * BAR_MAX, 0.05) bar = RoundedRectangle(corner_radius=0.1, width=w, height=0.46, stroke_width=0, fill_color=color, fill_opacity=1) bar.move_to([BAR_X0, y, 0], LEFT) lab = Text(f"{years:g} años".replace(".", ","), font=FONT, font_size=40, weight=BOLD, color=WHITE) lab.next_to(bar, RIGHT, buff=0.25) return VGroup(t, bar, lab) def construct(self): self.prepare() chip = self.chip("Finanzas en 40 segundos", C_GREEN) with self.beat(0) as b: q = VGroup( self.fit(Text("¿cuánto tarda tu plata", font=FONT, font_size=52, weight=BOLD, color=WHITE), 8.2), self.fit(Text("en duplicarse?", font=FONT, font_size=52, weight=BOLD, color=AMBER), 8.2), ).arrange(DOWN, buff=0.3).move_to(UP * 3.4) b.play(FadeIn(chip, shift=DOWN * 0.3), run_time=0.45) b.play(FadeIn(q[0], shift=UP * 0.15), run_time=0.6) b.play(Write(q[1]), run_time=0.8) with self.beat(1) as b: name = self.fit(Text("LA REGLA DEL 72", font=FONT, font_size=66, weight=BOLD, color=C_GREEN), 8.2).move_to(UP * 1.4) b.play(FadeIn(name, scale=0.7), run_time=0.8) b.play(Flash(name, color=C_GREEN, line_length=0.6, num_lines=20, flash_radius=2.6), run_time=0.7) with self.beat(2) as b: f = MathTex(r"\frac{72}{\text{tasa anual}} = \text{años}", color=WHITE).scale(1.5).move_to(DOWN * 0.6) f[0][0:2].set_color(C_GREEN) b.play(FadeOut(q), name.animate.scale(0.62).move_to(UP * 5.35), run_time=0.6) b.play(Write(f), run_time=1.1) rows = [] for i, (rate, years, col, yy) in enumerate( [(6, 12, AMBER, -2.6), (9, 8, C_SKY, -3.7), (12, 6, C_GREEN, -4.8)]): rows.append(self.row(rate, years, yy, col)) with self.beat(3) as b: b.play(f.animate.scale(0.72).move_to(UP * 3.6), run_time=0.5) for r in rows: r.shift(UP * 4.3) count = MathTex(r"72 \div 6 = 12", color=AMBER).scale(1.35).move_to(UP * 1.75) b.play(Write(count), run_time=0.8) b.play(FadeIn(rows[0][0]), GrowFromEdge(rows[0][1], LEFT), FadeIn(rows[0][2]), run_time=0.8) with self.beat(4) as b: c2 = MathTex(r"72 \div 9 = 8", color=C_SKY).scale(1.35).move_to(UP * 1.75) b.play(Transform(count, c2), run_time=0.6) b.play(FadeIn(rows[1][0]), GrowFromEdge(rows[1][1], LEFT), FadeIn(rows[1][2]), run_time=0.8) with self.beat(5) as b: c3 = MathTex(r"72 \div 12 = 6", color=C_GREEN).scale(1.35).move_to(UP * 1.75) b.play(Transform(count, c3), run_time=0.6) b.play(FadeIn(rows[2][0]), GrowFromEdge(rows[2][1], LEFT), FadeIn(rows[2][2]), run_time=0.8) tabla = VGroup(*rows) with self.beat(6) as b: inv_m = self.fit(Text("y también al revés", font=FONT, font_size=50, weight=BOLD, color=C_PINK), 8.0).move_to(DOWN * 1.1) b.play(FadeOut(count), run_time=0.3) b.play(FadeIn(inv_m, shift=UP * 0.15), run_time=0.7) with self.beat(7) as b: b.play(FadeOut(VGroup(tabla, inv_m)), run_time=0.45) infl = VGroup( self.fit(Text("30% de inflación anual", font=FONT, font_size=48, weight=BOLD, color=C_PINK), 8.2), self.fit(Text("tu plata vale la mitad", font=FONT, font_size=44, weight=BOLD, color=WHITE), 8.2), self.fit(Text("en 2,4 años", font=FONT, font_size=56, weight=BOLD, color=C_PINK), 8.2), ).arrange(DOWN, buff=0.35).move_to(UP * 0.35) b.play(FadeIn(infl[0], shift=UP * 0.15), run_time=0.6) b.play(FadeIn(infl[1], shift=UP * 0.15), run_time=0.6) b.play(FadeIn(infl[2], scale=0.7), run_time=0.7) with self.beat(8) as b: c4 = MathTex(r"72 \div 30 = 2{,}4", color=C_PINK).scale(1.45).move_to(DOWN * 2.5) b.play(Write(c4), run_time=1.0) with self.beat(9) as b: b.play(FadeOut(VGroup(infl, c4)), run_time=0.4) cmp = VGroup( Text("exacto: 11,9 años", font=FONT, font_size=42, color=C_GRAY), Text("regla: 12 años", font=FONT, font_size=42, weight=BOLD, color=C_GREEN), ).arrange(DOWN, buff=0.3, aligned_edge=LEFT).move_to(UP * 0.4) ok = self.fit(Text("es aproximada, pero se clava", font=FONT, font_size=42, weight=BOLD, color=WHITE), 8.2).next_to(cmp, DOWN, buff=0.6) b.play(FadeIn(cmp[0]), run_time=0.5) b.play(FadeIn(cmp[1]), run_time=0.5) b.play(FadeIn(ok, shift=UP * 0.15), run_time=0.6) with self.beat(10) as b: b.play(FadeOut(VGroup(cmp, ok)), run_time=0.35) count_txt = self.fit(Text("guardate esta cuenta", font=FONT, font_size=60, weight=BOLD, color=AMBER), 8.0).move_to(UP * 0.4) b.play(Write(count_txt), run_time=0.9) b.play(Circumscribe(count_txt, color=AMBER, buff=0.3, stroke_width=7), run_time=1.0) self.finish()