예제 #1
0
    def construct(self):
        term_en = CyrTex(r"Dynamic Programming").scale(2)
        #term_bg = CyrTex(r"\foreignlanguage{bulgarian}{\textit{Динамично програмиране}}").scale(1.5)

        group = VGroup(term_en)
        self.play(FadeIn(term_en))
        #term_bg.next_to(term_en, direction=DOWN)
        self.wait(2)
        #self.play(FadeIn(term_bg), group.center)
        self.wait(5)
        self.play(FadeOut(group))

        photo = ImageMobject("Richard_Ernest_Bellman.jpg").set_height(6)
        title_below = CyrTex(
            r"\foreignlanguage{english}{Richard Ernest Bellman}")
        group2 = Group(photo, title_below)
        self.play(FadeIn(photo), photo.to_edge, UP)
        title_below.next_to(photo, direction=DOWN)
        self.play(Write(title_below, run_time=1))
        self.wait(5)
        self.play(FadeOut(group2))
        self.wait(5)

        for x, y in random_points:
            print(f"[{x}, {y}]")
            coin = Coin("10").move_to(np.array((x, y, 0))).shift_onto_screen()
            self.add(coin)
        self.wait(5)
        new_coin = Coin("10").move_to(np.array((2, -2, 0)))
        self.play(FadeIn(new_coin))
        self.wait(10)
예제 #2
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.coin1 = Coin(1)
     self.coin2 = Coin(2)
     self.coin5 = Coin(5)
     self.coins = [self.coin1, self.coin2, self.coin5]
     self.mins = [MinCount(i) for i in range(10)]
     self.eq = CyrTex('$=$')
     self.plus = CyrTex('$+$')
     self.min_word = CyrTex('$min$')
     self.cdots = CyrTex(r'$\cdots$')
     self.zero = CyrTex('$0$')
     self.question_mark = CyrTex('?')
     self.same_min = [[] for _ in self.mins]
     self.iteration_groups = []
예제 #3
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)
예제 #4
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)