mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Updated the scale_to_fit Mobject methods based on new about_point and about_edge convention
This commit is contained in:
parent
d07efc6cb5
commit
7c9f5ca711
1 changed files with 36 additions and 32 deletions
|
@ -164,6 +164,9 @@ class Mobject(object):
|
||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def flip(self, axis = UP, **kwargs):
|
||||||
|
return self.rotate(TAU/2, axis, **kwargs)
|
||||||
|
|
||||||
def stretch(self, factor, dim, **kwargs):
|
def stretch(self, factor, dim, **kwargs):
|
||||||
def func(points):
|
def func(points):
|
||||||
points[:,dim] *= factor
|
points[:,dim] *= factor
|
||||||
|
@ -194,6 +197,12 @@ class Mobject(object):
|
||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def apply_complex_function(self, function, **kwargs):
|
||||||
|
return self.apply_function(
|
||||||
|
lambda (x, y, z) : complex_to_R3(function(complex(x, y))),
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
def wag(self, direction = RIGHT, axis = DOWN, wag_factor = 1.0):
|
def wag(self, direction = RIGHT, axis = DOWN, wag_factor = 1.0):
|
||||||
for mob in self.family_members_with_points():
|
for mob in self.family_members_with_points():
|
||||||
alphas = np.dot(mob.points, np.transpose(axis))
|
alphas = np.dot(mob.points, np.transpose(axis))
|
||||||
|
@ -227,6 +236,8 @@ class Mobject(object):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
#### In place operations ######
|
#### In place operations ######
|
||||||
|
#Note, much of these are now redundant with default behavior of
|
||||||
|
#above methods
|
||||||
|
|
||||||
def apply_points_function_about_point(self, func, about_point = None, about_edge = ORIGIN):
|
def apply_points_function_about_point(self, func, about_point = None, about_edge = ORIGIN):
|
||||||
if about_point is None:
|
if about_point is None:
|
||||||
|
@ -251,22 +262,20 @@ class Mobject(object):
|
||||||
# redundant with default behavior of rotate now.
|
# redundant with default behavior of rotate now.
|
||||||
return self.rotate(angle, axis = axis, axes = axes)
|
return self.rotate(angle, axis = axis, axes = axes)
|
||||||
|
|
||||||
def flip(self, axis = UP):
|
def scale_in_place(self, scale_factor, **kwargs):
|
||||||
self.rotate_in_place(np.pi, axis)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def scale_in_place(self, scale_factor):
|
|
||||||
#Redundant with default behavior of scale now.
|
#Redundant with default behavior of scale now.
|
||||||
return self.scale(scale_factor)
|
return self.scale(scale_factor, **kwargs)
|
||||||
|
|
||||||
def scale_about_point(self, scale_factor, point):
|
def scale_about_point(self, scale_factor, point):
|
||||||
#Redundant with default behavior of scale now.
|
#Redundant with default behavior of scale now.
|
||||||
return self.scale(scale_factor, about_point = point)
|
return self.scale(scale_factor, about_point = point)
|
||||||
|
|
||||||
def pose_at_angle(self):
|
def pose_at_angle(self, **kwargs):
|
||||||
self.rotate_in_place(np.pi / 7, RIGHT+UP)
|
self.rotate(TAU/14, RIGHT+UP, **kwargs)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
#### Positioning methods ####
|
||||||
|
|
||||||
def center(self):
|
def center(self):
|
||||||
self.shift(-self.get_center())
|
self.shift(-self.get_center())
|
||||||
return self
|
return self
|
||||||
|
@ -350,42 +359,41 @@ class Mobject(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def stretch_about_point(self, factor, dim, point):
|
def stretch_about_point(self, factor, dim, point):
|
||||||
self.do_about_point(point, self.stretch, factor, dim)
|
return self.stretch(factor, dim, about_point = point)
|
||||||
return self
|
|
||||||
|
|
||||||
def stretch_in_place(self, factor, dim):
|
def stretch_in_place(self, factor, dim):
|
||||||
self.do_in_place(self.stretch, factor, dim)
|
#Now redundant with stretch
|
||||||
return self
|
return self.stretch(factor, dim)
|
||||||
|
|
||||||
def rescale_to_fit(self, length, dim, stretch = False):
|
def rescale_to_fit(self, length, dim, stretch = False, **kwargs):
|
||||||
old_length = self.length_over_dim(dim)
|
old_length = self.length_over_dim(dim)
|
||||||
if old_length == 0:
|
if old_length == 0:
|
||||||
return self
|
return self
|
||||||
if stretch:
|
if stretch:
|
||||||
self.stretch_in_place(length/old_length, dim)
|
self.stretch(length/old_length, dim, **kwargs)
|
||||||
else:
|
else:
|
||||||
self.scale_in_place(length/old_length)
|
self.scale(length/old_length, **kwargs)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def stretch_to_fit_width(self, width):
|
def stretch_to_fit_width(self, width, **kwargs):
|
||||||
return self.rescale_to_fit(width, 0, stretch = True)
|
return self.rescale_to_fit(width, 0, stretch = True, **kwargs)
|
||||||
|
|
||||||
def stretch_to_fit_height(self, height):
|
def stretch_to_fit_height(self, height, **kwargs):
|
||||||
return self.rescale_to_fit(height, 1, stretch = True)
|
return self.rescale_to_fit(height, 1, stretch = True, **kwargs)
|
||||||
|
|
||||||
def scale_to_fit_width(self, width):
|
def scale_to_fit_width(self, width, **kwargs):
|
||||||
return self.rescale_to_fit(width, 0, stretch = False)
|
return self.rescale_to_fit(width, 0, stretch = False, **kwargs)
|
||||||
|
|
||||||
def scale_to_fit_height(self, height):
|
def scale_to_fit_height(self, height, **kwargs):
|
||||||
return self.rescale_to_fit(height, 1, stretch = False)
|
return self.rescale_to_fit(height, 1, stretch = False, **kwargs)
|
||||||
|
|
||||||
def scale_to_fit_depth(self, depth):
|
def scale_to_fit_depth(self, depth, **kwargs):
|
||||||
return self.rescale_to_fit(depth, 2, stretch = False)
|
return self.rescale_to_fit(depth, 2, stretch = False, **kwargs)
|
||||||
|
|
||||||
def space_out_submobjects(self, factor = 1.5, **kwargs):
|
def space_out_submobjects(self, factor = 1.5, **kwargs):
|
||||||
self.scale_in_place(factor)
|
self.scale(factor, **kwargs)
|
||||||
for submob in self.submobjects:
|
for submob in self.submobjects:
|
||||||
submob.scale_in_place(1./factor)
|
submob.scale(1./factor)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def move_to(self, point_or_mobject, aligned_edge = ORIGIN):
|
def move_to(self, point_or_mobject, aligned_edge = ORIGIN):
|
||||||
|
@ -521,11 +529,7 @@ class Mobject(object):
|
||||||
sm1.interpolate(sm1, sm2, 1)
|
sm1.interpolate(sm1, sm2, 1)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def apply_complex_function(self, function, **kwargs):
|
##
|
||||||
return self.apply_function(
|
|
||||||
lambda (x, y, z) : complex_to_R3(function(complex(x, y))),
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
def reduce_across_dimension(self, points_func, reduce_func, dim):
|
def reduce_across_dimension(self, points_func, reduce_func, dim):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue