aboutsummaryrefslogtreecommitdiffstats
path: root/scenes/v7_hilbert.py
blob: 86b1d0a9278346d5deea4c4cacdcec27ae6aa912 (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
# -*- coding: utf-8 -*-
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from manim import *
from tiktok import *

NR = 7
PITCH, RW, RH, RY = 1.05, 0.92, 1.3, 3.15
XS = [-3.15 + i * PITCH for i in range(NR)]


class Hilbert(TikTok):
    NAME = "hilbert"

    def room(self, i):
        r = RoundedRectangle(corner_radius=0.12, width=RW, height=RH,
                             stroke_color="#2E3A55", stroke_width=5,
                             fill_color="#131C33", fill_opacity=1).move_to([XS[i], RY, 0])
        n = Text(str(i + 1), font=FONT, font_size=34, weight=BOLD, color=C_GRAY)
        n.next_to(r, DOWN, buff=0.16)
        return VGroup(r, n)

    def guest(self, color=C_SKY, s=1.0):
        head = Dot(radius=0.12, color=color)
        body = RoundedRectangle(corner_radius=0.1, width=0.36, height=0.34,
                                stroke_width=0, fill_color=color, fill_opacity=1)
        body.next_to(head, DOWN, buff=0.05)
        return VGroup(head, body).scale(s)

    def construct(self):
        self.prepare()
        chip = self.chip("El hotel infinito", C_SKY)

        rooms = VGroup(*[self.room(i) for i in range(NR)])
        dots3 = Text("· · ·", font=FONT, font_size=52, weight=BOLD, color=C_GRAY)
        dots3.move_to([XS[-1] + 0.85, RY, 0])
        guests = VGroup(*[self.guest().move_to([XS[i], RY, 0]) for i in range(NR)])

        with self.beat(0) as b:
            b.play(FadeIn(chip, shift=DOWN * 0.3), run_time=0.45)
            b.play(LaggedStart(*[FadeIn(r, shift=DOWN * 0.2) for r in rooms],
                               lag_ratio=0.1), run_time=1.0)
            b.play(FadeIn(dots3), run_time=0.3)
            b.play(LaggedStart(*[FadeIn(g, scale=0.5) for g in guests],
                               lag_ratio=0.08), run_time=0.9)
            full = Text("COMPLETO", font=FONT, font_size=44, weight=BOLD, color=C_PINK)
            full.move_to(UP * 5.15)
            b.play(FadeIn(full), run_time=0.4)

        new_one = self.guest(AMBER).move_to([-4.05, 1.25, 0])
        with self.beat(1) as b:
            q = Text("¿hay lugar?", font=FONT, font_size=46, weight=BOLD, color=AMBER)
            q.move_to(DOWN * 0.15)
            b.play(FadeIn(new_one, shift=RIGHT * 0.3), run_time=0.6)
            b.play(Write(q), run_time=0.7)

        with self.beat(2) as b:
            b.play(FadeOut(q), FadeOut(full), run_time=0.3)
            movs = []
            for i in range(NR - 1):
                movs.append(guests[i].animate.move_to([XS[i + 1], RY, 0]))
            movs.append(guests[NR - 1].animate.move_to(dots3.get_center()).set_opacity(0))
            b.play(LaggedStart(*movs, lag_ratio=0.09), run_time=max(1.2, b.floor - 0.6))

        with self.beat(3) as b:
            loose = rooms[0][0].copy().set_stroke(AMBER, 8).set_fill("#2A2410", 1)
            b.play(Transform(rooms[0][0], loose), run_time=0.5)
            b.play(new_one.animate.move_to([XS[0], RY, 0]), run_time=0.8)
            b.play(rooms[0][0].animate.set_stroke("#2E3A55", 5).set_fill("#131C33", 1),
                   run_time=0.4)
        guests = VGroup(new_one, *[guests[i] for i in range(NR - 1)])

        # ---- infinitely many arrive ---
        with self.beat(4) as b:
            horde = VGroup(*[self.guest(AMBER, 0.55).move_to([-3.9 + i * 0.62, 0.7, 0])
                             for i in range(11)])
            inf = MathTex(r"\infty", color=AMBER).scale(2.2).next_to(horde, RIGHT, buff=0.3)
            b.play(LaggedStart(*[FadeIn(g, shift=UP * 0.2) for g in horde],
                               lag_ratio=0.06), run_time=1.1)
            b.play(Write(inf), run_time=0.6)

        with self.beat(5) as b:
            rule = self.fit(Text("cada uno → al doble", font=FONT, font_size=50,
                                 weight=BOLD, color=C_GREEN), 8.0).move_to(DOWN * 1.35)
            b.play(FadeIn(rule, shift=UP * 0.15), run_time=0.7)

        with self.beat(6) as b:
            movs = []
            for i in range(NR):
                t = 2 * (i + 1) - 1
                if t < NR:
                    movs.append(guests[i].animate.move_to([XS[t], RY, 0]))
                else:
                    movs.append(guests[i].animate.move_to(dots3.get_center()).set_opacity(0))
            b.play(LaggedStart(*movs, lag_ratio=0.12), run_time=max(1.3, b.floor - 0.5))

        with self.beat(7) as b:
            odds = [0, 2, 4, 6]
            b.play(FadeOut(rule), run_time=0.25)
            b.play(*[rooms[i][0].animate.set_stroke(AMBER, 8).set_fill("#2A2410", 1)
                     for i in odds], run_time=0.8)
            lbl = self.fit(Text("libres: 1, 3, 5, 7…", font=FONT, font_size=46,
                                weight=BOLD, color=AMBER), 8.0).move_to(DOWN * 1.35)
            b.play(FadeIn(lbl, shift=UP * 0.15), run_time=0.6)

        with self.beat(8) as b:
            b.play(FadeOut(VGroup(horde, inf, lbl)), run_time=0.4)
            t = VGroup(
                self.fit(Text("estaba lleno", font=FONT, font_size=50,
                              weight=BOLD, color=WHITE), 8.0),
                self.fit(Text("y entraron infinitos más", font=FONT, font_size=50,
                              weight=BOLD, color=AMBER), 8.2),
            ).arrange(DOWN, buff=0.3).move_to(DOWN * 0.7)
            b.play(FadeIn(t[0], shift=UP * 0.15), run_time=0.5)
            b.play(FadeIn(t[1], shift=UP * 0.15), run_time=0.7)

        with self.beat(9) as b:
            b.play(FadeOut(t), run_time=0.3)
            t2 = VGroup(
                MathTex(r"\infty", color=C_SKY).scale(3.4),
                self.fit(Text("no es un número grande.\nes otra cosa.", font=FONT,
                              font_size=44, weight=BOLD, color=WHITE,
                              line_spacing=0.8), 8.0),
            ).arrange(DOWN, buff=0.45).move_to(DOWN * 0.9)
            b.play(FadeIn(t2[0], scale=0.6), run_time=0.7)
            b.play(FadeIn(t2[1], shift=UP * 0.15), run_time=0.7)

        with self.beat(10) as b:
            b.play(FadeOut(t2), run_time=0.3)
            count_txt = self.fit(Text("hotel de Hilbert", font=FONT, font_size=62,
                                weight=BOLD, color=AMBER), 7.9).move_to(DOWN * 0.9)
            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()