SVGMobject#
Qualified name: manim.mobject.svg.svg\_mobject.SVGMobject
- class SVGMobject(file_name=None, should_center=True, height=2, width=None, color=None, opacity=None, fill_color=None, fill_opacity=None, stroke_color=None, stroke_opacity=None, stroke_width=None, svg_default=None, path_string_config=None, use_svg_cache=True, **kwargs)[source]#
Bases:
VMobject
A vectorized mobject created from importing an SVG file.
- Parameters
file_name (str | os.PathLike | None) – The path to the SVG file.
should_center (bool) – Whether or not the mobject should be centered after being imported.
height (float | None) – The target height of the mobject, set to 2 Manim units by default. If the height and width are both set to
None
, the mobject is imported without being scaled.width (float | None) – The target width of the mobject, set to
None
by default. If the height and the width are both set toNone
, the mobject is imported without being scaled.color (str | None) – The color (both fill and stroke color) of the mobject. If
None
(the default), the colors set in the SVG file are used.opacity (float | None) – The opacity (both fill and stroke opacity) of the mobject. If
None
(the default), the opacity set in the SVG file is used.fill_color (str | None) – The fill color of the mobject. If
None
(the default), the fill colors set in the SVG file are used.fill_opacity (float | None) – The fill opacity of the mobject. If
None
(the default), the fill opacities set in the SVG file are used.stroke_color (str | None) – The stroke color of the mobject. If
None
(the default), the stroke colors set in the SVG file are used.stroke_opacity (float | None) – The stroke opacity of the mobject. If
None
(the default), the stroke opacities set in the SVG file are used.stroke_width (float | None) – The stroke width of the mobject. If
None
(the default), the stroke width values set in the SVG file are used.svg_default (dict | None) – A dictionary in which fallback values for unspecified properties of elements in the SVG file are defined. If
None
(the default),color
,opacity
,fill_color
fill_opacity
,stroke_color
, andstroke_opacity
are set toNone
, andstroke_width
is set to 0.path_string_config (dict | None) – A dictionary with keyword arguments passed to
VMobjectFromSVGPath
used for importing path elements. IfNone
(the default), no additional arguments are passed.use_svg_cache (bool) – If True (default), the svg inputs (e.g. file_name, settings) will be used as a key and a copy of the created mobject will be saved using that key to be quickly retrieved if the same inputs need be processed later. For large SVGs which are used only once, this can be omitted to improve performance.
kwargs – Further arguments passed to the parent class.
Methods
Apply SVG style information to the converted mobject.
Convert an ellipse or circle element to a vectorized mobject.
Generate a dictionary holding the default style information.
Parse the SVG and translate its elements to submobjects.
Search for an existing file based on the specified file name.
Convert the elements of the SVG to a list of mobjects.
Apply SVG transformations to the converted mobject.
Checks whether the SVG has already been imported and generates it if not.
Convert a line element to a vectorized mobject.
Modifies the SVG element tree to include default style information.
Scale and move the generated mobject into position.
Convert a path element to a vectorized mobject.
Convert a polygon element to a vectorized mobject.
Convert a polyline element to a vectorized mobject.
Convert a rectangle element to a vectorized mobject.
Convert a text element to a vectorized mobject.
Attributes
animate
Used to animate the application of any method of
self
.animation_overrides
color
depth
The depth of the mobject.
fill_color
If there are multiple colors (for gradient) this returns the first one
A unique hash representing the result of the generated mobject points.
height
The height of the mobject.
n_points_per_curve
sheen_factor
stroke_color
width
The width of the mobject.
- static apply_style_to_mobject(mob, shape)[source]#
Apply SVG style information to the converted mobject.
- static ellipse_to_mobject(ellipse)[source]#
Convert an ellipse or circle element to a vectorized mobject.
- Parameters
ellipse (se.Ellipse | se.Circle) – The parsed SVG ellipse or circle.
- Return type
- generate_config_style_dict()[source]#
Generate a dictionary holding the default style information.
- Return type
dict[str, str]
- generate_mobject()[source]#
Parse the SVG and translate its elements to submobjects.
- Return type
None
- get_file_path()[source]#
Search for an existing file based on the specified file name.
- Return type
Path
- get_mobjects_from(svg)[source]#
Convert the elements of the SVG to a list of mobjects.
- Parameters
svg (se.SVG) – The parsed SVG file.
- Return type
list[VMobject]
- property hash_seed: tuple#
A unique hash representing the result of the generated mobject points.
Used as keys in the
SVG_HASH_TO_MOB_MAP
caching dictionary.
- init_svg_mobject(use_svg_cache)[source]#
Checks whether the SVG has already been imported and generates it if not.
See also
- Parameters
use_svg_cache (bool) –
- Return type
None
- static line_to_mobject(line)[source]#
Convert a line element to a vectorized mobject.
- Parameters
line (Line) – The parsed SVG line.
- Return type
- modify_xml_tree(element_tree)[source]#
Modifies the SVG element tree to include default style information.
- Parameters
element_tree (ElementTree) – The parsed element tree from the SVG file.
- Return type
ElementTree
- path_to_mobject(path)[source]#
Convert a path element to a vectorized mobject.
- Parameters
path (Path) – The parsed SVG path.
- Return type
- static polygon_to_mobject(polygon)[source]#
Convert a polygon element to a vectorized mobject.
- Parameters
polygon (Polygon) – The parsed SVG polygon.
- Return type
- polyline_to_mobject(polyline)[source]#
Convert a polyline element to a vectorized mobject.
- Parameters
polyline (Polyline) – The parsed SVG polyline.
- Return type