mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 22:13:30 +08:00
Use better progress bar library
This commit is contained in:
@ -195,7 +195,6 @@ def main():
|
|||||||
)
|
)
|
||||||
config["movie_prefix"] = config["file"].replace(".py", "")
|
config["movie_prefix"] = config["file"].replace(".py", "")
|
||||||
scene_kwargs = config["display_config"]
|
scene_kwargs = config["display_config"]
|
||||||
scene_kwargs["announce_construction"] = True
|
|
||||||
for SceneClass in get_scene_classes(scene_names_to_classes, config):
|
for SceneClass in get_scene_classes(scene_names_to_classes, config):
|
||||||
for args in get_scene_args(SceneClass, config):
|
for args in get_scene_args(SceneClass, config):
|
||||||
scene_kwargs["construct_args"] = tuplify(args)
|
scene_kwargs["construct_args"] = tuplify(args)
|
||||||
|
@ -6,7 +6,7 @@ import warnings
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
import progressbar
|
from tqdm import tqdm as ProgressDisplay
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from helpers import *
|
from helpers import *
|
||||||
@ -24,12 +24,9 @@ class Scene(object):
|
|||||||
"construct_args" : [],
|
"construct_args" : [],
|
||||||
"background" : None,
|
"background" : None,
|
||||||
"start_dither_time" : DEFAULT_DITHER_TIME,
|
"start_dither_time" : DEFAULT_DITHER_TIME,
|
||||||
"announce_construction" : False,
|
|
||||||
}
|
}
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
digest_config(self, kwargs)
|
digest_config(self, kwargs)
|
||||||
if self.announce_construction:
|
|
||||||
print "Constructing %s..."%str(self)
|
|
||||||
if self.background:
|
if self.background:
|
||||||
self.original_background = np.array(background)
|
self.original_background = np.array(background)
|
||||||
#TODO, Error checking?
|
#TODO, Error checking?
|
||||||
@ -42,6 +39,7 @@ class Scene(object):
|
|||||||
self.curr_frame = self.background
|
self.curr_frame = self.background
|
||||||
self.frames = []
|
self.frames = []
|
||||||
self.mobjects = []
|
self.mobjects = []
|
||||||
|
self.num_animations = 0
|
||||||
|
|
||||||
self.construct(*self.construct_args)
|
self.construct(*self.construct_args)
|
||||||
|
|
||||||
@ -154,6 +152,7 @@ class Scene(object):
|
|||||||
self.background = self.get_frame()
|
self.background = self.get_frame()
|
||||||
|
|
||||||
def play(self, *animations, **kwargs):
|
def play(self, *animations, **kwargs):
|
||||||
|
self.num_animations += 1
|
||||||
if "run_time" in kwargs:
|
if "run_time" in kwargs:
|
||||||
run_time = kwargs["run_time"]
|
run_time = kwargs["run_time"]
|
||||||
else:
|
else:
|
||||||
@ -177,12 +176,13 @@ class Scene(object):
|
|||||||
include_sub_mobjects = False
|
include_sub_mobjects = False
|
||||||
)
|
)
|
||||||
|
|
||||||
print "Generating " + ", ".join(map(str, animations))
|
times = np.arange(0, run_time, self.frame_duration)
|
||||||
progress_bar = progressbar.ProgressBar(maxval=run_time)
|
time_progression = ProgressDisplay(times)
|
||||||
progress_bar.start()
|
time_progression.set_description(
|
||||||
|
"Animation %d: "%self.num_animations + \
|
||||||
for t in np.arange(0, run_time, self.frame_duration):
|
", ".join(map(str, animations))
|
||||||
progress_bar.update(t)
|
)
|
||||||
|
for t in time_progression:
|
||||||
for animation in animations:
|
for animation in animations:
|
||||||
animation.update(t / animation.run_time)
|
animation.update(t / animation.run_time)
|
||||||
new_frame = disp.paint_mobjects(moving_mobjects, background)
|
new_frame = disp.paint_mobjects(moving_mobjects, background)
|
||||||
@ -191,7 +191,6 @@ class Scene(object):
|
|||||||
animation.clean_up()
|
animation.clean_up()
|
||||||
self.add(*moving_mobjects)
|
self.add(*moving_mobjects)
|
||||||
self.repaint_mojects()
|
self.repaint_mojects()
|
||||||
progress_bar.finish()
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def play_over_time_range(self, t0, t1, *animations):
|
def play_over_time_range(self, t0, t1, *animations):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
import itertools as it
|
import itertools as it
|
||||||
|
from tqdm import tqdm as show_progress
|
||||||
|
|
||||||
from scene import Scene
|
from scene import Scene
|
||||||
|
|
||||||
@ -25,20 +26,14 @@ class SceneFromVideo(Scene):
|
|||||||
|
|
||||||
frame_count = end_frame - start_frame
|
frame_count = end_frame - start_frame
|
||||||
print "Reading in " + file_name + "..."
|
print "Reading in " + file_name + "..."
|
||||||
progress_bar = progressbar.ProgressBar(maxval=frame_count)
|
for count in show_progress(range(start_frame, end_frame+1)):
|
||||||
progress_bar.start()
|
|
||||||
for count in it.count():
|
|
||||||
returned, frame = cap.read()
|
returned, frame = cap.read()
|
||||||
if count < start_frame:
|
if not returned
|
||||||
continue
|
|
||||||
if not returned or count > end_frame:
|
|
||||||
break
|
break
|
||||||
# b, g, r = cv2.split(frame)
|
# b, g, r = cv2.split(frame)
|
||||||
# self.frames.append(cv2.merge([r, g, b]))
|
# self.frames.append(cv2.merge([r, g, b]))
|
||||||
self.frames.append(frame)
|
self.frames.append(frame)
|
||||||
progress_bar.update(min(len(self.frames), frame_count))
|
|
||||||
cap.release()
|
cap.release()
|
||||||
progress_bar.finish()
|
|
||||||
|
|
||||||
if freeze_last_frame and len(self.frames) > 0:
|
if freeze_last_frame and len(self.frames) > 0:
|
||||||
self.original_background = self.background = self.frames[-1]
|
self.original_background = self.background = self.frames[-1]
|
||||||
|
Reference in New Issue
Block a user