A community-maintained Python framework for creating mathematical animations.
reorganize media file tree
Devin Nealcaa4577cd161
diff --git a/manim.py b/manim.pyold mode 100644new mode 100755diff --git a/manimlib/constants.py b/manimlib/constants.pyindex 3fb72a3f5..9ce2db5e3 100644--- a/manimlib/constants.py+++ b/manimlib/constants.py@@ -20,28 +20,19 @@ if not os.path.isdir(MEDIA_DIR):"this behavior by writing a different directory to media_dir.txt.")-VIDEO_DIR = os.path.join(MEDIA_DIR, "videos")-RASTER_IMAGE_DIR = os.path.join(MEDIA_DIR, "designs", "raster_images")-SVG_IMAGE_DIR = os.path.join(MEDIA_DIR, "designs", "svg_images")-SOUND_DIR = os.path.join(MEDIA_DIR, "designs", "sounds")-###-THIS_DIR = os.path.dirname(os.path.realpath(__file__))-FILE_DIR = os.path.join(os.getenv("FILE_DIR", default="."), "files")-TEX_DIR = os.path.join(FILE_DIR, "Tex")-# These two may be depricated now.-MOBJECT_DIR = os.path.join(FILE_DIR, "mobjects")-IMAGE_MOBJECT_DIR = os.path.join(MOBJECT_DIR, "image")--for folder in [FILE_DIR, RASTER_IMAGE_DIR, SVG_IMAGE_DIR, VIDEO_DIR,- TEX_DIR, MOBJECT_DIR, IMAGE_MOBJECT_DIR]:+VIDEO_DIR = os.path.join(MEDIA_DIR, "video")+ASSETS_DIR = os.path.join(MEDIA_DIR, "assets")+TEX_DIR = os.path.join(MEDIA_DIR, "Tex")++for folder in [VIDEO_DIR, ASSETS_DIR, TEX_DIR]:if not os.path.exists(folder):os.makedirs(folder)TEX_USE_CTEX = FalseTEX_TEXT_TO_REPLACE = "YourTextHere"TEMPLATE_TEX_FILE = os.path.join(- THIS_DIR, "tex_template.tex" if not TEX_USE_CTEX- else "ctex_template.tex"+ os.path.dirname(os.path.realpath(__file__)),+ "tex_template.tex" if not TEX_USE_CTEX else "ctex_template.tex")with open(TEMPLATE_TEX_FILE, "r") as infile:TEMPLATE_TEXT_FILE_BODY = infile.read()diff --git a/manimlib/for_3b1b_videos/pi_creature.py b/manimlib/for_3b1b_videos/pi_creature.pyindex fa3864d33..7375c8bd2 100644--- a/manimlib/for_3b1b_videos/pi_creature.py+++ b/manimlib/for_3b1b_videos/pi_creature.py@@ -15,11 +15,11 @@ from manimlib.utils.config_ops import digest_configfrom manimlib.utils.space_ops import get_normfrom manimlib.utils.space_ops import normalize-pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "designs", "PiCreature")+pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "assets", "PiCreature")if os.path.exists(pi_creature_dir_maybe):PI_CREATURE_DIR = pi_creature_dir_maybeelse:- PI_CREATURE_DIR = os.path.join(FILE_DIR)+ PI_CREATURE_DIR = os.path.join("assets")PI_CREATURE_SCALE_FACTOR = 0.5diff --git a/manimlib/mobject/svg/svg_mobject.py b/manimlib/mobject/svg/svg_mobject.pyindex 2e27bb6cb..a5dc6bc3b 100644--- a/manimlib/mobject/svg/svg_mobject.py+++ b/manimlib/mobject/svg/svg_mobject.py@@ -50,9 +50,9 @@ class SVGMobject(VMobject):if self.file_name is None:raise Exception("Must specify file for SVGMobject")possible_paths = [- os.path.join(SVG_IMAGE_DIR, self.file_name),- os.path.join(SVG_IMAGE_DIR, self.file_name + ".svg"),- os.path.join(SVG_IMAGE_DIR, self.file_name + ".xdv"),+ os.path.join(os.path.join("assets", "svg_images"), self.file_name),+ os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".svg"),+ os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".xdv"),self.file_name,]for path in possible_paths:diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.pyindex 7280961b3..fb39c90e3 100644--- a/manimlib/scene/scene_file_writer.py+++ b/manimlib/scene/scene_file_writer.py@@ -13,7 +13,7 @@ from manimlib.constants import STREAMING_PORTfrom manimlib.constants import STREAMING_PROTOCOLfrom manimlib.constants import VIDEO_DIRfrom manimlib.utils.config_ops import digest_config-from manimlib.utils.file_ops import guarantee_existance+from manimlib.utils.file_ops import guarantee_existencefrom manimlib.utils.file_ops import add_extension_if_not_presentfrom manimlib.utils.file_ops import get_sorted_integer_filesfrom manimlib.utils.sounds import get_full_sound_file_path@@ -35,7 +35,6 @@ class SceneFileWriter(object):# TODO, address this in extract_scene et. al."file_name": None,"output_directory": None,- "file_name": None,}def __init__(self, scene, **kwargs):@@ -47,66 +46,62 @@ class SceneFileWriter(object):# Output directories and filesdef init_output_directories(self):- output_directory = self.output_directory or self.get_default_output_directory()- file_name = self.file_name or self.get_default_file_name()+ module_directory = self.output_directory or self.get_default_module_directory()+ scene_name = self.file_name or self.get_default_scene_name()if self.save_last_frame:- image_dir = guarantee_existance(os.path.join(+ image_dir = guarantee_existence(os.path.join(VIDEO_DIR,- output_directory,- self.get_image_directory(),+ module_directory,+ scene_name,+ "images",))self.image_file_path = os.path.join(image_dir,- add_extension_if_not_present(file_name, ".png")+ add_extension_if_not_present(scene_name, ".png"))if self.write_to_movie:- movie_dir = guarantee_existance(os.path.join(+ movie_dir = guarantee_existence(os.path.join(VIDEO_DIR,- output_directory,- self.get_movie_directory(),+ module_directory,+ scene_name,+ self.get_resolution_directory(),))self.movie_file_path = os.path.join(movie_dir,add_extension_if_not_present(- file_name, self.movie_file_extension+ scene_name, self.movie_file_extension))self.gif_file_path = os.path.join(movie_dir,add_extension_if_not_present(- file_name, self.gif_file_extension+ scene_name, self.gif_file_extension))- self.partial_movie_directory = guarantee_existance(os.path.join(+ self.partial_movie_directory = guarantee_existence(os.path.join(movie_dir,- self.get_partial_movie_directory(),- file_name,+ "partial_movie_files",+ scene_name,))- def get_default_output_directory(self):+ def get_default_module_directory(self):filename = os.path.basename(self.input_file_path)- root, ext = os.path.splitext(filename)- return root if root else ext[1:]+ root, _ = os.path.splitext(filename)+ return root- def get_default_file_name(self):+ def get_default_scene_name(self):if self.file_name is None:return self.scene.__class__.__name__else:return self.file_name- def get_movie_directory(self):+ def get_resolution_directory(self):pixel_height = self.scene.camera.pixel_heightframe_rate = self.scene.camera.frame_ratereturn "{}p{}".format(pixel_height, frame_rate)- def get_image_directory(self):- return "images"-- def get_partial_movie_directory(self):- return "partial_movie_files"-# Directory gettersdef get_image_file_path(self):return self.image_file_pathdiff --git a/manimlib/utils/file_ops.py b/manimlib/utils/file_ops.pyindex 36a21e4e2..9c9752a49 100644--- a/manimlib/utils/file_ops.py+++ b/manimlib/utils/file_ops.py@@ -10,7 +10,7 @@ def add_extension_if_not_present(file_name, extension):return file_name-def guarantee_existance(path):+def guarantee_existence(path):if not os.path.exists(path):os.makedirs(path)return os.path.abspath(path)diff --git a/manimlib/utils/images.py b/manimlib/utils/images.pyindex 63dcc58b4..edd755305 100644--- a/manimlib/utils/images.py+++ b/manimlib/utils/images.py@@ -3,14 +3,13 @@ import osfrom PIL import Image-from manimlib.constants import RASTER_IMAGE_DIRfrom manimlib.utils.file_ops import seek_full_path_from_defaultsdef get_full_raster_image_path(image_file_name):return seek_full_path_from_defaults(image_file_name,- default_dir=RASTER_IMAGE_DIR,+ default_dir=os.path.join("assets", "raster_images"),extensions=[".jpg", ".png", ".gif"])diff --git a/manimlib/utils/sounds.py b/manimlib/utils/sounds.pyindex 17a185cee..26cfff07d 100644--- a/manimlib/utils/sounds.py+++ b/manimlib/utils/sounds.py@@ -1,5 +1,4 @@import os-from manimlib.constants import SOUND_DIRfrom manimlib.utils.file_ops import seek_full_path_from_defaults@@ -35,6 +34,6 @@ def play_finish_sound():def get_full_sound_file_path(sound_file_name):return seek_full_path_from_defaults(sound_file_name,- default_dir=SOUND_DIR,+ default_dir=os.path.join("assets", "sounds"),extensions=[".wav", ".mp3"])