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/example_scenes.py b/example_scenes.py index bc19f2ae..510a09b3 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", 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", font_size=24, + # 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/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 diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index 5a9873f5..1a42eea0 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -3,13 +3,13 @@ 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 +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 @@ -28,13 +28,15 @@ class TextSetting(object): class Text(SVGMobject): CONFIG = { # Mobject - 'color': consts.WHITE, + 'color': WHITE, 'height': None, + 'stroke_width': 0, # Text 'font': '', 'gradient': None, 'lsh': -1, 'size': 1, + 'font_size': 48, 'slant': NORMAL, 'weight': NORMAL, 't2c': {}, @@ -54,20 +56,6 @@ class Text(SVGMobject): 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: @@ -77,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: @@ -206,7 +194,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/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 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) 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")) 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