A community-maintained Python framework for creating mathematical animations.
Use better progress bar library
Grant Sandersone63ef5b3ad56
diff --git a/extract_scene.py b/extract_scene.pyindex 3376cc773..8e5541f1a 100644--- a/extract_scene.py+++ b/extract_scene.py@@ -195,7 +195,6 @@ def main():)config["movie_prefix"] = config["file"].replace(".py", "")scene_kwargs = config["display_config"]- scene_kwargs["announce_construction"] = Truefor SceneClass in get_scene_classes(scene_names_to_classes, config):for args in get_scene_args(SceneClass, config):scene_kwargs["construct_args"] = tuplify(args)diff --git a/scene/scene.py b/scene/scene.pyindex 495767418..9a05ee672 100644--- a/scene/scene.py+++ b/scene/scene.py@@ -6,7 +6,7 @@ import warningsimport timeimport osimport copy-import progressbar+from tqdm import tqdm as ProgressDisplayimport inspectfrom helpers import *@@ -24,12 +24,9 @@ class Scene(object):"construct_args" : [],"background" : None,"start_dither_time" : DEFAULT_DITHER_TIME,- "announce_construction" : False,}def __init__(self, **kwargs):digest_config(self, kwargs)- if self.announce_construction:- print "Constructing %s..."%str(self)if self.background:self.original_background = np.array(background)#TODO, Error checking?@@ -42,6 +39,7 @@ class Scene(object):self.curr_frame = self.backgroundself.frames = []self.mobjects = []+ self.num_animations = 0self.construct(*self.construct_args)@@ -154,6 +152,7 @@ class Scene(object):self.background = self.get_frame()def play(self, *animations, **kwargs):+ self.num_animations += 1if "run_time" in kwargs:run_time = kwargs["run_time"]else:@@ -177,12 +176,13 @@ class Scene(object):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)+ times = np.arange(0, run_time, self.frame_duration)+ time_progression = ProgressDisplay(times)+ time_progression.set_description(+ "Animation %d: "%self.num_animations + \+ ", ".join(map(str, animations))+ )+ for t in time_progression:for animation in animations:animation.update(t / animation.run_time)new_frame = disp.paint_mobjects(moving_mobjects, background)@@ -191,7 +191,6 @@ class Scene(object):animation.clean_up()self.add(*moving_mobjects)self.repaint_mojects()- progress_bar.finish()return selfdef play_over_time_range(self, t0, t1, *animations):diff --git a/scene/scene_from_video.py b/scene/scene_from_video.pyindex 7d1cde3b7..04c17edc2 100644--- a/scene/scene_from_video.py+++ b/scene/scene_from_video.py@@ -1,6 +1,7 @@import numpy as npimport cv2import itertools as it+from tqdm import tqdm as show_progressfrom scene import Scene@@ -25,20 +26,14 @@ class SceneFromVideo(Scene):frame_count = end_frame - start_frameprint "Reading in " + file_name + "..."- progress_bar = progressbar.ProgressBar(maxval=frame_count)- progress_bar.start()- for count in it.count():+ for count in show_progress(range(start_frame, end_frame+1)):returned, frame = cap.read()- if count < start_frame:- continue- if not returned or count > end_frame:+ if not returnedbreak# b, g, r = cv2.split(frame)# self.frames.append(cv2.merge([r, g, b]))self.frames.append(frame)- progress_bar.update(min(len(self.frames), frame_count))cap.release()- progress_bar.finish()if freeze_last_frame and len(self.frames) > 0:self.original_background = self.background = self.frames[-1]