aboutsummaryrefslogtreecommitdiffstats
path: root/scenes/v18_dados.py
diff options
context:
space:
mode:
Diffstat (limited to 'scenes/v18_dados.py')
-rw-r--r--scenes/v18_dados.py189
1 files changed, 189 insertions, 0 deletions
diff --git a/scenes/v18_dados.py b/scenes/v18_dados.py
new file mode 100644
index 0000000..f0c2940
--- /dev/null
+++ b/scenes/v18_dados.py
@@ -0,0 +1,189 @@
+# -*- coding: utf-8 -*-
+"""Dados no transitivos: A gana a B, B gana a C y C gana a A, siempre 5 de 9."""
+import sys, os
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from manim import *
+from tiktok import *
+
+ROJO = ROSA
+CARAS = {"rojo": [2, 4, 9], "celeste": [1, 6, 8], "verde": [3, 5, 7]}
+COL = {"rojo": ROJO, "celeste": CELESTE, "verde": VERDE}
+CELL = 1.30
+
+
+def dado(nombre, s=0.62):
+ vals = CARAS[nombre] * 2
+ col = COL[nombre]
+ caras = VGroup()
+ for v in vals:
+ f = RoundedRectangle(corner_radius=0.11, width=s, height=s, stroke_width=3,
+ stroke_color=col, fill_color="#121C33", fill_opacity=1)
+ caras.add(VGroup(f, Text(str(v), font=FONT, font_size=32, weight=BOLD,
+ color=col).move_to(f)))
+ caras.arrange_in_grid(rows=2, cols=3, buff=0.08)
+ rot = Text(nombre, font=FONT, font_size=30, weight=BOLD, color=col)
+ rot.next_to(caras, DOWN, buff=0.18)
+ return VGroup(caras, rot)
+
+
+def duelo(na, nb, centro):
+ """Tabla 3x3 con los nueve duelos. Cada celda pintada del que gana."""
+ av, bv = CARAS[na], CARAS[nb]
+ ca, cb = COL[na], COL[nb]
+ celdas, gana = VGroup(), 0
+ for i, a in enumerate(av):
+ for j, bq in enumerate(bv):
+ ok = a > bq
+ gana += ok
+ r = RoundedRectangle(corner_radius=0.1, width=CELL, height=CELL, stroke_width=4,
+ stroke_color="#0B0F1A", fill_color=ca if ok else cb,
+ fill_opacity=0.92)
+ t = Text(str(max(a, bq)), font=FONT, font_size=42, weight=BOLD, color="#0B0F1A")
+ c = VGroup(r, t.move_to(r))
+ c.move_to(centro + np.array([(j - 1) * (CELL + 0.07),
+ -(i - 1) * (CELL + 0.07), 0.0]))
+ celdas.add(c)
+ d = CELL + 0.07
+ fuera = d + CELL / 2 + 0.36 # el rotulo va por fuera de la tabla
+ cab = VGroup(*[Text(str(v), font=FONT, font_size=38, weight=BOLD, color=cb)
+ .move_to(centro + np.array([(j - 1) * d, fuera, 0.0]))
+ for j, v in enumerate(bv)])
+ lat = VGroup(*[Text(str(v), font=FONT, font_size=38, weight=BOLD, color=ca)
+ .move_to(centro + np.array([-fuera, -(i - 1) * d, 0.0]))
+ for i, v in enumerate(av)])
+ return celdas, cab, lat, gana
+
+
+class Dados(TikTok):
+ NAME = "dados"
+
+ def construct(self):
+ self.prepare()
+ chip = self.chip("Intuición rota", ROJO)
+
+ dds = VGroup(*[dado(n) for n in ("rojo", "celeste", "verde")])
+ dds.arrange(RIGHT, buff=0.55).move_to(UP * 4.15)
+
+ with self.beat(0) as b:
+ b.play(FadeIn(chip, shift=DOWN * 0.3), run_time=0.4)
+ b.play(LaggedStart(*[FadeIn(d, shift=DOWN * 0.3) for d in dds],
+ lag_ratio=0.25), run_time=1.1)
+ dedo = Triangle(stroke_width=0, fill_color=WHITE, fill_opacity=1).scale(0.22)
+ dedo.rotate(PI).next_to(dds[1], DOWN, buff=0.35)
+ b.play(FadeIn(dedo, shift=UP * 0.3), run_time=0.5)
+
+ vos = Text("vos", font=FONT, font_size=34, weight=BOLD, color=WHITE)
+ vos.next_to(dedo, DOWN, buff=0.15)
+ yo = Text("yo elijo después", font=FONT, font_size=40, weight=BOLD, color=AMBAR)
+ yo.move_to(UP * 1.45)
+
+ with self.beat(1) as b:
+ b.play(FadeIn(vos), run_time=0.35)
+ b.play(FadeIn(yo, shift=UP * 0.2), run_time=0.6)
+
+ gran = Text("56%", font=FONT, font_size=190, weight=BOLD, color=AMBAR)
+ gran.move_to(DOWN * 0.55)
+ pie = Text("gano yo", font=FONT, font_size=46, weight=BOLD, color=WHITE)
+ pie.next_to(gran, DOWN, buff=0.25)
+
+ with self.beat(2) as b:
+ b.play(FadeOut(VGroup(dedo, vos, yo)), run_time=0.3)
+ b.play(FadeIn(gran, scale=0.6), run_time=0.7)
+ b.play(FadeIn(pie, shift=UP * 0.2), run_time=0.4)
+ b.play(Flash(gran, color=AMBAR, flash_radius=2.6, num_lines=20), run_time=0.8)
+
+ with self.beat(3) as b:
+ b.play(FadeOut(VGroup(gran, pie)), run_time=0.35)
+ b.play(dds[1].animate.set_opacity(0.25), dds[2].animate.set_opacity(0.25),
+ run_time=0.4)
+ grande = dds[0].copy().scale(2.0).move_to(UP * 1.2)
+ b.play(TransformFromCopy(dds[0], grande), run_time=0.8)
+
+ with self.beat(4) as b:
+ b.play(FadeOut(grande), dds[1].animate.set_opacity(1),
+ dds[2].animate.set_opacity(1), run_time=0.5)
+ g2 = dds[1].copy().scale(1.7).move_to(UP * 1.5 + LEFT * 1.9)
+ g3 = dds[2].copy().scale(1.7).move_to(UP * 1.5 + RIGHT * 1.9)
+ b.play(TransformFromCopy(dds[1], g2), run_time=0.6)
+ b.play(TransformFromCopy(dds[2], g3), run_time=0.6)
+
+ # --- los tres cruces ----------------------------------------------------
+ centro = np.array([0.0, 0.42, 0.0])
+
+ def cruce(beat, na, nb, previo):
+ celdas, cab, lat, gana = duelo(na, nb, centro)
+ marca = VGroup(
+ Text(na, font=FONT, font_size=42, weight=BOLD, color=COL[na]),
+ Text(f"gana {gana} de 9", font=FONT, font_size=42, weight=BOLD, color=WHITE),
+ ).arrange(RIGHT, buff=0.25).move_to(DOWN * 2.45)
+ if previo:
+ beat.play(FadeOut(previo), run_time=0.3)
+ beat.play(FadeIn(VGroup(cab, lat)), run_time=0.35)
+ beat.play(LaggedStart(*[FadeIn(c, scale=0.6) for c in celdas],
+ lag_ratio=0.09), run_time=max(1.0, beat.floor - 1.5))
+ beat.play(FadeIn(marca, shift=UP * 0.2), run_time=0.45)
+ return VGroup(celdas, cab, lat, marca)
+
+ with self.beat(5) as b:
+ b.play(FadeOut(VGroup(g2, g3)), run_time=0.3)
+ t1 = cruce(b, "rojo", "celeste", None)
+
+ with self.beat(6) as b:
+ t2 = cruce(b, "celeste", "verde", t1)
+
+ with self.beat(7) as b:
+ b.play(FadeOut(t2), run_time=0.35)
+ preg = VGroup(
+ Text("rojo", font=FONT, font_size=54, weight=BOLD, color=ROJO),
+ Text("→", font=FONT, font_size=54, weight=BOLD, color=WHITE),
+ Text("verde", font=FONT, font_size=54, weight=BOLD, color=VERDE),
+ Text("?", font=FONT, font_size=70, weight=BOLD, color=AMBAR),
+ ).arrange(RIGHT, buff=0.3).move_to(UP * 1.6)
+ b.play(FadeIn(preg, shift=UP * 0.25), run_time=0.6)
+ b.play(Indicate(preg[3], color=AMBAR, scale_factor=1.4), run_time=0.7)
+
+ with self.beat(8) as b:
+ no = Text("NO", font=FONT, font_size=96, weight=BOLD, color=ROSA).move_to(UP * 1.6)
+ b.play(FadeOut(preg), run_time=0.25)
+ b.play(FadeIn(no, scale=1.8), run_time=0.4)
+ b.play(FadeOut(no), run_time=0.3)
+ t3 = cruce(b, "verde", "rojo", None)
+
+ # --- el circulo ----------------------------------------------------------
+ with self.beat(9) as b:
+ b.play(FadeOut(t3), FadeOut(dds), run_time=0.4)
+ vert = {"rojo": np.array([0.0, 4.1, 0.0]),
+ "celeste": np.array([-2.55, 0.5, 0.0]),
+ "verde": np.array([2.55, 0.5, 0.0])}
+ nodos = VGroup()
+ for n, p in vert.items():
+ nodos.add(VGroup(
+ Circle(radius=0.86, stroke_width=6, color=COL[n],
+ fill_color="#121C33", fill_opacity=1).move_to(p),
+ Text(n, font=FONT, font_size=27, weight=BOLD, color=COL[n]).move_to(p)))
+ flechas = VGroup()
+ for a, c in (("rojo", "celeste"), ("celeste", "verde"), ("verde", "rojo")):
+ pa, pb = vert[a], vert[c]
+ d = (pb - pa) / np.linalg.norm(pb - pa)
+ f = CurvedArrow(pa + d * 1.02, pb - d * 1.02, angle=-0.55,
+ color=COL[a], stroke_width=7, tip_length=0.26)
+ flechas.add(f)
+ b.play(LaggedStart(*[GrowFromCenter(n) for n in nodos], lag_ratio=0.2),
+ run_time=0.8)
+ b.play(LaggedStart(*[Create(f) for f in flechas], lag_ratio=0.3),
+ run_time=max(0.9, b.floor - 1.6))
+ cinco = Text("5 de 9 siempre", font=FONT, font_size=44, weight=BOLD, color=AMBAR)
+ cinco.move_to(DOWN * 1.35)
+ b.play(FadeIn(cinco, shift=UP * 0.2), run_time=0.45)
+
+ with self.beat(10) as b:
+ cierre = VGroup(
+ Text("El truco:", font=FONT, font_size=44, weight=BOLD, color=WHITE),
+ Text("elegí SEGUNDO", font=FONT, font_size=66, weight=BOLD, color=AMBAR),
+ ).arrange(DOWN, buff=0.26).move_to(DOWN * 1.65)
+ b.play(FadeOut(cinco), run_time=0.3)
+ b.play(FadeIn(cierre, shift=UP * 0.25), run_time=0.7)
+ b.play(*[Indicate(f, color=WHITE, scale_factor=1.05) for f in flechas],
+ run_time=0.9)
+
+ self.finish()