コード例 #1
0
ファイル: combinatorics.py プロジェクト: Magnus01/manim_test
 def generate_n_choose_k_mobs(self):
     self.coords_to_n_choose_k = {}
     for n, k in self.coords:
         nck_mob = TexMobject(r"{%d \choose %d}" % (n, k))
         scale_factor = min(
             1,
             self.portion_to_fill * self.cell_height / nck_mob.get_height(),
             self.portion_to_fill * self.cell_width / nck_mob.get_width(),
         )
         center = self.coords_to_mobs[n][k].get_center()
         nck_mob.center().scale(scale_factor).shift(center)
         if n not in self.coords_to_n_choose_k:
             self.coords_to_n_choose_k[n] = {}
         self.coords_to_n_choose_k[n][k] = nck_mob
     return self
コード例 #2
0
ファイル: combinatorics.py プロジェクト: Magnus01/manim_test
    def count_mobjects(self,
                       mobjects,
                       mode="highlight",
                       color="red",
                       display_numbers=True,
                       num_offset=DEFAULT_COUNT_NUM_OFFSET,
                       run_time=DEFAULT_COUNT_RUN_TIME):
        """
        Note, leaves final number mobject as "number" attribute

        mode can be "highlight", "show_creation" or "show", otherwise
        a warning is given and nothing is animating during the count
        """
        if len(mobjects) > 50:  #TODO
            raise Exception("I don't know if you should be counting \
                             too many mobjects...")
        if len(mobjects) == 0:
            raise Exception("Counting mobject list of length 0")
        if mode not in ["highlight", "show_creation", "show"]:
            raise Warning("Unknown mode")
        frame_time = run_time / len(mobjects)
        if mode == "highlight":
            self.add(*mobjects)
        for mob, num in zip(mobjects, it.count(1)):
            if display_numbers:
                num_mob = TexMobject(str(num))
                num_mob.center().shift(num_offset)
                self.add(num_mob)
            if mode == "highlight":
                original_color = mob.color
                mob.set_color(color)
                self.wait(frame_time)
                mob.set_color(original_color)
            if mode == "show_creation":
                self.play(ShowCreation(mob, run_time=frame_time))
            if mode == "show":
                self.add(mob)
                self.wait(frame_time)
            if display_numbers:
                self.remove(num_mob)
        if display_numbers:
            self.add(num_mob)
            self.number = num_mob
        return self
コード例 #3
0
class FlipThroughSymbols(Animation):
    CONFIG = {
        "start_center": ORIGIN,
        "end_center": ORIGIN,
    }

    def __init__(self, tex_list, **kwargs):
        mobject = TexMobject(self.curr_tex).shift(start_center)
        Animation.__init__(self, mobject, **kwargs)

    def update_mobject(self, alpha):
        new_tex = self.tex_list[np.ceil(alpha * len(self.tex_list)) - 1]

        if new_tex != self.curr_tex:
            self.curr_tex = new_tex
            self.mobject = TexMobject(new_tex).shift(self.start_center)
        if not all(self.start_center == self.end_center):
            self.mobject.center().shift((1 - alpha) * self.start_center +
                                        alpha * self.end_center)
コード例 #4
0
class FlipThroughSymbols(Animation):
    CONFIG = {
        "start_center": ORIGIN,
        "end_center": ORIGIN,
    }

    def __init__(self, tex_list, **kwargs):
        mobject = TexMobject(self.curr_tex).shift(start_center)
        Animation.__init__(self, mobject, **kwargs)

    def update_mobject(self, alpha):
        new_tex = self.tex_list[np.ceil(alpha * len(self.tex_list)) - 1]

        if new_tex != self.curr_tex:
            self.curr_tex = new_tex
            self.mobject = TexMobject(new_tex).shift(self.start_center)
        if not all(self.start_center == self.end_center):
            self.mobject.center().shift(
                (1 - alpha) * self.start_center + alpha * self.end_center
            )
コード例 #5
0
ファイル: combinatorics.py プロジェクト: Magnus01/manim_test
 def count_regions(self,
                   regions,
                   mode="one_at_a_time",
                   num_offset=DEFAULT_COUNT_NUM_OFFSET,
                   run_time=DEFAULT_COUNT_RUN_TIME,
                   **unused_kwargsn):
     if mode not in ["one_at_a_time", "show_all"]:
         raise Warning("Unknown mode")
     frame_time = run_time / (len(regions))
     for region, count in zip(regions, it.count(1)):
         num_mob = TexMobject(str(count))
         num_mob.center().shift(num_offset)
         self.add(num_mob)
         self.set_color_region(region)
         self.wait(frame_time)
         if mode == "one_at_a_time":
             self.reset_background()
         self.remove(num_mob)
     self.add(num_mob)
     self.number = num_mob
     return self
コード例 #6
0
ファイル: combinatorics.py プロジェクト: yetong170728/manim
 def generate_points(self):
     self.cell_height = float(self.height) / self.nrows
     self.cell_width = float(self.width) / self.nrows
     self.bottom_left = (self.cell_width * self.nrows / 2.0)*LEFT + \
                        (self.cell_height * self.nrows / 2.0)*DOWN
     num_to_num_mob = {}
     self.coords_to_mobs = {}
     self.coords = [(n, k) for n in range(self.nrows) for k in range(n + 1)]
     for n, k in self.coords:
         num = choose(n, k)
         center = self.coords_to_center(n, k)
         num_mob = TexMobject(str(num))
         scale_factor = min(
             1,
             self.portion_to_fill * self.cell_height / num_mob.get_height(),
             self.portion_to_fill * self.cell_width / num_mob.get_width(),
         )
         num_mob.center().scale(scale_factor).shift(center)
         if n not in self.coords_to_mobs:
             self.coords_to_mobs[n] = {}
         self.coords_to_mobs[n][k] = num_mob
     self.add(*[self.coords_to_mobs[n][k] for n, k in self.coords])
     return self