diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2026-09-26 20:21:47 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2026-09-26 20:21:47 -0300 |
| commit | 59355909f2de9236af8168a26c70bcf6caa3b285 (patch) | |
| tree | 686186e2086f81aa22ad25e78eb29fca3cbadc9a /scenes/v12_simpson.py | |
| download | 100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.tar.gz 100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.zip | |
Import video pipeline as it was
Diffstat (limited to 'scenes/v12_simpson.py')
| -rw-r--r-- | scenes/v12_simpson.py | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/scenes/v12_simpson.py b/scenes/v12_simpson.py new file mode 100644 index 0000000..6092924 --- /dev/null +++ b/scenes/v12_simpson.py @@ -0,0 +1,188 @@ +# -*- coding: utf-8 -*- +import sys, os +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from manim import * +from tiktok import * + +# datos reales (Charig et al., 1986): tratamiento A vs B para calculos renales +LEV = (("A", 81, 87), ("B", 234, 270)) +GRA = (("A", 192, 263), ("B", 55, 80)) +TOT = (("A", 81 + 192, 87 + 263), ("B", 234 + 55, 270 + 80)) + +BARW = 4.05 # ancho de barra al 100% +XL = -1.55 # borde izquierdo de las barras + + +class Simpson(TikTok): + NAME = "simpson" + + def barra(self, letra, num, den, y, gana): + pct = 100.0 * num / den + col = VERDE if gana else GRIS + lab = Text(letra, font=FONT, font_size=50, weight=BOLD, + color=CELESTE if letra == "A" else ROSA) + lab.move_to([-3.65, y, 0]) + track = RoundedRectangle(corner_radius=0.12, width=BARW, height=0.62, + stroke_width=0, fill_color="#1B2233", fill_opacity=1) + track.move_to([XL, y, 0], LEFT) + fill = RoundedRectangle(corner_radius=0.12, width=max(pct / 100 * BARW, 0.2), + height=0.62, stroke_width=0, fill_color=col, fill_opacity=1) + fill.move_to([XL, y, 0], LEFT) + val = Text(f"{pct:.0f}%", font=FONT, font_size=42, weight=BOLD, color=col) + val.next_to(track, RIGHT, buff=0.22) + return VGroup(lab, track, fill, val) + + def bloque(self, titulo, datos, ytop, ganador): + t = Text(titulo, font=FONT, font_size=40, weight=BOLD, color=WHITE) + t.move_to([-3.85, ytop, 0], LEFT) + b1 = self.barra(datos[0][0], datos[0][1], datos[0][2], ytop - 0.85, + datos[0][0] == ganador) + b2 = self.barra(datos[1][0], datos[1][1], datos[1][2], ytop - 1.70, + datos[1][0] == ganador) + return VGroup(t, b1, b2) + + def construct(self): + self.prepare() + chip = self.chip("Estadística que engaña", ROSA) + + with self.beat(0) as b: + b.play(FadeIn(chip, shift=DOWN * 0.3), run_time=0.45) + cab = VGroup( + self.fit(Text("dos tratamientos", font=FONT, font_size=52, + weight=BOLD, color=WHITE), 8.2), + VGroup( + Text("A", font=FONT, font_size=90, weight=BOLD, color=CELESTE), + Text("vs", font=FONT, font_size=44, color=GRIS), + Text("B", font=FONT, font_size=90, weight=BOLD, color=ROSA), + ).arrange(RIGHT, buff=0.7), + ).arrange(DOWN, buff=0.45).move_to(UP * 3.0) + b.play(FadeIn(cab[0], shift=UP * 0.15), run_time=0.6) + b.play(FadeIn(cab[1][0], scale=0.6), run_time=0.35) + b.play(FadeIn(cab[1][1]), run_time=0.2) + b.play(FadeIn(cab[1][2], scale=0.6), run_time=0.35) + + lev = self.bloque("casos LEVES", LEV, 2.55, "A") + with self.beat(1) as b: + b.play(cab.animate.scale(0.5).move_to(UP * 5.4), run_time=0.5) + b.play(FadeIn(lev[0], shift=RIGHT * 0.2), run_time=0.4) + for bb in (lev[1], lev[2]): + b.play(FadeIn(bb[0]), FadeIn(bb[1]), + GrowFromEdge(bb[2], LEFT), FadeIn(bb[3]), run_time=0.55) + + gra = self.bloque("casos GRAVES", GRA, -0.35, "A") + with self.beat(2) as b: + b.play(FadeIn(gra[0], shift=RIGHT * 0.2), run_time=0.4) + for bb in (gra[1], gra[2]): + b.play(FadeIn(bb[0]), FadeIn(bb[1]), + GrowFromEdge(bb[2], LEFT), FadeIn(bb[3]), run_time=0.55) + + def tilde(col=VERDE): + m = VMobject(stroke_color=col, stroke_width=9) + m.set_points_as_corners([[-0.20, 0.02, 0], [-0.05, -0.18, 0], [0.24, 0.26, 0]]) + return m + + with self.beat(3) as b: + tick = VGroup(*[tilde() for _ in range(2)]) + tick[0].next_to(lev[1][3], RIGHT, buff=0.25) + tick[1].next_to(gra[1][3], RIGHT, buff=0.25) + b.play(FadeIn(tick[0], scale=0.5), run_time=0.4) + b.play(FadeIn(tick[1], scale=0.5), run_time=0.4) + pre = self.fit(Text("A gana 2 de 2", font=FONT, font_size=48, + weight=BOLD, color=CELESTE), 8.0).move_to(DOWN * 2.80) + b.play(FadeIn(pre, shift=UP * 0.15), run_time=0.5) + + tot = self.bloque("TODOS juntos", TOT, 2.55, "B") + with self.beat(4) as b: + b.play(FadeOut(VGroup(lev, gra, tick, pre)), run_time=0.45) + b.play(FadeIn(tot[0], shift=RIGHT * 0.2), run_time=0.4) + for bb in (tot[1], tot[2]): + b.play(FadeIn(bb[0]), FadeIn(bb[1]), + GrowFromEdge(bb[2], LEFT), FadeIn(bb[3]), run_time=0.6) + + with self.beat(5) as b: + b.play(Circumscribe(tot[2], color=VERDE, buff=0.18, stroke_width=6), + run_time=0.8) + g = self.fit(Text("gana B", font=FONT, font_size=70, weight=BOLD, + color=ROSA), 8.0).move_to(DOWN * 0.75) + ne = self.fit(Text("y no hay ningún error", font=FONT, font_size=44, + weight=BOLD, color=WHITE), 8.0).next_to(g, DOWN, buff=0.4) + b.play(FadeIn(g, scale=0.7), run_time=0.6) + b.play(FadeIn(ne, shift=UP * 0.15), run_time=0.5) + + with self.beat(6) as b: + b.play(FadeOut(VGroup(tot, g, ne, cab)), run_time=0.4) + nom = VGroup( + self.fit(Text("PARADOJA", font=FONT, font_size=72, weight=BOLD, + color=AMBAR), 8.2), + self.fit(Text("DE SIMPSON", font=FONT, font_size=72, weight=BOLD, + color=AMBAR), 8.2), + ).arrange(DOWN, buff=0.2).move_to(UP * 2.6) + b.play(FadeIn(nom, scale=0.75), run_time=0.8) + b.play(Flash(nom, color=AMBAR, line_length=0.6, num_lines=20, + flash_radius=3.0), run_time=0.7) + + def reparto(letra, col, leves, graves, y): + lab = Text(letra, font=FONT, font_size=50, weight=BOLD, color=col) + lab.move_to([-3.65, y, 0]) + n = leves + graves + wl = leves / n * BARW + a = Rectangle(width=max(wl, 0.05), height=0.7, stroke_width=0, + fill_color=VERDE, fill_opacity=1).move_to([XL, y, 0], LEFT) + c = Rectangle(width=max(BARW - wl, 0.05), height=0.7, stroke_width=0, + fill_color=ROSA, fill_opacity=1).next_to(a, RIGHT, buff=0) + nl = Text(str(leves), font=FONT, font_size=30, weight=BOLD, color="#0B0F1A").move_to(a) + ng = Text(str(graves), font=FONT, font_size=30, weight=BOLD, color="#0B0F1A").move_to(c) + return VGroup(lab, a, c, nl, ng) + + leyenda = VGroup( + VGroup(Square(0.34, stroke_width=0, fill_color=VERDE, fill_opacity=1), + Text("leves", font=FONT, font_size=32, color=WHITE)).arrange(RIGHT, buff=0.18), + VGroup(Square(0.34, stroke_width=0, fill_color=ROSA, fill_opacity=1), + Text("graves", font=FONT, font_size=32, color=WHITE)).arrange(RIGHT, buff=0.18), + ).arrange(RIGHT, buff=0.8).move_to(UP * 0.55) + + rA = reparto("A", CELESTE, 87, 263, -0.65) + rB = reparto("B", ROSA, 270, 80, -1.75) + + with self.beat(7) as b: + b.play(nom.animate.scale(0.55).move_to(UP * 5.3), run_time=0.5) + b.play(FadeIn(leyenda), run_time=0.4) + b.play(FadeIn(rA[0]), GrowFromEdge(VGroup(rA[1], rA[2]), LEFT), + FadeIn(VGroup(rA[3], rA[4])), run_time=0.8) + b.play(Circumscribe(rA[2], color=ROSA, buff=0.1, stroke_width=5), run_time=0.7) + + with self.beat(8) as b: + b.play(FadeIn(rB[0]), GrowFromEdge(VGroup(rB[1], rB[2]), LEFT), + FadeIn(VGroup(rB[3], rB[4])), run_time=0.8) + b.play(Circumscribe(rB[1], color=VERDE, buff=0.1, stroke_width=5), run_time=0.7) + + with self.beat(9) as b: + b.play(FadeOut(VGroup(rA, rB, leyenda)), run_time=0.4) + t = VGroup( + self.fit(Text("el promedio mezcla", font=FONT, font_size=48, + weight=BOLD, color=WHITE), 8.2), + self.fit(Text("dos grupos distintos", font=FONT, font_size=48, + weight=BOLD, color=AMBAR), 8.2), + self.fit(Text("(datos de un estudio real)", font=FONT, font_size=34, + color=GRIS), 8.2), + ).arrange(DOWN, buff=0.35).move_to(UP * 1.6) + b.play(FadeIn(t[0], shift=UP * 0.15), run_time=0.55) + b.play(FadeIn(t[1], shift=UP * 0.15), run_time=0.55) + b.play(FadeIn(t[2]), run_time=0.45) + + with self.beat(10) as b: + b.play(FadeOut(t), run_time=0.35) + cta = VGroup( + self.fit(Text("cuando te muestren", font=FONT, font_size=44, + weight=BOLD, color=WHITE), 8.0), + self.fit(Text("un promedio, preguntá:", font=FONT, font_size=44, + weight=BOLD, color=WHITE), 8.0), + self.fit(Text("¿de quiénes?", font=FONT, font_size=64, + weight=BOLD, color=AMBAR), 8.0), + ).arrange(DOWN, buff=0.3).move_to(UP * 1.4) + b.play(FadeIn(cta[0], shift=UP * 0.12), run_time=0.45) + b.play(FadeIn(cta[1], shift=UP * 0.12), run_time=0.45) + b.play(Write(cta[2]), run_time=0.8) + b.play(Circumscribe(cta[2], color=AMBAR, buff=0.25, stroke_width=6), run_time=0.8) + + self.finish() |