Ejemplo n.º 1
0
    def show_99_percent_accuracy(self):
        title = TextMobject("99\\% Accuracy")
        title.to_edge(UP)
        title.generate_target()
        title.target.to_corner(UP + LEFT)

        checks = VGroup(*[
            VGroup(*[
                TexMobject("\\checkmark").highlight(GREEN) for y in range(10)
            ]).arrange_submobjects(DOWN) for x in range(10)
        ]).arrange_submobjects(RIGHT)
        cross = TexMobject("\\times")
        cross.replace(checks[-1][-1])
        cross.highlight(RED)
        Transform(checks[-1][-1], cross).update(1)
        checks.scale_to_fit_height(6)
        checks.next_to(title, DOWN)
        checks.generate_target()
        checks.target.scale(0.5)
        checks.target.next_to(title.target, DOWN)

        self.add(title)
        self.play(Write(checks))
        self.dither(2)
        self.play(*map(MoveToTarget, [title, checks]))
Ejemplo n.º 2
0
 def initialize_bits(self):
     bits = bit_string_to_mobject("")
     bits.to_corner(UP + LEFT)
     one = TexMobject("1")[0]
     one.replace(bits[0], dim_to_match=1)
     self.add(bits)
     self.add_foreground_mobject(VGroup(*bits[-15:]))
     self.number = 0
     self.bits = bits
     self.one = one
     self.zero = bits[0].copy()
Ejemplo n.º 3
0
 def initialize_bits(self):
     bits = bit_string_to_mobject("")
     bits.to_corner(UP+LEFT)
     one = TexMobject("1")[0]
     one.replace(bits[0], dim_to_match = 1)
     self.add(bits)
     self.add_foreground_mobject(VGroup(*bits[-15:]))
     self.number = 0
     self.bits = bits
     self.one = one
     self.zero = bits[0].copy()
Ejemplo n.º 4
0
    def cannot_move_disk_with_crap_on_top(self):
        not_allowed = TextMobject("Not allowed")
        not_allowed.to_edge(UP)
        not_allowed.highlight(RED)
        cross = TexMobject("\\times")
        cross.set_fill(RED, opacity = 0.5)

        disk = self.disks[3]
        disk.save_state()
        self.move_disks_to_peg([3], 1, added_anims = [
            Transform(self.title, not_allowed)
        ])
        cross.replace(disk, stretch = False)
        self.play(FadeIn(cross))
        self.dither()
        self.play(
            FadeOut(cross),
            disk.restore
        )
Ejemplo n.º 5
0
    def write_bayes_rule(self):
        words = self.bayes_rule_words
        words_rect = SurroundingRectangle(words)
        rule = TexMobject("P(", "S", "|", "+", ")", "=", "P(", "S", ")", "{P(",
                          "+", "|", "S", ")", "\\over", "P(", "+", ")}")
        rule.highlight_by_tex("S", SICKLY_GREEN)
        rule.highlight_by_tex("+", YELLOW)
        rule.to_corner(UP + RIGHT)
        rule_rect = SurroundingRectangle(rule)
        rule_rect.highlight(BLUE)
        rule.save_state()
        rule.replace(words_rect)
        rule.scale_in_place(0.9)
        rule.set_fill(opacity=0)

        self.play(ShowCreation(words_rect))
        self.play(ReplacementTransform(words_rect, rule_rect),
                  rule.restore,
                  run_time=2)
        self.dither(3)
Ejemplo n.º 6
0
    def take_derivatives_of_monomial(self, term):
        """
        Must be a group of pure TexMobjects,
        last part must be of the form x^n
        """
        n = int(term[-1].get_tex_string()[-1])
        curr_term = term
        for k in range(n, 0, -1):
            exponent = curr_term[-1][-1]
            exponent_copy = exponent.copy()
            front_num = TexMobject("%d \\cdot"%k)
            front_num.move_to(curr_term[0][0], DOWN+LEFT)

            new_monomial = TexMobject("x^%d"%(k-1))
            new_monomial.replace(curr_term[-1])
            Transform(curr_term[-1], new_monomial).update(1)
            curr_term.generate_target()
            curr_term.target.shift(
                (front_num.get_width()+SMALL_BUFF)*RIGHT
            )
            curr_term[-1][-1].set_fill(opacity = 0)

            self.play(
                ApplyMethod(
                    exponent_copy.replace, front_num[0],
                    path_arc = np.pi,
                ),
                Write(
                    front_num[1], 
                    rate_func = squish_rate_func(smooth, 0.5, 1)
                ),
                MoveToTarget(curr_term),
                run_time = 2
            )
            self.remove(exponent_copy)
            self.add(front_num)
            curr_term = VGroup(front_num, *curr_term)
        self.dither()
        self.play(FadeOut(curr_term[-1]))

        return VGroup(*curr_term[:-1])
Ejemplo n.º 7
0
    def cannot_move_disk_onto_smaller_disk(self):
        also_not_allowed = TextMobject("Also not allowed")
        also_not_allowed.to_edge(UP)
        also_not_allowed.highlight(RED)
        cross = TexMobject("\\times")
        cross.set_fill(RED, opacity = 0.5)

        disk = self.disks[2]
        disk.save_state()
        self.move_disks_to_peg([2], 2, added_anims = [
            Transform(self.title, also_not_allowed)
        ])
        cross.replace(disk)
        self.play(FadeIn(cross))
        self.dither()
        self.play(
            FadeOut(cross),
            FadeOut(self.title),
            disk.restore
        )
        self.dither()
Ejemplo n.º 8
0
    def construct(self):
        top = TOP()
        times = top.put_in_vertex(0, TexMobject("\\times"))
        times.highlight(YELLOW)
        oplus = top.put_in_vertex(1, TexMobject("\\oplus"))
        oplus.highlight(BLUE)
        dot = top.put_in_vertex(2, Dot())
        eight = top.put_on_vertex(2, TexMobject("8"))

        self.add(top)
        self.play(ShowCreation(eight))
        for mob in dot, oplus, times:
            self.play(ShowCreation(mob))
            self.wait()

        top.add(eight)
        top.add(times, oplus, dot)
        top1, top2, top3 = tops = [top.copy() for i in range(3)]
        big_oplus = TexMobject("\\oplus").scale(2).highlight(BLUE)
        equals = TexMobject("=")
        equation = VMobject(top1, big_oplus, top2, equals, top3)
        equation.arrange_submobjects()
        top3.shift(0.5 * RIGHT)
        x, y, xy = [
            t.put_on_vertex(0, s) for t, s in zip(tops, ["x", "y", "xy"])
        ]
        old_style_eq = TexMobject(
            "\\dfrac{1}{\\frac{1}{\\log_x(8)} + \\frac{1}{\\log_y(8)}} = \\log_{xy}(8)"
        )
        old_style_eq.to_edge(UP).highlight(RED)

        triple_top_copy = VMobject(*[top.copy() for i in range(3)])
        self.clear()
        self.play(Transform(triple_top_copy, VMobject(*tops)),
                  FadeIn(VMobject(x, y, xy, big_oplus, equals)))
        self.remove(triple_top_copy)
        self.add(*tops)
        self.play(Write(old_style_eq))
        self.wait(3)

        syms = VMobject(x, y, xy)
        new_syms = VMobject(*[
            t.put_on_vertex(1, s)
            for t, s in zip(tops, ["x", "y", "x \\oplus y"])
        ])
        new_old_style_eq = TexMobject(
            "\\sqrt[x]{8} \\sqrt[y]{8} = \\sqrt[X]{8}")
        X = new_old_style_eq.split()[-4]
        frac = TexMobject("\\frac{1}{\\frac{1}{x} + \\frac{1}{y}}")
        frac.replace(X)
        frac_lower_right = frac.get_corner(DOWN + RIGHT)
        frac.scale(2)
        frac.shift(frac_lower_right - frac.get_corner(DOWN + RIGHT))
        new_old_style_eq.submobjects[-4] = frac
        new_old_style_eq.to_edge(UP)
        new_old_style_eq.highlight(RED)
        big_times = TexMobject("\\times").highlight(YELLOW)
        big_times.shift(big_oplus.get_center())
        self.play(Transform(old_style_eq, new_old_style_eq),
                  Transform(syms, new_syms, path_arc=np.pi / 2),
                  Transform(big_oplus, big_times))
        self.wait(4)
Ejemplo n.º 9
0
    def construct(self):
        top = TOP()
        times = top.put_in_vertex(0, TexMobject("\\times"))
        times.highlight(YELLOW)
        oplus = top.put_in_vertex(1, TexMobject("\\oplus"))
        oplus.highlight(BLUE)
        dot = top.put_in_vertex(2, Dot())
        eight = top.put_on_vertex(2, TexMobject("8"))

        self.add(top)
        self.play(ShowCreation(eight))
        for mob in dot, oplus, times:
            self.play(ShowCreation(mob))
            self.dither()

        top.add(eight)
        top.add(times, oplus, dot)
        top1, top2, top3 = tops = [
            top.copy() for i in range(3)
        ]
        big_oplus = TexMobject("\\oplus").scale(2).highlight(BLUE)
        equals = TexMobject("=")
        equation = VMobject(
            top1, big_oplus, top2, equals, top3
        )
        equation.arrange_submobjects()
        top3.shift(0.5*RIGHT)
        x, y, xy = [
            t.put_on_vertex(0, s)
            for t, s in zip(tops, ["x", "y", "xy"])
        ]
        old_style_eq = TexMobject(
            "\\dfrac{1}{\\frac{1}{\\log_x(8)} + \\frac{1}{\\log_y(8)}} = \\log_{xy}(8)"
        )
        old_style_eq.to_edge(UP).highlight(RED)

        triple_top_copy = VMobject(*[
            top.copy() for i in range(3)
        ])
        self.clear()
        self.play(
            Transform(triple_top_copy, VMobject(*tops)),
            FadeIn(VMobject(x, y, xy, big_oplus, equals))
        )
        self.remove(triple_top_copy)
        self.add(*tops)
        self.play(Write(old_style_eq))
        self.dither(3)

        syms = VMobject(x, y, xy)
        new_syms = VMobject(*[
            t.put_on_vertex(1, s)
            for t, s in zip(tops, ["x", "y", "x \\oplus y"])
        ])
        new_old_style_eq = TexMobject(
            "\\sqrt[x]{8} \\sqrt[y]{8} = \\sqrt[X]{8}"
        )
        X = new_old_style_eq.split()[-4]
        frac = TexMobject("\\frac{1}{\\frac{1}{x} + \\frac{1}{y}}")
        frac.replace(X)
        frac_lower_right = frac.get_corner(DOWN+RIGHT)
        frac.scale(2)
        frac.shift(frac_lower_right - frac.get_corner(DOWN+RIGHT))
        new_old_style_eq.submobjects[-4] = frac
        new_old_style_eq.to_edge(UP)
        new_old_style_eq.highlight(RED)
        big_times = TexMobject("\\times").highlight(YELLOW)
        big_times.shift(big_oplus.get_center())
        self.play(
            Transform(old_style_eq, new_old_style_eq),
            Transform(syms, new_syms, path_arc = np.pi/2),
            Transform(big_oplus, big_times)
        )
        self.dither(4)
Ejemplo n.º 10
0
    def construct(self):
        title = TextMobject("``Linearly dependent'' ")
        title.highlight(YELLOW)
        title.scale(2)
        title.to_edge(UP)
        self.add(title)

        equation1 = TexMobject([
            "\\vec{\\textbf{w}}",
            "=",
            "a",
            "\\vec{\\textbf{v}}",
        ])
        w, eq, a, v = equation1.split()
        w.highlight(BLUE)
        v.highlight(MAROON_C)
        equation1.scale(2)
        eq1_copy = equation1.copy()

        low_words1 = TextMobject("For some value of $a$")
        low_words1.scale(2)
        low_words1.to_edge(DOWN)
        arrow = Arrow(low_words1, a)
        arrow_copy = arrow.copy()

        equation2 = TexMobject([
            "\\vec{\\textbf{u}}",
            "=",
            "a",
            "\\vec{\\textbf{v}}",
            "+",
            "b",
            "\\vec{\\textbf{w}}",
        ])
        u, eq, a, v, plus, b, w = equation2.split()
        u.highlight(RED)
        w.highlight(BLUE)
        v.highlight(MAROON_C)
        equation2.scale(2)
        eq2_copy = equation2.copy()

        low_words2 = TextMobject("For some values of a and b")
        low_words2.scale(2)
        low_words2.to_edge(DOWN)
        arrows = VMobject(*[Arrow(low_words2, var) for var in a, b])

        self.play(Write(equation1))
        self.play(ShowCreation(arrow), Write(low_words1))
        self.wait()

        self.play(Transform(equation1, equation2),
                  Transform(low_words1, low_words2), Transform(arrow, arrows))
        self.wait(2)

        new_title = TextMobject("``Linearly independent'' ")
        new_title.highlight(GREEN)
        new_title.replace(title)

        for eq_copy in eq1_copy, eq2_copy:
            neq = TexMobject("\\neq")
            neq.replace(eq_copy.submobjects[1])
            eq_copy.submobjects[1] = neq

        new_low_words1 = TextMobject(["For", "all", "values of a"])
        new_low_words2 = TextMobject(["For", "all", "values of a and b"])
        for low_words in new_low_words1, new_low_words2:
            low_words.split()[1].highlight(GREEN)
            low_words.scale(2)
            low_words.to_edge(DOWN)

        self.play(Transform(title, new_title), Transform(equation1, eq1_copy),
                  Transform(arrow, arrow_copy),
                  Transform(low_words1, new_low_words1))
        self.wait()
        self.play(Transform(equation1, eq2_copy), Transform(arrow, arrows),
                  Transform(low_words1, new_low_words2))
        self.wait()
Ejemplo n.º 11
0
    def construct(self):
        title = TextMobject("``Linearly dependent'' ")
        title.highlight(YELLOW)
        title.scale(2)
        title.to_edge(UP)
        self.add(title)

        equation1 = TexMobject([
            "\\vec{\\textbf{w}}",
            "=",
            "a",
            "\\vec{\\textbf{v}}",
        ])
        w, eq, a, v = equation1.split()
        w.highlight(BLUE)
        v.highlight(MAROON_C)
        equation1.scale(2)
        eq1_copy = equation1.copy()

        low_words1 = TextMobject("For some value of $a$")
        low_words1.scale(2)
        low_words1.to_edge(DOWN)
        arrow = Arrow(low_words1, a)
        arrow_copy = arrow.copy()

        equation2 = TexMobject([
            "\\vec{\\textbf{u}}",
            "=",
            "a",
            "\\vec{\\textbf{v}}",
            "+",
            "b",
            "\\vec{\\textbf{w}}",
        ])
        u, eq, a, v, plus, b, w = equation2.split()
        u.highlight(RED)
        w.highlight(BLUE)
        v.highlight(MAROON_C)
        equation2.scale(2)
        eq2_copy = equation2.copy()

        low_words2 = TextMobject("For some values of a and b")
        low_words2.scale(2)
        low_words2.to_edge(DOWN)
        arrows = VMobject(*[
            Arrow(low_words2, var)
            for var in a, b
        ])

        self.play(Write(equation1))
        self.play(
            ShowCreation(arrow),
            Write(low_words1)
        )
        self.dither()

        self.play(
            Transform(equation1, equation2),
            Transform(low_words1, low_words2),
            Transform(arrow, arrows)
        )
        self.dither(2)

        new_title = TextMobject("``Linearly independent'' ")
        new_title.highlight(GREEN)
        new_title.replace(title)

        for eq_copy in eq1_copy, eq2_copy:
            neq = TexMobject("\\neq")
            neq.replace(eq_copy.submobjects[1])
            eq_copy.submobjects[1] = neq

        new_low_words1 = TextMobject(["For", "all", "values of a"])
        new_low_words2 = TextMobject(["For", "all", "values of a and b"])
        for low_words in new_low_words1, new_low_words2:
            low_words.split()[1].highlight(GREEN)
            low_words.scale(2)
            low_words.to_edge(DOWN)

        self.play(
            Transform(title, new_title),
            Transform(equation1, eq1_copy),
            Transform(arrow, arrow_copy),
            Transform(low_words1, new_low_words1)
        )
        self.dither()
        self.play(
            Transform(equation1, eq2_copy),
            Transform(arrow, arrows),
            Transform(low_words1, new_low_words2)
        )
        self.dither()
Ejemplo n.º 12
0
Archivo: mug.py Proyecto: Glidos/manim
    def construct(self):
        self.setup_configuration()
        houses, utilities = self.houses, self.utilities
        self.convert_objects_to_dots(run_time = 0)
        objects = self.objects
        lines, line_groups, regions = self.get_lines_line_groups_and_regions()
        back_region = regions[0]
        front_regions = VGroup(*regions[1:])
        missing_lines = VGroup(
            self.get_line(2, 0, self.objects.get_top()),
            self.get_line(
                2, 0, 
                self.objects.get_bottom() + DOWN,
                self.objects.get_corner(DOWN+LEFT) + DOWN+LEFT,
            )
        )
        missing_lines.set_stroke(width = 5)

        front_regions.save_state()
        front_regions.generate_target()
        front_regions.target.scale(0.5)
        front_regions.target.arrange_submobjects(RIGHT, buff = LARGE_BUFF)
        front_regions.target.to_edge(UP)

        self.add(front_regions)
        self.add_foreground_mobjects(lines, objects)
        self.dither()
        self.play(MoveToTarget(front_regions))
        self.play(LaggedStart(
            ApplyMethod, front_regions,
            lambda m : (m.rotate_in_place, np.pi/12),
            rate_func = wiggle,
            lag_ratio = 0.75,
            run_time = 1
        ))
        self.play(front_regions.restore)
        self.dither()

        #Show missing lines
        for line in missing_lines:
            self.play(ShowCreation(
                line,
                rate_func = there_and_back,
                run_time = 2,
            ))

        #Count regions
        count = TexMobject("1")
        count.scale(1.5)
        count.to_edge(UP)
        self.play(
            FadeIn(back_region), 
            FadeIn(count),
            Animation(front_regions)
        )
        last_region = None
        for n, region in zip(it.count(2), front_regions):
            new_count = TexMobject(str(n))
            new_count.replace(count, dim_to_match = 1)
            self.remove(count)
            self.add(new_count)
            count = new_count

            region.save_state()
            anims = [ApplyMethod(region.highlight, YELLOW)]
            if last_region:
                anims.append(ApplyMethod(last_region.restore))
            anims.append(Animation(front_regions))
            self.play(*anims, run_time = 0.25)
            self.dither(0.5)
            last_region = region
        self.play(last_region.restore)
        self.dither()
        self.play(FadeOut(count))

        #Count edges per region
        fade_rect = FullScreenFadeRectangle(opacity = 0.8)
        line_group = line_groups[0].copy()
        region = front_regions[0].copy()
        self.foreground_mobjects = []
        def show_lines(line_group):
            lg_copy = line_group.copy()
            lg_copy.set_stroke(WHITE, 6)
            self.play(LaggedStart(
                FadeIn, lg_copy,
                run_time = 3,
                rate_func = there_and_back,
                lag_ratio = 0.4,
                remover = True,
            ))

        self.play(
            FadeIn(fade_rect),
            Animation(region),
            Animation(line_group),
        )
        show_lines(line_group)
        last_line_group = line_group
        last_region = region
        for i in range(1, 3):
            line_group = line_groups[i].copy()
            region = front_regions[i].copy()
            self.play(
                FadeOut(last_region),
                FadeOut(last_line_group),
                FadeIn(region),
                FadeIn(line_group),
            )
            show_lines(line_group)
            last_line_group = line_group
            last_region = region
        self.play(
            FadeOut(fade_rect),
            FadeOut(last_region),
            FadeOut(last_line_group),
        )
        self.dither()