2022-02-15 18:39:45 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.animation.animation import Animation
|
2022-04-12 19:19:59 +08:00
|
|
|
from manimlib.constants import ORIGIN, OUT
|
|
|
|
from manimlib.constants import PI, TAU
|
2019-02-05 15:39:58 -08:00
|
|
|
from manimlib.utils.rate_functions import linear
|
2020-02-21 12:00:50 -08:00
|
|
|
from manimlib.utils.rate_functions import smooth
|
2018-03-31 15:11:35 -07:00
|
|
|
|
2022-02-15 18:39:45 +08:00
|
|
|
from typing import TYPE_CHECKING
|
2022-02-16 21:08:25 +08:00
|
|
|
|
2022-02-15 18:39:45 +08:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
import numpy as np
|
2022-12-14 15:08:20 -08:00
|
|
|
from typing import Callable
|
2022-02-15 18:39:45 +08:00
|
|
|
from manimlib.mobject.mobject import Mobject
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 15:11:35 -07:00
|
|
|
class Rotating(Animation):
|
2022-02-15 18:39:45 +08:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
mobject: Mobject,
|
|
|
|
angle: float = TAU,
|
|
|
|
axis: np.ndarray = OUT,
|
2022-12-14 15:08:20 -08:00
|
|
|
about_point: np.ndarray | None = None,
|
|
|
|
about_edge: np.ndarray | None = None,
|
|
|
|
run_time: float = 5.0,
|
|
|
|
rate_func: Callable[[float], float] = linear,
|
|
|
|
suspend_mobject_updating: bool = False,
|
2022-02-15 18:39:45 +08:00
|
|
|
**kwargs
|
|
|
|
):
|
2020-02-21 12:00:50 -08:00
|
|
|
self.angle = angle
|
|
|
|
self.axis = axis
|
2022-12-14 15:08:20 -08:00
|
|
|
self.about_point = about_point
|
|
|
|
self.about_edge = about_edge
|
|
|
|
super().__init__(
|
|
|
|
mobject,
|
|
|
|
run_time=run_time,
|
|
|
|
rate_func=rate_func,
|
|
|
|
suspend_mobject_updating=suspend_mobject_updating,
|
|
|
|
**kwargs
|
|
|
|
)
|
2020-02-21 12:00:50 -08:00
|
|
|
|
2022-02-15 18:39:45 +08:00
|
|
|
def interpolate_mobject(self, alpha: float) -> None:
|
2023-01-05 08:29:59 -05:00
|
|
|
pairs = zip(
|
|
|
|
self.mobject.family_members_with_points(),
|
|
|
|
self.starting_mobject.family_members_with_points(),
|
|
|
|
)
|
|
|
|
for sm1, sm2 in pairs:
|
2023-01-15 18:01:37 -08:00
|
|
|
for key in sm1.pointlike_data_keys:
|
|
|
|
sm1.data[key][:] = sm2.data[key]
|
2018-03-31 15:11:35 -07:00
|
|
|
self.mobject.rotate(
|
2022-11-18 09:07:33 -08:00
|
|
|
self.rate_func(alpha) * self.angle,
|
2018-04-06 13:58:59 -07:00
|
|
|
axis=self.axis,
|
|
|
|
about_point=self.about_point,
|
|
|
|
about_edge=self.about_edge,
|
2018-03-31 15:11:35 -07:00
|
|
|
)
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2020-02-21 12:00:50 -08:00
|
|
|
class Rotate(Rotating):
|
2022-02-15 18:39:45 +08:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
mobject: Mobject,
|
|
|
|
angle: float = PI,
|
|
|
|
axis: np.ndarray = OUT,
|
2022-12-14 15:08:20 -08:00
|
|
|
run_time: float = 1,
|
|
|
|
rate_func: Callable[[float], float] = smooth,
|
|
|
|
about_edge: np.ndarray = ORIGIN,
|
2022-02-15 18:39:45 +08:00
|
|
|
**kwargs
|
|
|
|
):
|
2022-12-14 15:08:20 -08:00
|
|
|
super().__init__(
|
|
|
|
mobject, angle, axis,
|
|
|
|
run_time=run_time,
|
|
|
|
rate_func=rate_func,
|
|
|
|
about_edge=about_edge,
|
|
|
|
**kwargs
|
|
|
|
)
|