mirror of
https://github.com/3b1b/manim.git
synced 2025-11-15 16:37:45 +00:00
Some small refactors
This commit is contained in:
parent
5d2dcec307
commit
a6675eb043
1 changed files with 9 additions and 10 deletions
|
|
@ -3,6 +3,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
from types import MethodType
|
from types import MethodType
|
||||||
|
|
||||||
|
from manimlib.constants import BLACK
|
||||||
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
||||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||||
|
|
@ -31,6 +32,7 @@ def _get_neighbouring_pairs(iterable):
|
||||||
|
|
||||||
class _TexSVG(SVGMobject):
|
class _TexSVG(SVGMobject):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
"color": BLACK,
|
||||||
"height": None,
|
"height": None,
|
||||||
"path_string_config": {
|
"path_string_config": {
|
||||||
"should_subdivide_sharp_curves": True,
|
"should_subdivide_sharp_curves": True,
|
||||||
|
|
@ -39,17 +41,14 @@ class _TexSVG(SVGMobject):
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def color_str_to_label(color_str):
|
def color_to_label(fill_color):
|
||||||
if len(color_str) == 4:
|
r, g, b = color_to_int_rgb(fill_color)
|
||||||
# "#RGB" => "#RRGGBB"
|
rg = r * 256 + g
|
||||||
color_str = "#" + "".join([c * 2 for c in color_str[1:]])
|
return rg * 256 + b
|
||||||
if color_str == "#ffffff":
|
|
||||||
return 0
|
|
||||||
return int(color_str[1:], 16)
|
|
||||||
|
|
||||||
def parse_labels(self):
|
def parse_labels(self):
|
||||||
for glyph in self:
|
for glyph in self:
|
||||||
glyph.glyph_label = _TexSVG.color_str_to_label(glyph.fill_color)
|
glyph.glyph_label = _TexSVG.color_to_label(glyph.fill_color)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -90,8 +89,7 @@ class _TexParser(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def label_to_color_tuple(rgb):
|
def label_to_color_tuple(rgb):
|
||||||
# Get a unique color different from black,
|
# Get a unique color different from black.
|
||||||
# or the svg file will not include the color information.
|
|
||||||
rg, b = divmod(rgb, 256)
|
rg, b = divmod(rgb, 256)
|
||||||
r, g = divmod(rg, 256)
|
r, g = divmod(rg, 256)
|
||||||
return r, g, b
|
return r, g, b
|
||||||
|
|
@ -306,6 +304,7 @@ class _TexParser(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_color_related_commands_dict():
|
def get_color_related_commands_dict():
|
||||||
|
# Only list a few commands that are commonly used.
|
||||||
return {
|
return {
|
||||||
"\\color": 1,
|
"\\color": 1,
|
||||||
"\\textcolor": 1,
|
"\\textcolor": 1,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue