2022-02-15 18:39:45 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from manimlib.animation.transform import Transform
|
|
|
|
|
|
|
|
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-04-12 19:19:59 +08:00
|
|
|
|
2022-02-15 18:39:45 +08:00
|
|
|
from manimlib.mobject.geometry import Arrow
|
2022-04-12 19:19:59 +08:00
|
|
|
from manimlib.mobject.mobject import Mobject
|
2022-12-16 20:19:18 -08:00
|
|
|
from manimlib.typing import ManimColor
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
class GrowFromPoint(Transform):
|
2022-12-14 12:08:18 -08:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
mobject: Mobject,
|
|
|
|
point: np.ndarray,
|
|
|
|
point_color: ManimColor = None,
|
|
|
|
**kwargs
|
|
|
|
):
|
2019-02-09 10:21:14 -08:00
|
|
|
self.point = point
|
2022-12-14 12:08:18 -08:00
|
|
|
self.point_color = point_color
|
2019-02-09 10:21:14 -08:00
|
|
|
super().__init__(mobject, **kwargs)
|
|
|
|
|
2022-02-15 18:39:45 +08:00
|
|
|
def create_target(self) -> Mobject:
|
2023-02-02 15:36:58 -08:00
|
|
|
return self.mobject.copy()
|
2019-02-09 10:21:14 -08:00
|
|
|
|
2022-02-15 18:39:45 +08:00
|
|
|
def create_starting_mobject(self) -> Mobject:
|
2019-02-09 10:21:14 -08:00
|
|
|
start = super().create_starting_mobject()
|
|
|
|
start.scale(0)
|
|
|
|
start.move_to(self.point)
|
2022-12-14 12:08:18 -08:00
|
|
|
if self.point_color is not None:
|
2019-02-09 10:21:14 -08:00
|
|
|
start.set_color(self.point_color)
|
|
|
|
return start
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
class GrowFromCenter(GrowFromPoint):
|
2022-02-15 18:39:45 +08:00
|
|
|
def __init__(self, mobject: Mobject, **kwargs):
|
2019-02-09 10:21:14 -08:00
|
|
|
point = mobject.get_center()
|
|
|
|
super().__init__(mobject, point, **kwargs)
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
class GrowFromEdge(GrowFromPoint):
|
2022-02-15 18:39:45 +08:00
|
|
|
def __init__(self, mobject: Mobject, edge: np.ndarray, **kwargs):
|
2020-02-13 10:54:09 -08:00
|
|
|
point = mobject.get_bounding_box_point(edge)
|
2019-02-09 10:21:14 -08:00
|
|
|
super().__init__(mobject, point, **kwargs)
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
class GrowArrow(GrowFromPoint):
|
2022-02-15 18:39:45 +08:00
|
|
|
def __init__(self, arrow: Arrow, **kwargs):
|
2019-02-09 10:21:14 -08:00
|
|
|
point = arrow.get_start()
|
|
|
|
super().__init__(arrow, point, **kwargs)
|