Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added Surround method to MObject, as well as special-case implementation of it to Circle

Sridhar Ramesh0ce1a528c618
diff --git a/mobject/mobject.py b/mobject/mobject.py
index 6129017ea..ec1ff7c3c 100644
--- a/mobject/mobject.py
+++ b/mobject/mobject.py
@@ -384,6 +384,10 @@ class Mobject(object):
self.shift(mobject.get_center() - self.get_center())
return self
+ def surround(self, mobject, dim_to_match = 0, stretch = False, buffer_factor = 1.2):
+ self.replace(mobject, dim_to_match, stretch)
+ self.scale_in_place(buffer_factor)
+
def position_endpoints_on(self, start, end):
curr_vect = self.points[-1] - self.points[0]
if np.all(curr_vect == 0):
diff --git a/topics/geometry.py b/topics/geometry.py
index 70f5ff7aa..dfa852579 100644
--- a/topics/geometry.py
+++ b/topics/geometry.py
@@ -47,6 +47,13 @@ class Circle(Arc):
def __init__(self, **kwargs):
Arc.__init__(self, 2*np.pi, **kwargs)
+ def surround(self, mobject, dim_to_match = 0, stretch = False, buffer_factor = 1.2):
+ # Ignores dim_to_match and stretch; result will always be a circle
+ # TODO: Perhaps create an ellipse class to handle singele-dimension stretching
+ self.replace(mobject, dim_to_match, stretch)
+ self.scale_to_fit_width(np.sqrt(mobject.get_width()**2 + mobject.get_height()**2))
+ self.scale(buffer_factor)
+
class Dot(Circle):
CONFIG = {
"radius" : 0.08,