mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 13:34:19 +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", "")
|
||||
scene_kwargs = config["display_config"]
|
||||
scene_kwargs["announce_construction"] = True
|
||||
for SceneClass in get_scene_classes(scene_names_to_classes, config):
|
||||
for args in get_scene_args(SceneClass, config):
|
||||
scene_kwargs["construct_args"] = tuplify(args)
|
||||
|
@ -6,7 +6,7 @@ import warnings
|
||||
import time
|
||||
import os
|
||||
import copy
|
||||
import progressbar
|
||||
from tqdm import tqdm as ProgressDisplay
|
||||
import inspect
|
||||
|
||||
from 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.background
|
||||
self.frames = []
|
||||
self.mobjects = []
|
||||
self.num_animations = 0
|
||||
|
||||
self.construct(*self.construct_args)
|
||||
|
||||
@ -154,6 +152,7 @@ class Scene(object):
|
||||
self.background = self.get_frame()
|
||||
|
||||
def play(self, *animations, **kwargs):
|
||||
self.num_animations += 1
|
||||
if "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 self
|
||||
|
||||
def play_over_time_range(self, t0, t1, *animations):
|
||||
|
@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import itertools as it
|
||||
from tqdm import tqdm as show_progress
|
||||
|
||||
from scene import Scene
|
||||
|
||||
@ -25,20 +26,14 @@ class SceneFromVideo(Scene):
|
||||
|
||||
frame_count = end_frame - start_frame
|
||||
print "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 returned
|
||||
break
|
||||
# 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]
|
||||
|
Reference in New Issue
Block a user