Ejemplo n.º 1
0
    def animate(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 = [anim.mobject for anim in animations]
        self.remove(*moving_mobjects)
        background = self.get_frame()

        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)
            new_frame = background
            for animation in animations:
                animation.update(t / animation.run_time)
                new_frame = disp.paint_mobject(animation.mobject, new_frame)
            self.frames.append(new_frame)
        for animation in animations:
            animation.clean_up()
        self.add(*moving_mobjects)
        progress_bar.finish()
        return self
Ejemplo n.º 2
0
    def animate(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 = [anim.mobject for anim in animations]
        self.remove(*moving_mobjects)
        background = self.get_frame()

        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)
            new_frame = background
            for animation in animations:
                animation.update(t / animation.run_time)
                new_frame = disp.paint_mobject(animation.mobject, new_frame)
            self.frames.append(new_frame)
        for animation in animations:
            animation.clean_up()
        self.add(*moving_mobjects)
        progress_bar.finish()
        return self
Ejemplo n.º 3
0
    def animate_over_time_range(self, t0, t1, animation):
        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)

        for t in np.arange(t0, t1, self.frame_duration):
            animation.update((t - t0) / (t1 - t0))
            index = int(t / self.frame_duration)
            self.frames[index] = disp.paint_mobject(animation.mobject,
                                                    self.frames[index])
        animation.clean_up()
        return self
Ejemplo n.º 4
0
    def animate_over_time_range(self, t0, t1, animation):
        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)    

        for t in np.arange(t0, t1, self.frame_duration):
            animation.update((t-t0)/(t1 - t0))
            index = int(t/self.frame_duration)
            self.frames[index] = disp.paint_mobject(
                animation.mobject, self.frames[index]
            )
        animation.clean_up()
        return self
Ejemplo n.º 5
0
 def show(self):
     Image.fromarray(disp.paint_mobject(self)).show()
Ejemplo n.º 6
0
 def save_image(self, name = None):
     Image.fromarray(disp.paint_mobject(self)).save(
         os.path.join(MOVIE_DIR, (name or str(self)) + ".png")
     )
Ejemplo n.º 7
0
 def save_image(self, name=None):
     Image.fromarray(disp.paint_mobject(self)).save(
         os.path.join(MOVIE_DIR, (name or str(self)) + ".png"))
Ejemplo n.º 8
0
 def show(self):
     Image.fromarray(disp.paint_mobject(self)).show()
Ejemplo n.º 9
0
 def get_frame(self):
     frame = self.background
     for mob in self.mobjects:
         frame = disp.paint_mobject(mob, frame)
     return frame
Ejemplo n.º 10
0
 def get_frame(self):
     frame = self.background
     for mob in self.mobjects:
         frame = disp.paint_mobject(mob, frame)
     return frame