aboutsummaryrefslogtreecommitdiffstats
path: root/scenes/v18_dados.py
blob: f0c2940b94095c362438644a19511a3b3b69275a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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=