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

This commit is contained in:
Sridhar Ramesh 2018-01-10 17:57:22 -08:00
parent a0fc3ce324
commit 0ce1a528c6
2 changed files with 11 additions and 0 deletions

View file

@ -384,6 +384,10 @@ class Mobject(object):
self.shift(mobject.get_center() - self.get_center()) self.shift(mobject.get_center() - self.get_center())
return self 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): def position_endpoints_on(self, start, end):
curr_vect = self.points[-1] - self.points[0] curr_vect = self.points[-1] - self.points[0]
if np.all(curr_vect == 0): if np.all(curr_vect == 0):

View file

@ -47,6 +47,13 @@ class Circle(Arc):
def __init__(self, **kwargs): def __init__(self, **kwargs):
Arc.__init__(self, 2*np.pi, **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): class Dot(Circle):
CONFIG = { CONFIG = {
"radius" : 0.08, "radius" : 0.08,