Merge pull request #1315 from Tony031218/shaders

Fix some bugs of the shaders branch
This commit is contained in:
Grant Sanderson
2021-01-15 11:13:33 -08:00
committed by GitHub
8 changed files with 56 additions and 73 deletions

View File

@ -17,7 +17,11 @@ dependencies:
- Pillow - Pillow
- progressbar - progressbar
- scipy - scipy
- sympy
- tqdm - tqdm
- moderngl - moderngl
- pydub - pydub
- pyyaml
- validators
- ipython

View File

@ -104,6 +104,45 @@ class WarpSquare(Scene):
self.wait() 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): class SquareToCircle(Scene):
def construct(self): def construct(self):
circle = Circle() circle = Circle()

View File

@ -79,7 +79,6 @@ def get_scenes_to_render(scene_classes, scene_config, config):
logging.log( logging.log(
logging.ERROR, logging.ERROR,
f"No scene named {scene_name} found", f"No scene named {scene_name} found",
file=sys.stderr
) )
if result: if result:
return result return result

View File

@ -3,13 +3,13 @@ import os
import copy import copy
import hashlib import hashlib
import cairo import cairo
import manimlib.constants as consts
from manimlib.constants import * from manimlib.constants import *
from manimlib.mobject.svg.svg_mobject import SVGMobject from manimlib.mobject.svg.svg_mobject import SVGMobject
from manimlib.utils.config_ops import digest_config 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 # Warning, these classes are currently based on an old rendering mode
@ -28,13 +28,15 @@ class TextSetting(object):
class Text(SVGMobject): class Text(SVGMobject):
CONFIG = { CONFIG = {
# Mobject # Mobject
'color': consts.WHITE, 'color': WHITE,
'height': None, 'height': None,
'stroke_width': 0,
# Text # Text
'font': '', 'font': '',
'gradient': None, 'gradient': None,
'lsh': -1, 'lsh': -1,
'size': 1, 'size': 1,
'font_size': 48,
'slant': NORMAL, 'slant': NORMAL,
'weight': NORMAL, 'weight': NORMAL,
't2c': {}, 't2c': {},
@ -54,20 +56,6 @@ class Text(SVGMobject):
self.remove_last_M(file_name) self.remove_last_M(file_name)
SVGMobject.__init__(self, file_name, **config) 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: if self.t2c:
self.set_color_by_t2c() self.set_color_by_t2c()
if self.gradient: if self.gradient:
@ -77,7 +65,7 @@ class Text(SVGMobject):
# anti-aliasing # anti-aliasing
if self.height is None: 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): def remove_last_M(self, file_name):
with open(file_name, 'r') as fpr: with open(file_name, 'r') as fpr:
@ -206,7 +194,7 @@ class Text(SVGMobject):
if self.font == '': if self.font == '':
print(NOT_SETTING_FONT_MSG) print(NOT_SETTING_FONT_MSG)
dir_name = consts.TEXT_DIR dir_name = get_text_dir()
hash_name = self.text2hash() hash_name = self.text2hash()
file_name = os.path.join(dir_name, hash_name) +'.svg' file_name = os.path.join(dir_name, hash_name) +'.svg'
if os.path.exists(file_name): if os.path.exists(file_name):

View File

@ -1 +0,0 @@
media

View File

@ -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)

View File

@ -33,6 +33,10 @@ def get_tex_dir():
return guarantee_existence(os.path.join(get_temp_dir(), "Tex")) 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(): def get_mobject_data_dir():
return guarantee_existence(os.path.join(get_temp_dir(), "mobject_data")) return guarantee_existence(os.path.join(get_temp_dir(), "mobject_data"))

View File

@ -14,4 +14,5 @@ pydub
pyyaml pyyaml
screeninfo screeninfo
pyreadline; sys_platform == 'win32' pyreadline; sys_platform == 'win32'
validators validators
ipython