Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

svg can handle ellipse

mirefekfd1f92b705fb
diff --git a/mobject/svg_mobject.py b/mobject/svg_mobject.py
index dc2273bbd..81d7c7c8d 100644
--- a/mobject/svg_mobject.py
+++ b/mobject/svg_mobject.py
@@ -76,6 +76,8 @@ class SVGMobject(VMobject):
result.append(self.rect_to_mobject(element))
elif element.tagName == 'circle':
result.append(self.circle_to_mobject(element))
+ elif element.tagName == 'ellipse':
+ result.append(self.ellipse_to_mobject(element))
elif element.tagName in ['polygon', 'polyline']:
result.append(self.polygon_to_mobject(element))
else:
@@ -122,6 +124,15 @@ class SVGMobject(VMobject):
]
return Circle(radius = r).shift(x*RIGHT+y*DOWN)
+ def ellipse_to_mobject(self, circle_element):
+ x, y, rx, ry = [
+ float(circle_element.getAttribute(key))
+ if circle_element.hasAttribute(key)
+ else 0.0
+ for key in "cx", "cy", "rx", "ry"
+ ]
+ return Circle().scale(rx*RIGHT + ry*UP).shift(x*RIGHT+y*DOWN)
+
def rect_to_mobject(self, rect_element):
if rect_element.hasAttribute("fill"):
if Color(str(rect_element.getAttribute("fill"))) == Color(WHITE):