From 15d8ebb572231d6d546946e29cd322cca9c70493 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Mon, 30 Jan 2023 11:53:15 -0800 Subject: [PATCH] Add Mobject.set_shape --- manimlib/mobject/mobject.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/manimlib/mobject/mobject.py b/manimlib/mobject/mobject.py index d1fb0410..32a113f7 100644 --- a/manimlib/mobject/mobject.py +++ b/manimlib/mobject/mobject.py @@ -48,7 +48,7 @@ from manimlib.utils.space_ops import rotation_matrix_transpose from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import Callable, Iterable, Union, Tuple + from typing import Callable, Iterable, Union, Tuple, Optional import numpy.typing as npt from manimlib.typing import ManimColor, Vect3, Vect4, Vect3Array, UniformDict from moderngl.context import Context @@ -1168,6 +1168,21 @@ class Mobject(object): self.set_depth(min_depth, **kwargs) return self + def set_shape( + self, + width: Optional[float] = None, + height: Optional[float] = None, + depth: Optional[float] = None, + **kwargs + ): + if width is not None: + self.set_width(width, stretch=True, **kwargs) + if height is not None: + self.set_height(height, stretch=True, **kwargs) + if depth is not None: + self.set_depth(depth, stretch=True, **kwargs) + return self + def set_coord(self, value: float, dim: int, direction: Vect3 = ORIGIN): curr = self.get_coord(dim, direction) shift_vect = np.zeros(self.dim)