コード例 #1
0
    def construct(self):
        #  mA = dot_to_vgroup(A_source)
        #  mA_complement = dot_to_vgroup(Acomplement_source)
        #  mA_complement_trim = dot_to_vgroup(Acomplement_trim_source)

        #  self.play(mn.ShowCreation(mA))
        #  self.wait()
        #  self.remove(mA)
        #  self.play(mn.Transform(mA, mA_complement))
        #  self.wait()
        #  self.remove(mA)
        #  self.remove(mA_complement)
        #  self.play(mn.Transform(mA_complement, mA_complement_trim))

        #  self.wait()

        mD = dot_to_vgroup(C_progression[0])
        self.play(mn.ShowCreation(mD))
        self.wait()
        self.remove(mD)
        for source in C_progression[1:]:
            next_mD = dot_to_vgroup(source)
            self.play(mn.Transform(mD, next_mD))
            self.wait()
            self.remove(mD)
            self.remove(next_mD)
            mD = next_mD
コード例 #2
0
ファイル: examples.py プロジェクト: Dettorer/animaut
 def construct(self):
     with open("examples/C1.dot") as f:
         mD = dot_to_vgroup(f.read())
     self.play(mn.ShowCreation(mD))
     self.wait()
     self.remove(mD)
     for n in range(2, 4):
         with open(f"examples/C{n}.dot") as f:
             next_mD = dot_to_vgroup(f.read())
         self.play(mn.Transform(mD, next_mD))
         self.wait()
         self.remove(mD)
         self.remove(next_mD)
         mD = next_mD
コード例 #3
0
ファイル: examples.py プロジェクト: Dettorer/animaut
    def construct(self):
        with open("examples/A.dot") as f:
            mA = dot_to_vgroup(f.read())
        with open("examples/A_complement.dot") as f:
            mA_complement = dot_to_vgroup(f.read())
        with open("examples/A_complement_trim.dot") as f:
            mA_complement_trim = dot_to_vgroup(f.read())

        self.play(mn.ShowCreation(mA))
        self.wait()
        self.remove(mA)
        self.play(mn.Transform(mA, mA_complement))
        self.wait()
        self.remove(mA)
        self.remove(mA_complement)
        self.play(mn.Transform(mA_complement, mA_complement_trim))

        self.wait()
コード例 #4
0
    def flip_cell(self, i, j):
        """
        Flips a cell
        :param i, j: coordinates of cell, int
        :return: Transform object instance, to be fed into `play` function
        """
        if self.grid[i][j]:
            animation = man.FadeOut(self.grid[i][j], run_time=ANIMATION_SPEED)
            self.grid[i][j] = None

        else:
            self.grid[i][j] = man.Rectangle(height=CELL_SIZE, width=CELL_SIZE)
            self.grid[i][j].set_fill(man.COLOR_MAP["RED_C"], opacity=1.0)
            self.grid[i][j].shift(man.RIGHT * CELL_SIZE * j +
                                  man.UP * CELL_SIZE * i +
                                  0.5 * CELL_SIZE * DIAGONAL_LINE)
            animation = man.ShowCreation(self.grid[i][j],
                                         run_time=ANIMATION_SPEED)

        return animation
コード例 #5
0
    def construct(self):
        # Detailed design of the subtractor
        sub_wiring = TikzMobject(subtractor_detailed_source).scale(0.5)
        input_a = mn.TexMobject("A_i") \
            .move_to(sub_wiring.get_center() + 2.8 * UP + 5.3 * LEFT)
        input_b = mn.TexMobject("B_i").next_to(input_a, mn.RIGHT)
        input_r = mn.TexMobject("R_{i-1}").next_to(input_b, mn.RIGHT)
        output_s = mn.TexMobject("S_i") \
            .move_to(sub_wiring.get_center() + 5.7 * RIGHT + 0.9 * UP)
        output_r = mn.TexMobject("R_i") \
            .move_to(sub_wiring.get_center() + 5.7 * RIGHT + 2.3 * DOWN)
        sub_detailed = mn.VGroup(sub_wiring, input_a, input_b, input_r,
                                 output_s, output_r)

        self.play(mn.ShowCreation(sub_detailed))
        self.wait()

        # Simplfied symbol for the subtractor
        sub_symbol = TikzMobject(subtractor_source)
        input_a = mn.TexMobject("A_i") \
            .move_to(sub_symbol.get_center() + 0.7 * LEFT + 0.2 * UP)
        input_b = mn.TexMobject("B_i") \
            .move_to(input_a.get_center() + 1.1 * DOWN)
        input_r = mn.TexMobject("R_{i-1}") \
            .move_to(sub_symbol.get_center() + 0.9 * UP)
        output_s = mn.TexMobject("S_i") \
            .move_to(sub_symbol.get_center() + 0.7 * RIGHT + 0.2 * UP)
        output_r = mn.TexMobject("R_i") \
            .move_to(output_s.get_center() + 1.1 * DOWN)
        sub = mn.VGroup(sub_symbol, input_a, input_b, input_r, output_s,
                        output_r)

        self.play(mn.Transform(sub_detailed, sub))
        self.wait()

        # Draw the four subtractors
        sub1 = sub.copy().scale(0.3).move_to(2.5 * UP)
        self.remove(sub_detailed)  # why is it needed?
        self.play(mn.Transform(sub, sub1))
        sub2 = sub1.copy().next_to(sub1, DOWN)
        sub3 = sub2.copy().next_to(sub2, DOWN)
        sub4 = sub3.copy().next_to(sub3, DOWN)
        subs = [sub1, sub2, sub3, sub4]
        self.play(*[mn.ShowCreation(obj) for obj in subs[1:]])

        # Link them
        links = []
        for i in range(3):
            src = subs[i]
            dst = subs[i + 1]
            down = mn.Line(src.get_center() + 0.43 * RIGHT + 0.26 * DOWN,
                           dst.get_center() + 0.43 * RIGHT + 0.48 * UP,
                           stroke_width=0.8)
            left = mn.Line(dst.get_center() + 0.43 * RIGHT + 0.48 * UP,
                           dst.get_center() + 0.48 * UP,
                           stroke_width=0.8)
            links.append(mn.VGroup(down, left))
        self.play(*[mn.ShowCreation(link) for link in links])

        # Link inputs
        r0 = mn.TextMobject("0") \
            .scale(0.3) \
            .move_to(sub1.get_center() + 0.7 * UP)
        r0_line = mn.Line(sub1.get_center() + 0.47 * UP,
                          sub1.get_center() + 0.63 * UP,
                          stroke_width=0.8)
        inputs = [r0, r0_line]
        for sub in subs:
            ai_line = mn.Line(sub.get_center() + 0.42 * LEFT + 0.05 * UP,
                              sub.get_center() + LEFT + 0.05 * UP,
                              stroke_width=0.8)
            ai = mn.TexMobject(f"A_{i}").scale(0.3).next_to(ai_line, LEFT)
            inputs.append(mn.VGroup(ai_line, ai))

            bi_line = mn.Line(sub.get_center() + 0.42 * LEFT + 0.265 * DOWN,
                              sub.get_center() + LEFT + 0.265 * DOWN,
                              stroke_width=0.8)
            bi = mn.TexMobject(f"B_{i}").scale(0.3).next_to(bi_line, LEFT)
            inputs.append(mn.VGroup(bi_line, bi))

        self.play(*[mn.ShowCreation(obj) for obj in inputs])

        # Link outputs
        outputs = []
        for sub in subs:
            si_line = mn.Line(sub.get_center() + 0.42 * RIGHT + 0.05 * UP,
                              sub.get_center() + RIGHT + 0.05 * UP,
                              stroke_width=0.8)
            si = mn.TexMobject(f"S_{i}").scale(0.3).next_to(si_line, RIGHT)
            outputs.append(mn.VGroup(si_line, si))

        self.play(*[mn.ShowCreation(obj) for obj in outputs])

        complete_sub = mn.VGroup(*subs, *links, *inputs, *outputs)
        self.play(mn.ApplyMethod(complete_sub.shift, 2 * LEFT + 0.5 * DOWN))

        # Draw a subtraction
        a = [
            mn.TexMobject("5").move_to(subs[1].get_center() + 4 * RIGHT),
            mn.TexMobject("6").move_to(subs[1].get_center() + 4.5 * RIGHT),
            mn.TexMobject("3").move_to(subs[1].get_center() + 5 * RIGHT),
            mn.TexMobject("1").move_to(subs[1].get_center() + 5.5 * RIGHT)
        ]
        b = [
            mn.TexMobject("3").move_to(subs[1].get_center() + 0.5 * DOWN +
                                       4 * RIGHT),
            mn.TexMobject("8").move_to(subs[1].get_center() + 0.5 * DOWN +
                                       4.5 * RIGHT),
            mn.TexMobject("4").move_to(subs[1].get_center() + 0.5 * DOWN +
                                       5 * RIGHT),
            mn.TexMobject("6").move_to(subs[1].get_center() + 0.5 * DOWN +
                                       5.5 * RIGHT)
        ]
        minus_sign = mn.TexMobject("-").next_to(b[0], LEFT)
        separator = mn.Line(minus_sign.get_center() + 0.5 * LEFT + 0.5 * DOWN,
                            b[-1].get_center() + 0.5 * RIGHT + 0.5 * DOWN)
        subtraction = mn.VGroup(*a, *b, minus_sign, separator)
        self.play(mn.ShowCreation(subtraction))
        self.wait(5)