# -*- 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=GRIS) n.next_to(r, DOWN, buff=0.16) return VGroup(r, n) def guest(self, color=CELESTE, 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", CELESTE) rooms = VGroup(*[self.room(i) for i in range(NR)]) dots3 = Text("· · ·", font=FONT, font_size=52, weight=BOLD, color=GRIS) 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=ROSA) full.move_to(UP * 5.15) b.play(FadeIn(full), run_time=0.4) nuevo = self.guest(AMBAR).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=AMBAR) q.move_to(DOWN * 0.15) b.play(FadeIn(nuevo, 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: libre = rooms[0][0].copy().set_stroke(AMBAR, 8).set_fill("#2A2410", 1) b.play(Transform(rooms[0][0], libre), run_time=0.5) b.play(nuevo.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(nuevo, *[guests[i] for i in range(NR - 1)]) # ---- llegan infinitos ---- with self.beat(4) as b: horda = VGroup(*[self.guest(AMBAR, 0.55).move_to([-3.9 + i * 0.62, 0.7, 0]) for i in range(11)]) inf = MathTex(r"\infty", color=AMBAR).scale(2.2).next_to(horda, RIGHT, buff=0.3) b.play(LaggedStart(*[FadeIn(g, shift=UP * 0.2) for g in horda], 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=VERDE), 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: impares = [0, 2, 4, 6] b.play(FadeOut(rule), run_time=0.25) b.play(*[rooms[i][0].animate.set_stroke(AMBAR, 8).set_fill("#2A2410", 1) for i in impares], run_time=0.8) lbl = self.fit(Text("libres: 1, 3, 5, 7…", font=FONT, font_size=46, weight=BOLD, color=AMBAR), 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(horda, 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=AMBAR), 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=CELESTE).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) cta = self.fit(Text("hotel de Hilbert", font=FONT, font_size=62, weight=BOLD, color=AMBAR), 7.9).move_to(DOWN * 0.9) b.play(Write(cta), run_time=0.9) b.play(Circumscribe(cta, color=AMBAR, buff=0.3, stroke_width=7), run_time=1.0) self.finish()