aboutsummaryrefslogtreecommitdiffstats
path: root/scenes/v12_simpson.py
diff options
context:
space:
mode:
Diffstat (limited to 'scenes/v12_simpson.py')
-rw-r--r--scenes/v12_simpson.py144
1 files changed, 72 insertions, 72 deletions
diff --git a/scenes/v12_simpson.py b/scenes/v12_simpson.py
index 6092924..885d9e7 100644
--- a/scenes/v12_simpson.py
+++ b/scenes/v12_simpson.py
@@ -4,23 +4,23 @@ 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))
+# real data (Charig et al., 1986): treatment A vs B for kidney stones
+LEVER = (("A", 81, 87), ("B", 234, 270))
+GRAV_FIELD = (("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
+BARW = 4.05 # bar width at 100%
+XL = -1.55 # left edge of the bars
class Simpson(TikTok):
NAME = "simpson"
- def barra(self, letra, num, den, y, gana):
+ def bar_m(self, letter, num, den, y, wins):
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)
+ col = C_GREEN if wins else C_GRAY
+ lab = Text(letter, font=FONT, font_size=50, weight=BOLD,
+ color=C_SKY if letter == "A" else C_PINK)
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)
@@ -32,139 +32,139 @@ class Simpson(TikTok):
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)
+ def block_obj(self, title, dataset, ytop, winner):
+ t = Text(title, 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)
+ b1 = self.bar_m(dataset[0][0], dataset[0][1], dataset[0][2], ytop - 0.85,
+ dataset[0][0] == winner)
+ b2 = self.bar_m(dataset[1][0], dataset[1][1], dataset[1][2], ytop - 1.70,
+ dataset[1][0] == winner)
return VGroup(t, b1, b2)
def construct(self):
self.prepare()
- chip = self.chip("Estadística que engaña", ROSA)
+ chip = self.chip("Estadística que engaña", C_PINK)
with self.beat(0) as b:
b.play(FadeIn(chip, shift=DOWN * 0.3), run_time=0.45)
- cab = VGroup(
+ header = 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),
+ Text("A", font=FONT, font_size=90, weight=BOLD, color=C_SKY),
+ Text("vs", font=FONT, font_size=44, color=C_GRAY),
+ Text("B", font=FONT, font_size=90, weight=BOLD, color=C_PINK),
).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)
+ b.play(FadeIn(header[0], shift=UP * 0.15), run_time=0.6)
+ b.play(FadeIn(header[1][0], scale=0.6), run_time=0.35)
+ b.play(FadeIn(header[1][1]), run_time=0.2)
+ b.play(FadeIn(header[1][2], scale=0.6), run_time=0.35)
- lev = self.bloque("casos LEVES", LEV, 2.55, "A")
+ lever = self.block_obj("casos LEVES", LEVER, 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(header.animate.scale(0.5).move_to(UP * 5.4), run_time=0.5)
+ b.play(FadeIn(lever[0], shift=RIGHT * 0.2), run_time=0.4)
+ for bb in (lever[1], lever[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")
+ grav = self.block_obj("casos GRAVES", GRAV_FIELD, -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(grav[0], shift=RIGHT * 0.2), run_time=0.4)
+ for bb in (grav[1], grav[2]):
b.play(FadeIn(bb[0]), FadeIn(bb[1]),
GrowFromEdge(bb[2], LEFT), FadeIn(bb[3]), run_time=0.55)
- def tilde(col=VERDE):
+ def tilde(col=C_GREEN):
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)
+ tick[0].next_to(lever[1][3], RIGHT, buff=0.25)
+ tick[1].next_to(grav[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)
+ pre_frames = self.fit(Text("A gana 2 de 2", font=FONT, font_size=48,
+ weight=BOLD, color=C_SKY), 8.0).move_to(DOWN * 2.80)
+ b.play(FadeIn(pre_frames, shift=UP * 0.15), run_time=0.5)
- tot = self.bloque("TODOS juntos", TOT, 2.55, "B")
+ tot = self.block_obj("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(FadeOut(VGroup(lever, grav, tick, pre_frames)), 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),
+ b.play(Circumscribe(tot[2], color=C_GREEN, 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)
+ color=C_PINK), 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(
+ b.play(FadeOut(VGroup(tot, g, ne, header)), run_time=0.4)
+ nm_key = VGroup(
self.fit(Text("PARADOJA", font=FONT, font_size=72, weight=BOLD,
- color=AMBAR), 8.2),
+ color=AMBER), 8.2),
self.fit(Text("DE SIMPSON", font=FONT, font_size=72, weight=BOLD,
- color=AMBAR), 8.2),
+ color=AMBER), 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,
+ b.play(FadeIn(nm_key, scale=0.75), run_time=0.8)
+ b.play(Flash(nm_key, color=AMBER, 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)
+ def split_up(letter, col, minor, graves, y):
+ lab = Text(letter, font=FONT, font_size=50, weight=BOLD, color=col)
lab.move_to([-3.65, y, 0])
- n = leves + graves
- wl = leves / n * BARW
+ n = minor + graves
+ wl = minor / 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)
+ fill_color=C_GREEN, 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)
+ fill_color=C_PINK, fill_opacity=1).next_to(a, RIGHT, buff=0)
+ nl = Text(str(minor), 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),
+ legend = VGroup(
+ VGroup(Square(0.34, stroke_width=0, fill_color=C_GREEN, 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),
+ VGroup(Square(0.34, stroke_width=0, fill_color=C_PINK, 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)
+ rA = split_up("A", C_SKY, 87, 263, -0.65)
+ rB = split_up("B", C_PINK, 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(nm_key.animate.scale(0.55).move_to(UP * 5.3), run_time=0.5)
+ b.play(FadeIn(legend), 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)
+ b.play(Circumscribe(rA[2], color=C_PINK, 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)
+ b.play(Circumscribe(rB[1], color=C_GREEN, 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)
+ b.play(FadeOut(VGroup(rA, rB, legend)), 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),
+ weight=BOLD, color=AMBER), 8.2),
self.fit(Text("(datos de un estudio real)", font=FONT, font_size=34,
- color=GRIS), 8.2),
+ color=C_GRAY), 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)
@@ -172,17 +172,17 @@ class Simpson(TikTok):
with self.beat(10) as b:
b.play(FadeOut(t), run_time=0.35)
- cta = VGroup(
+ count_txt = 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),
+ weight=BOLD, color=AMBER), 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)
+ b.play(FadeIn(count_txt[0], shift=UP * 0.12), run_time=0.45)
+ b.play(FadeIn(count_txt[1], shift=UP * 0.12), run_time=0.45)
+ b.play(Write(count_txt[2]), run_time=0.8)
+ b.play(Circumscribe(count_txt[2], color=AMBER, buff=0.25, stroke_width=6), run_time=0.8)
self.finish()