예제 #1
0
파일: scene.py 프로젝트: Rubixdarcy/manim
    def play(self, *animations, **kwargs):
        self.num_animations += 1
        if "run_time" in kwargs:
            run_time = kwargs["run_time"]
        else:
            run_time = animations[0].run_time
        for animation in animations:
            animation.set_run_time(run_time)
        moving_mobjects = [mobject for anim in animations for mobject in anim.mobject.submobject_family()]

        bundle = Mobject(*self.mobjects)
        static_mobjects = filter(lambda m: m not in moving_mobjects, bundle.submobject_family())
        background = disp.paint_mobjects(static_mobjects, self.background, include_sub_mobjects=False)

        times = np.arange(0, run_time, self.frame_duration)
        time_progression = ProgressDisplay(times)
        time_progression.set_description(
            "Animation %d: " % self.num_animations + str(animations[0]) + (", etc." if len(animations) > 1 else "")
        )
        for t in time_progression:
            for animation in animations:
                animation.update(t / animation.run_time)
            new_frame = disp.paint_mobjects([anim.mobject for anim in animations], background)
            self.frames.append(new_frame)
        for animation in animations:
            animation.clean_up()
        self.add(*[anim.mobject for anim in animations])
        self.repaint_mojects()
        return self
예제 #2
0
파일: scene.py 프로젝트: stoeckley/manim
 def add(self, *mobjects):
     """
     Mobjects will be displayed, from background to foreground,
     in the order with which they are entered.
     """
     if not all_elements_are_instances(mobjects, Mobject):
         raise Exception("Adding something which is not a mobject")
     self.set_frame(disp.paint_mobjects(mobjects, self.get_frame()))
     old_mobjects = filter(lambda m: m not in mobjects, self.mobjects)
     self.mobjects = old_mobjects + list(mobjects)
     return self
예제 #3
0
 def add(self, *mobjects):
     """
     Mobjects will be displayed, from background to foreground,
     in the order with which they are entered.
     """
     if not all_elements_are_instances(mobjects, Mobject):
         raise Exception("Adding something which is not a mobject")
     self.set_frame(disp.paint_mobjects(mobjects, self.get_frame()))
     old_mobjects = filter(lambda m : m not in mobjects, self.mobjects)
     self.mobjects = old_mobjects + list(mobjects)
     return self
예제 #4
0
    def play(self, *animations, **kwargs):
        if "run_time" in kwargs:
            run_time = kwargs["run_time"]
        else:
            run_time = animations[0].run_time
        for animation in animations:
            animation.set_run_time(run_time)
        moving_mobjects = [
            mobject
            for anim in animations
            for mobject in anim.mobject.get_full_submobject_family()
        ]

        bundle = Mobject(*self.mobjects)
        static_mobjects = filter(
            lambda m : m not in moving_mobjects, 
            bundle.get_full_submobject_family()
        )
        background = disp.paint_mobjects(
            static_mobjects,
            self.background,
            include_sub_mobjects = False
        )

        print "Generating " + ", ".join(map(str, animations))
        progress_bar = progressbar.ProgressBar(maxval=run_time)
        progress_bar.start()

        for t in np.arange(0, run_time, self.frame_duration):
            progress_bar.update(t)
            for animation in animations:
                animation.update(t / animation.run_time)
            new_frame = disp.paint_mobjects(moving_mobjects, background)
            self.frames.append(new_frame)
        for animation in animations:
            animation.clean_up()
        self.add(*moving_mobjects)
        self.repaint_mojects()
        progress_bar.finish()
        return self
예제 #5
0
파일: scene.py 프로젝트: stoeckley/manim
    def play(self, *animations, **kwargs):
        self.num_animations += 1
        if "run_time" in kwargs:
            run_time = kwargs["run_time"]
        else:
            run_time = animations[0].run_time
        for animation in animations:
            animation.set_run_time(run_time)
        moving_mobjects = [
            mobject for anim in animations
            for mobject in anim.mobject.submobject_family()
        ]

        bundle = Mobject(*self.mobjects)
        static_mobjects = filter(lambda m: m not in moving_mobjects,
                                 bundle.submobject_family())
        background = disp.paint_mobjects(static_mobjects,
                                         self.background,
                                         include_sub_mobjects=False)

        times = np.arange(0, run_time, self.frame_duration)
        time_progression = ProgressDisplay(times)
        time_progression.set_description(
            "Animation %d: "%self.num_animations + \
            str(animations[0]) + \
            (", etc." if len(animations) > 1 else "")
        )
        for t in time_progression:
            for animation in animations:
                animation.update(t / animation.run_time)
            new_frame = disp.paint_mobjects(
                [anim.mobject for anim in animations], background)
            self.frames.append(new_frame)
        for animation in animations:
            animation.clean_up()
        self.add(*[anim.mobject for anim in animations])
        self.repaint_mojects()
        return self
예제 #6
0
    def play_over_time_range(self, t0, t1, *animations):
        needed_scene_time = max(abs(t0), abs(t1))
        existing_scene_time = len(self.frames)*self.frame_duration
        if existing_scene_time < needed_scene_time:
            self.dither(needed_scene_time - existing_scene_time)
            existing_scene_time = needed_scene_time
        #So negative values may be used
        if t0 < 0:
            t0 = float(t0)%existing_scene_time
        if t1 < 0:
            t1 = float(t1)%existing_scene_time
        t0, t1 = min(t0, t1), max(t0, t1)    

        moving_mobjects = [anim.mobject for anim in animations]
        for t in np.arange(t0, t1, self.frame_duration):
            for animation in animations:
                animation.update((t-t0)/(t1 - t0))
            index = int(t/self.frame_duration)
            self.frames[index] = disp.paint_mobjects(moving_mobjects, self.frames[index])
        for animation in animations:
            animation.clean_up()
        return self
예제 #7
0
파일: scene.py 프로젝트: stoeckley/manim
    def play_over_time_range(self, t0, t1, *animations):
        needed_scene_time = max(abs(t0), abs(t1))
        existing_scene_time = len(self.frames) * self.frame_duration
        if existing_scene_time < needed_scene_time:
            self.dither(needed_scene_time - existing_scene_time)
            existing_scene_time = needed_scene_time
        #So negative values may be used
        if t0 < 0:
            t0 = float(t0) % existing_scene_time
        if t1 < 0:
            t1 = float(t1) % existing_scene_time
        t0, t1 = min(t0, t1), max(t0, t1)

        moving_mobjects = [anim.mobject for anim in animations]
        for t in np.arange(t0, t1, self.frame_duration):
            for animation in animations:
                animation.update((t - t0) / (t1 - t0))
            index = int(t / self.frame_duration)
            self.frames[index] = disp.paint_mobjects(moving_mobjects,
                                                     self.frames[index])
        for animation in animations:
            animation.clean_up()
        return self
예제 #8
0
파일: scene.py 프로젝트: stoeckley/manim
 def paint_into_background(self, *mobjects):
     #This way current mobjects don't have to be redrawn with
     #every change, and one can later call "apply" without worrying
     #about it applying to these mobjects
     self.background = disp.paint_mobjects(mobjects, self.background)
     return self
예제 #9
0
파일: scene.py 프로젝트: stoeckley/manim
 def repaint_mojects(self):
     self.set_frame(disp.paint_mobjects(self.mobjects, self.background))
     return self
예제 #10
0
 def paint_into_background(self, *mobjects):
     #This way current mobjects don't have to be redrawn with
     #every change, and one can later call "apply" without worrying
     #about it applying to these mobjects
     self.background = disp.paint_mobjects(mobjects, self.background)
     return self
예제 #11
0
 def repaint_mojects(self):
     self.set_frame(disp.paint_mobjects(self.mobjects, self.background))
     return self