예제 #1
0
    def construct(self):
        amount_main = CyrTex(r'\foreignlanguage{bulgarian}{1,42 лева}').scale(
            3)
        self.play(Write(amount_main))
        self.wait()

        amount_cents = CyrTex(
            r'\foreignlanguage{bulgarian}{142 стотинки}').scale(3)
        self.play(FadeOutAndShift(amount_main, UP),
                  FadeInFrom(amount_cents, DOWN))
        self.wait()

        all_coins = Group()
        all_coins.add(Coin(1))
        all_coins.add(Coin(2))
        all_coins.add(Coin(5))
        all_coins.add(Coin(10))
        all_coins.add(Coin(20))
        all_coins.add(Coin(50))
        all_coins.arrange()
        self.add(all_coins)
        all_coins.next_to(amount_cents, DOWN, buff=LARGE_BUFF)

        amount_cents_small = CyrTex(
            r'\foreignlanguage{bulgarian}{142 ст.} =').scale(2)
        amount_cents_small.shift(amount_cents_small.get_width() * LEFT + UP)
        self.play(amount_cents.shift,
                  amount_cents_small.get_width() * LEFT + UP,
                  ReplacementTransform(amount_cents, amount_cents_small),
                  all_coins.to_edge, DOWN)

        brace = MathTex(r'\underbrace{\qquad\qquad\qquad\qquad}').scale(
            1).rotate(-PI / 2)
        brace.next_to(amount_cents_small, RIGHT)
        self.play(FadeIn(brace))

        cents50 = all_coins[5]
        cents20 = all_coins[4]
        cents2 = all_coins[1]

        buff = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER
        cents50_1 = cents50.copy()
        edge = brace.get_critical_point(RIGHT) + RIGHT * 0.75
        up = (cents50_1.get_height() + buff) * UP
        down = (cents50_1.get_height() + buff) * DOWN

        self.play(cents50_1.move_to, edge + up)
        cents50_2 = cents50.copy()
        self.play(cents50_2.next_to, cents50_1)

        cents20_1 = cents20.copy()
        self.play(cents20_1.move_to, edge)
        cents20_2 = cents20.copy()
        self.play(cents20_2.next_to, cents20_1)

        cents2_1 = cents2.copy()
        self.play(cents2_1.move_to, edge + down)
        self.wait()

        self.wait(10)
예제 #2
0
    def construct(self):
        amount_cents_small = CyrTex(
            r'\foreignlanguage{bulgarian}{142 ¢} $=$').scale(2)
        amount_cents_small.shift(amount_cents_small.get_width() * LEFT +
                                 UP * 0.5)
        self.add(amount_cents_small)

        mo_group = Group()
        for loop in range(1):
            for group in groups:
                self.remove(mo_group)
                # self.play(FadeOut(mo_group, run_time=0.05))
                mo_group = Group()
                uniq, counts = numpy.unique(group, return_counts=True)
                print(uniq)
                first = None
                for coin, count in zip(uniq, counts):
                    print(f"{count} x {coin}")
                    mo_coins = [Coin(coin) for _ in range(count)]
                    mo_group.add(*mo_coins)
                    if first:
                        mo_coins[0].next_to(first, DOWN)
                    first = mo_coins[0]
                    for prev, cur in zip(mo_coins, mo_coins[1:]):
                        cur.next_to(prev, RIGHT)
                brace = Brace(mo_group, direction=LEFT)
                brace2 = BraceLabel(mo_group,
                                    r'\foreignlanguage{english}{$' +
                                    str(len(group)) + "$ coins}",
                                    label_constructor=CyrTex)
                mo_group.add(brace, brace2)
                mo_group.shift(
                    amount_cents_small.get_critical_point(RIGHT) -
                    brace.get_tip() +
                    X_AXIS * DEFAULT_MOBJECT_TO_MOBJECT_BUFFER)
                self.add(mo_group)
                # self.play(FadeIn(mo_group, run_time=0.05))
                self.wait(0.2)

        self.wait()
        self.play(FadeOut(amount_cents_small), FadeOut(mo_group))
        self.wait(10)
예제 #3
0
파일: greedy.py 프로젝트: svilen-ivanov/sgp
    def construct(self):
        all_coins = Group()
        all_coins.add(Coin(1))
        all_coins.add(Coin(5))
        all_coins.add(Coin(10))
        all_coins.add(Coin(20))
        all_coins.add(Coin(25))
        all_coins.arrange()
        self.add(all_coins)
        all_coins.to_edge(DOWN, buff=LARGE_BUFF)

        amount_cents_small = CyrTex(
            r'\foreignlanguage{bulgarian}{$40$ ст.} =').scale(2)
        amount_cents_small.shift(amount_cents_small.get_width() * LEFT + UP)
        self.add(amount_cents_small)

        brace = MathTex(r'\underbrace{\qquad\qquad\qquad\qquad}').scale(
            1).rotate(-PI / 2)
        brace.next_to(amount_cents_small, RIGHT)
        self.play(FadeIn(brace))

        cents25 = all_coins[4]
        cents10 = all_coins[2]
        cents5 = all_coins[1]

        buff = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER
        cents25_1 = cents25.copy()

        edge = brace.get_critical_point(RIGHT) + RIGHT * 0.75
        up = (cents25_1.get_height() + buff) * UP
        down = (cents25_1.get_height() + buff) * DOWN

        self.play(cents25_1.move_to, edge + up)

        cents10_1 = cents10.copy()
        self.play(cents10_1.move_to, edge)

        cents5_1 = cents5.copy()
        self.play(cents5_1.move_to, edge + down)
        self.wait()

        wrong_group = Group(cents25_1, cents10_1, cents5_1)
        cross = Cross(wrong_group)
        self.add(cross)
        self.wait()
        self.play(
            LaggedStart(
                *[FadeOut(wrong_group),
                  FadeOut(cross),
                  FadeOut(brace)],
                lag_ratio=0.2))

        brace = MathTex(r'\underbrace{\qquad\qquad\quad}').scale(1).rotate(
            -PI / 2)
        brace.next_to(amount_cents_small, RIGHT)
        self.play(FadeIn(brace))

        cents20 = all_coins[3]

        up = (cents20.get_height() + buff) * UP * 0.5
        down = (cents20.get_height() + buff) * DOWN * 0.5

        cents20_1 = cents20.copy()
        self.play(cents20_1.move_to, edge + up)
        cents20_2 = cents20.copy()
        self.play(cents20_2.move_to, edge + down)
        self.wait()

        self.play(*[FadeOut(x) for x in self.mobjects])
        self.wait(10)