Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Made Rectangle a Polygon

Grant Sandersond695e2cc0ba2
diff --git a/manimlib/mobject/geometry.py b/manimlib/mobject/geometry.py
index c23db8df6..583d8fe9a 100644
--- a/manimlib/mobject/geometry.py
+++ b/manimlib/mobject/geometry.py
@@ -702,15 +702,13 @@ class Polygon(VMobject):
}
def __init__(self, *vertices, **kwargs):
- assert len(vertices) > 1
- digest_locals(self)
VMobject.__init__(self, **kwargs)
-
- def generate_points(self):
- self.set_anchor_points(self.vertices, mode="corners")
+ self.set_points_as_corners(
+ [*vertices, vertices[0]]
+ )
def get_vertices(self):
- return self.get_anchors_and_handles()[0]
+ return self.get_start_anchors()
class RegularPolygon(Polygon):
@@ -725,7 +723,7 @@ class RegularPolygon(Polygon):
Polygon.__init__(self, *vertices, **kwargs)
-class Rectangle(VMobject):
+class Rectangle(Polygon):
CONFIG = {
"color": WHITE,
"height": 2.0,
@@ -734,14 +732,16 @@ class Rectangle(VMobject):
"close_new_points": True,
}
- def generate_points(self):
- y, x = self.height / 2., self.width / 2.
- self.set_anchor_points([
+ def __init__(self, **kwargs):
+ digest_config(self, kwargs)
+ x, y = self.width / 2., self.height / 2.
+ vertices = [
x * LEFT + y * UP,
x * RIGHT + y * UP,
x * RIGHT + y * DOWN,
x * LEFT + y * DOWN
- ], mode="corners")
+ ]
+ Polygon.__init__(self, *vertices, **kwargs)
class Square(Rectangle):