From 79b81363309d4b9eb1a125d6dac75ee5cd674bc1 Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 20:18:13 +0800 Subject: [PATCH 1/8] fix Text in shaders --- manimlib/mobject/svg/text_mobject.py | 26 +++----------------------- manimlib/utils/directories.py | 4 ++++ 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index 5a9873f5..a19b416d 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -7,6 +7,7 @@ import manimlib.constants as consts from manimlib.constants import * from manimlib.mobject.svg.svg_mobject import SVGMobject from manimlib.utils.config_ops import digest_config +from manimlib.utils.directories import get_text_dir TEXT_MOB_SCALE_FACTOR = 0.05 @@ -30,6 +31,7 @@ class Text(SVGMobject): # Mobject 'color': consts.WHITE, 'height': None, + 'stroke_width': 0, # Text 'font': '', 'gradient': None, @@ -51,23 +53,8 @@ class Text(SVGMobject): self.lsh = self.size if self.lsh == -1 else self.lsh file_name = self.text2svg() - self.remove_last_M(file_name) SVGMobject.__init__(self, file_name, **config) - nppc = self.n_points_per_curve - for each in self: - if len(each.get_points()) == 0: - continue - points = each.get_points() - last = points[0] - each.clear_points() - for index, point in enumerate(points): - each.append_points([point]) - if index != len(points) - 1 and (index + 1) % nppc == 0 and any(point != points[index+1]): - each.add_line_to(last) - last = points[index + 1] - each.add_line_to(last) - if self.t2c: self.set_color_by_t2c() if self.gradient: @@ -79,13 +66,6 @@ class Text(SVGMobject): if self.height is None: self.scale(TEXT_MOB_SCALE_FACTOR) - def remove_last_M(self, file_name): - with open(file_name, 'r') as fpr: - content = fpr.read() - content = re.sub(r'Z M [^A-Za-z]*? "\/>', 'Z "/>', content) - with open(file_name, 'w') as fpw: - fpw.write(content) - def find_indexes(self, word): m = re.match(r'\[([0-9\-]{0,}):([0-9\-]{0,})\]', word) if m: @@ -206,7 +186,7 @@ class Text(SVGMobject): if self.font == '': print(NOT_SETTING_FONT_MSG) - dir_name = consts.TEXT_DIR + dir_name = get_text_dir() hash_name = self.text2hash() file_name = os.path.join(dir_name, hash_name) +'.svg' if os.path.exists(file_name): diff --git a/manimlib/utils/directories.py b/manimlib/utils/directories.py index cd70af57..efdaffe4 100644 --- a/manimlib/utils/directories.py +++ b/manimlib/utils/directories.py @@ -33,6 +33,10 @@ def get_tex_dir(): return guarantee_existence(os.path.join(get_temp_dir(), "Tex")) +def get_text_dir(): + return guarantee_existence(os.path.join(get_temp_dir(), "Text")) + + def get_mobject_data_dir(): return guarantee_existence(os.path.join(get_temp_dir(), "mobject_data")) From 78848b971cd3f7db0831db58ad4e9c40d1cf61e4 Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 20:18:50 +0800 Subject: [PATCH 2/8] fix a wrong usage of logging.log --- manimlib/extract_scene.py | 1 - 1 file changed, 1 deletion(-) diff --git a/manimlib/extract_scene.py b/manimlib/extract_scene.py index d0d27802..a04bd7db 100644 --- a/manimlib/extract_scene.py +++ b/manimlib/extract_scene.py @@ -79,7 +79,6 @@ def get_scenes_to_render(scene_classes, scene_config, config): logging.log( logging.ERROR, f"No scene named {scene_name} found", - file=sys.stderr ) if result: return result From 1d1706039e8ca40a2a9ba94a102afc5495427b06 Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 20:25:17 +0800 Subject: [PATCH 3/8] remove an unnecessary import --- manimlib/mobject/svg/text_mobject.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index a19b416d..9f4d8aac 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -3,7 +3,6 @@ import os import copy import hashlib import cairo -import manimlib.constants as consts from manimlib.constants import * from manimlib.mobject.svg.svg_mobject import SVGMobject from manimlib.utils.config_ops import digest_config @@ -29,7 +28,7 @@ class TextSetting(object): class Text(SVGMobject): CONFIG = { # Mobject - 'color': consts.WHITE, + 'color': WHITE, 'height': None, 'stroke_width': 0, # Text From f696ba4100d43e67a3ebd05c05b514086cf435b6 Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 21:11:17 +0800 Subject: [PATCH 4/8] add an example for Text --- example_scenes.py | 39 ++++++++++++++++++++++++++++ manimlib/mobject/svg/text_mobject.py | 8 ++++++ 2 files changed, 47 insertions(+) diff --git a/example_scenes.py b/example_scenes.py index bc19f2ae..c38599f4 100644 --- a/example_scenes.py +++ b/example_scenes.py @@ -104,6 +104,45 @@ class WarpSquare(Scene): self.wait() +class TextExample(Scene): + def construct(self): + # To run this scene properly, you should have "Consolas" font in your computer + # for full usage, you can see https://github.com/3b1b/manim/pull/680 + text = Text("Here is a text", font="Consolas", size=2) + difference = Text( + """ + The most important difference between Text and TextMobject is that\n + you can change the font more easily, but can't use the LaTeX gramma + """, + font="Arial", size=0.5, + # t2c is a dict that you can choose color for different text + t2c={"Text": BLUE, "TextMobject": BLUE, "LaTeX": ORANGE} + ) + VGroup(text, difference).arrange(DOWN, buff=1) + self.play(Write(text)) + self.play(FadeIn(difference, UP)) + self.wait(3) + + fonts = Text( + "And you can also set the font according to different words", + t2f={"font": "Consolas", "words": "Consolas"}, + t2c={"font": BLUE, "words": GREEN} + ) + slant = Text( + "And the same as slant and weight", + font="Consolas", + t2s={"slant": ITALIC}, + t2w={"weight": BOLD}, + t2c={"slant": ORANGE, "weight": RED} + ) + VGroup(fonts, slant).arrange(DOWN, buff=0.8) + self.play(FadeOut(text), FadeOut(difference, shift=DOWN)) + self.play(Write(fonts)) + self.wait() + self.play(Write(slant)) + self.wait() + + class SquareToCircle(Scene): def construct(self): circle = Circle() diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index 9f4d8aac..baeb33b4 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -52,6 +52,7 @@ class Text(SVGMobject): self.lsh = self.size if self.lsh == -1 else self.lsh file_name = self.text2svg() + self.remove_last_M(file_name) SVGMobject.__init__(self, file_name, **config) if self.t2c: @@ -65,6 +66,13 @@ class Text(SVGMobject): if self.height is None: self.scale(TEXT_MOB_SCALE_FACTOR) + def remove_last_M(self, file_name): + with open(file_name, 'r') as fpr: + content = fpr.read() + content = re.sub(r'Z M [^A-Za-z]*? "\/>', 'Z "/>', content) + with open(file_name, 'w') as fpw: + fpw.write(content) + def find_indexes(self, word): m = re.match(r'\[([0-9\-]{0,}):([0-9\-]{0,})\]', word) if m: From fa3cad18e0e4d55e727b09ff210a79befa612b19 Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 21:47:19 +0800 Subject: [PATCH 5/8] update requirements.txt and environment.yml --- environment.yml | 4 ++++ requirements.txt | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 3bafd191..96780d9c 100644 --- a/environment.yml +++ b/environment.yml @@ -17,7 +17,11 @@ dependencies: - Pillow - progressbar - scipy + - sympy - tqdm - moderngl - pydub + - pyyaml + - validators + - ipython diff --git a/requirements.txt b/requirements.txt index 3136ec28..1507d768 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,5 @@ pydub pyyaml screeninfo pyreadline; sys_platform == 'win32' -validators \ No newline at end of file +validators +ipython \ No newline at end of file From c6fcaa93bb9c4482815fd03b19de2a52951cf143 Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 22:49:11 +0800 Subject: [PATCH 6/8] remove stream_starter --- manimlib/stream_starter.py | 51 -------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 manimlib/stream_starter.py diff --git a/manimlib/stream_starter.py b/manimlib/stream_starter.py deleted file mode 100644 index 4a3c5a9b..00000000 --- a/manimlib/stream_starter.py +++ /dev/null @@ -1,51 +0,0 @@ -from time import sleep -import code -import os -import subprocess - -from manimlib.scene.scene import Scene -import manimlib.constants - - -def start_livestream(to_twitch=False, twitch_key=None): - class Manim(): - def __new__(cls): - kwargs = { - "scene_name": manimlib.constants.LIVE_STREAM_NAME, - "open_video_upon_completion": False, - "show_file_in_finder": False, - # By default, write to file - "write_to_movie": True, - "show_last_frame": False, - "save_pngs": False, - # If -t is passed in (for transparent), this will be RGBA - "saved_image_mode": "RGB", - "movie_file_extension": ".mp4", - "quiet": True, - "ignore_waits": False, - "write_all": False, - "name": manimlib.constants.LIVE_STREAM_NAME, - "start_at_animation_number": 0, - "end_at_animation_number": None, - "skip_animations": False, - "camera_config": manimlib.constants.HIGH_QUALITY_CAMERA_CONFIG, - "livestreaming": True, - "to_twitch": to_twitch, - "twitch_key": twitch_key, - } - return Scene(**kwargs) - - if not to_twitch: - FNULL = open(os.devnull, 'w') - subprocess.Popen( - [manimlib.constants.STREAMING_CLIENT, manimlib.constants.STREAMING_URL], - stdout=FNULL, - stderr=FNULL) - sleep(3) - - variables = globals().copy() - variables.update(locals()) - shell = code.InteractiveConsole(variables) - shell.push("manim = Manim()") - shell.push("from manimlib.imports import *") - shell.interact(banner=manimlib.constants.STREAMING_CONSOLE_BANNER) From 97ecfcda9b018a318463c49c451258eb18c6323c Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 22:57:22 +0800 Subject: [PATCH 7/8] remove media_dir.txt in scene/ --- manimlib/scene/media_dir.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 manimlib/scene/media_dir.txt diff --git a/manimlib/scene/media_dir.txt b/manimlib/scene/media_dir.txt deleted file mode 100644 index 27949aaf..00000000 --- a/manimlib/scene/media_dir.txt +++ /dev/null @@ -1 +0,0 @@ -media \ No newline at end of file From 7c04edcced38eea1046b934aa853e8500c4b3af9 Mon Sep 17 00:00:00 2001 From: Tony031218 <975062472@qq.com> Date: Fri, 15 Jan 2021 23:39:24 +0800 Subject: [PATCH 8/8] improve Text's size --- example_scenes.py | 4 ++-- manimlib/mobject/svg/text_mobject.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/example_scenes.py b/example_scenes.py index c38599f4..510a09b3 100644 --- a/example_scenes.py +++ b/example_scenes.py @@ -108,13 +108,13 @@ class TextExample(Scene): def construct(self): # To run this scene properly, you should have "Consolas" font in your computer # for full usage, you can see https://github.com/3b1b/manim/pull/680 - text = Text("Here is a text", font="Consolas", size=2) + text = Text("Here is a text", font="Consolas", font_size=90) difference = Text( """ The most important difference between Text and TextMobject is that\n you can change the font more easily, but can't use the LaTeX gramma """, - font="Arial", size=0.5, + font="Arial", font_size=24, # t2c is a dict that you can choose color for different text t2c={"Text": BLUE, "TextMobject": BLUE, "LaTeX": ORANGE} ) diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index baeb33b4..1a42eea0 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -9,7 +9,7 @@ from manimlib.utils.config_ops import digest_config from manimlib.utils.directories import get_text_dir -TEXT_MOB_SCALE_FACTOR = 0.05 +TEXT_MOB_SCALE_FACTOR = 0.001048 # Warning, these classes are currently based on an old rendering mode @@ -36,6 +36,7 @@ class Text(SVGMobject): 'gradient': None, 'lsh': -1, 'size': 1, + 'font_size': 48, 'slant': NORMAL, 'weight': NORMAL, 't2c': {}, @@ -64,7 +65,7 @@ class Text(SVGMobject): # anti-aliasing if self.height is None: - self.scale(TEXT_MOB_SCALE_FACTOR) + self.scale(TEXT_MOB_SCALE_FACTOR * self.font_size) def remove_last_M(self, file_name): with open(file_name, 'r') as fpr: