datacut 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. datacut/__init__.py +121 -0
  2. datacut/__main__.py +122 -0
  3. datacut/animation/__init__.py +0 -0
  4. datacut/animation/animation.py +336 -0
  5. datacut/animation/composition.py +258 -0
  6. datacut/animation/creation.py +315 -0
  7. datacut/animation/fading.py +328 -0
  8. datacut/animation/growing.py +90 -0
  9. datacut/animation/indication.py +608 -0
  10. datacut/animation/movement.py +165 -0
  11. datacut/animation/numbers.py +92 -0
  12. datacut/animation/physics.py +453 -0
  13. datacut/animation/rotation.py +95 -0
  14. datacut/animation/specialized.py +956 -0
  15. datacut/animation/transform.py +505 -0
  16. datacut/animation/transform_matching_parts.py +343 -0
  17. datacut/animation/update.py +95 -0
  18. datacut/camera/__init__.py +0 -0
  19. datacut/camera/camera.py +795 -0
  20. datacut/camera/camera_frame.py +320 -0
  21. datacut/camera/cinematography.py +1166 -0
  22. datacut/config.py +479 -0
  23. datacut/constants.py +160 -0
  24. datacut/css/__init__.py +189 -0
  25. datacut/css/easing.py +328 -0
  26. datacut/css/engine.py +1727 -0
  27. datacut/css/gradients.py +678 -0
  28. datacut/css/motion.py +1615 -0
  29. datacut/css/parser.py +741 -0
  30. datacut/css/presets.py +143 -0
  31. datacut/css/shader_fill.py +703 -0
  32. datacut/css/values.py +650 -0
  33. datacut/default_config.yml +224 -0
  34. datacut/event_handler/__init__.py +6 -0
  35. datacut/event_handler/event_dispatcher.py +161 -0
  36. datacut/event_handler/event_listner.py +31 -0
  37. datacut/event_handler/event_type.py +11 -0
  38. datacut/event_handler/picking.py +111 -0
  39. datacut/event_keys.py +53 -0
  40. datacut/extract_scene.py +200 -0
  41. datacut/layout/__init__.py +39 -0
  42. datacut/layout/components.py +425 -0
  43. datacut/layout/containers.py +1520 -0
  44. datacut/logger.py +13 -0
  45. datacut/mobject/__init__.py +0 -0
  46. datacut/mobject/boolean_ops.py +168 -0
  47. datacut/mobject/changing.py +209 -0
  48. datacut/mobject/coordinate_systems.py +1056 -0
  49. datacut/mobject/fractals.py +348 -0
  50. datacut/mobject/frame.py +80 -0
  51. datacut/mobject/functions.py +147 -0
  52. datacut/mobject/geometry.py +1834 -0
  53. datacut/mobject/gltf.py +243 -0
  54. datacut/mobject/interactive.py +906 -0
  55. datacut/mobject/lights.py +366 -0
  56. datacut/mobject/materials.py +207 -0
  57. datacut/mobject/matrix.py +570 -0
  58. datacut/mobject/mesh3d.py +2288 -0
  59. datacut/mobject/mobject.py +2885 -0
  60. datacut/mobject/mobject_update_utils.py +123 -0
  61. datacut/mobject/model.py +543 -0
  62. datacut/mobject/number_line.py +517 -0
  63. datacut/mobject/numbers.py +441 -0
  64. datacut/mobject/probability.py +536 -0
  65. datacut/mobject/shape_matchers.py +161 -0
  66. datacut/mobject/subtitles.py +260 -0
  67. datacut/mobject/svg/__init__.py +0 -0
  68. datacut/mobject/svg/brace.py +356 -0
  69. datacut/mobject/svg/drawings.py +1041 -0
  70. datacut/mobject/svg/old_tex_mobject.py +335 -0
  71. datacut/mobject/svg/path_cache.py +155 -0
  72. datacut/mobject/svg/special_tex.py +216 -0
  73. datacut/mobject/svg/string_mobject.py +622 -0
  74. datacut/mobject/svg/svg_mobject.py +657 -0
  75. datacut/mobject/svg/svg_parse.py +437 -0
  76. datacut/mobject/svg/tex_mobject.py +499 -0
  77. datacut/mobject/svg/text_mobject.py +702 -0
  78. datacut/mobject/svg/typst_mobject.py +864 -0
  79. datacut/mobject/three_dimensions.py +686 -0
  80. datacut/mobject/types/__init__.py +0 -0
  81. datacut/mobject/types/dot_cloud.py +220 -0
  82. datacut/mobject/types/image_mobject.py +130 -0
  83. datacut/mobject/types/point_cloud_mobject.py +138 -0
  84. datacut/mobject/types/shader_mobject.py +268 -0
  85. datacut/mobject/types/surface.py +848 -0
  86. datacut/mobject/types/vectorized_mobject.py +1749 -0
  87. datacut/mobject/types/video_mobject.py +3902 -0
  88. datacut/mobject/value_tracker.py +110 -0
  89. datacut/mobject/vector_field.py +585 -0
  90. datacut/module_loader.py +176 -0
  91. datacut/reactive/__init__.py +25 -0
  92. datacut/reactive/signals.py +610 -0
  93. datacut/renderer/__init__.py +4 -0
  94. datacut/renderer/drawing.py +1066 -0
  95. datacut/renderer/gpu.py +800 -0
  96. datacut/renderer/material.py +88 -0
  97. datacut/renderer/pipeline.py +179 -0
  98. datacut/renderer/post_process.py +577 -0
  99. datacut/renderer/renderer.py +1285 -0
  100. datacut/renderer/shader_source.py +146 -0
  101. datacut/renderer/shared_buffer.py +185 -0
  102. datacut/renderer/texture.py +217 -0
  103. datacut/renderer/uniform_block.py +118 -0
  104. datacut/scene/__init__.py +0 -0
  105. datacut/scene/incremental.py +233 -0
  106. datacut/scene/interactive_scene.py +758 -0
  107. datacut/scene/performance.py +226 -0
  108. datacut/scene/presentation_scene.py +783 -0
  109. datacut/scene/recording.py +541 -0
  110. datacut/scene/safe_zones.py +323 -0
  111. datacut/scene/scene.py +2849 -0
  112. datacut/scene/scene_embed.py +277 -0
  113. datacut/scene/scene_file_writer.py +1014 -0
  114. datacut/scene/scene_task.py +183 -0
  115. datacut/scene/sfx.py +164 -0
  116. datacut/scene/sound.py +702 -0
  117. datacut/scene/sound_clip.py +580 -0
  118. datacut/scene/timeline.py +1689 -0
  119. datacut/scene/transcript.py +503 -0
  120. datacut/shaders/fill.wgsl +107 -0
  121. datacut/shaders/fill_depth.wgsl +198 -0
  122. datacut/shaders/image.wgsl +25 -0
  123. datacut/shaders/inserts/NOTE.md +16 -0
  124. datacut/shaders/inserts/clip_test.wgsl +14 -0
  125. datacut/shaders/inserts/complex_functions.wgsl +20 -0
  126. datacut/shaders/inserts/fill_color.wgsl +10 -0
  127. datacut/shaders/inserts/finalize_color.wgsl +44 -0
  128. datacut/shaders/inserts/frame_uniforms.wgsl +37 -0
  129. datacut/shaders/inserts/frame_units.wgsl +18 -0
  130. datacut/shaders/inserts/image_quad.wgsl +28 -0
  131. datacut/shaders/inserts/mobject_uniforms.wgsl +11 -0
  132. datacut/shaders/inserts/project_point.wgsl +44 -0
  133. datacut/shaders/inserts/quad_corners.wgsl +12 -0
  134. datacut/shaders/inserts/read_data.wgsl +33 -0
  135. datacut/shaders/inserts/surface_mesh.wgsl +106 -0
  136. datacut/shaders/mandelbrot_fractal.wgsl +100 -0
  137. datacut/shaders/mesh.wgsl +474 -0
  138. datacut/shaders/newton_fractal.wgsl +200 -0
  139. datacut/shaders/present.wgsl +62 -0
  140. datacut/shaders/stroke.wgsl +1141 -0
  141. datacut/shaders/stroke_depth.wgsl +1136 -0
  142. datacut/shaders/surface.wgsl +40 -0
  143. datacut/shaders/textured_surface.wgsl +59 -0
  144. datacut/shaders/true_dot.wgsl +78 -0
  145. datacut/shaders/video.wgsl +42 -0
  146. datacut/tex_templates.yml +736 -0
  147. datacut/transcribe.py +32 -0
  148. datacut/typing.py +412 -0
  149. datacut/utils/__init__.py +0 -0
  150. datacut/utils/bezier.py +467 -0
  151. datacut/utils/browser_audio.py +423 -0
  152. datacut/utils/browser_code_transform.py +1293 -0
  153. datacut/utils/browser_completions.py +2255 -0
  154. datacut/utils/browser_fonts.py +143 -0
  155. datacut/utils/browser_pathops.py +47 -0
  156. datacut/utils/browser_scheduler.py +18 -0
  157. datacut/utils/browser_typst.py +82 -0
  158. datacut/utils/cache.py +34 -0
  159. datacut/utils/cinematic_vfx.py +779 -0
  160. datacut/utils/color.py +203 -0
  161. datacut/utils/debug.py +46 -0
  162. datacut/utils/dict_ops.py +22 -0
  163. datacut/utils/directories.py +55 -0
  164. datacut/utils/editor_signatures.py +1806 -0
  165. datacut/utils/editor_thumbnails.py +769 -0
  166. datacut/utils/family_ops.py +48 -0
  167. datacut/utils/file_ops.py +65 -0
  168. datacut/utils/images.py +52 -0
  169. datacut/utils/iterables.py +216 -0
  170. datacut/utils/native.py +280 -0
  171. datacut/utils/paths.py +83 -0
  172. datacut/utils/rate_functions.py +154 -0
  173. datacut/utils/render_geometry.py +186 -0
  174. datacut/utils/simple_functions.py +99 -0
  175. datacut/utils/sounds.py +43 -0
  176. datacut/utils/space_ops.py +460 -0
  177. datacut/utils/structured_array.py +256 -0
  178. datacut/utils/svg_export.py +102 -0
  179. datacut/utils/tex.py +139 -0
  180. datacut/utils/tex_file_writing.py +164 -0
  181. datacut/utils/tex_to_symbol_count.py +186 -0
  182. datacut/utils/typst_file_writing.py +205 -0
  183. datacut/utils/vfx_presets.py +4543 -0
  184. datacut/utils/visual_css.py +737 -0
  185. datacut/utils/visual_editor.py +4292 -0
  186. datacut/utils/window_audio.py +760 -0
  187. datacut/window.py +910 -0
  188. datacut-0.1.0.dist-info/METADATA +226 -0
  189. datacut-0.1.0.dist-info/RECORD +193 -0
  190. datacut-0.1.0.dist-info/WHEEL +5 -0
  191. datacut-0.1.0.dist-info/entry_points.txt +2 -0
  192. datacut-0.1.0.dist-info/licenses/LICENSE.md +21 -0
  193. datacut-0.1.0.dist-info/top_level.txt +1 -0
datacut/__init__.py ADDED
@@ -0,0 +1,121 @@
1
+ import sys
2
+
3
+ try:
4
+ from importlib.metadata import version, PackageNotFoundError
5
+ except ImportError: # For Python <3.8 fallback
6
+ from importlib_metadata import version, PackageNotFoundError # type: ignore
7
+
8
+ try:
9
+ __version__ = version("datacut")
10
+ except PackageNotFoundError:
11
+ __version__ = "unknown"
12
+
13
+
14
+ from datacut.config import manim_config
15
+
16
+ from typing import TYPE_CHECKING
17
+
18
+ if TYPE_CHECKING:
19
+ from datacut.typing import *
20
+
21
+ from datacut.constants import *
22
+
23
+ from datacut.window import *
24
+
25
+ # The browser-only scene runner is intentionally absent on native platforms.
26
+ if sys.platform == "emscripten":
27
+ from datacut.window import run_scene_from_class
28
+
29
+ from datacut.animation.animation import *
30
+ from datacut.animation.composition import *
31
+ from datacut.animation.creation import *
32
+ from datacut.animation.fading import *
33
+ from datacut.animation.growing import *
34
+ from datacut.animation.indication import *
35
+ from datacut.animation.movement import *
36
+ from datacut.animation.numbers import *
37
+ from datacut.animation.physics import *
38
+ from datacut.animation.rotation import *
39
+ from datacut.animation.specialized import *
40
+ from datacut.animation.transform import *
41
+ from datacut.animation.transform_matching_parts import *
42
+ from datacut.animation.update import *
43
+
44
+ from datacut.camera.camera import *
45
+ from datacut.camera.cinematography import CameraPath, KeyframePath, DepthOfField, Haze, RotationalBlur, CameraShake
46
+
47
+ from datacut.mobject.boolean_ops import *
48
+ from datacut.mobject.changing import *
49
+ from datacut.mobject.coordinate_systems import *
50
+ from datacut.mobject.fractals import *
51
+ from datacut.mobject.frame import *
52
+ from datacut.mobject.functions import *
53
+ from datacut.mobject.geometry import *
54
+ from datacut.mobject.interactive import *
55
+ from datacut.mobject.matrix import *
56
+ from datacut.mobject.mobject import *
57
+ from datacut.mobject.mobject_update_utils import *
58
+ from datacut.mobject.number_line import *
59
+ from datacut.mobject.numbers import *
60
+ from datacut.mobject.probability import *
61
+ from datacut.mobject.shape_matchers import *
62
+ from datacut.mobject.subtitles import *
63
+ from datacut.mobject.svg.brace import *
64
+ from datacut.mobject.svg.drawings import *
65
+ from datacut.mobject.svg.string_mobject import *
66
+ from datacut.mobject.svg.svg_mobject import *
67
+ from datacut.mobject.svg.special_tex import *
68
+ from datacut.mobject.svg.tex_mobject import *
69
+ from datacut.mobject.svg.text_mobject import *
70
+ from datacut.mobject.svg.typst_mobject import *
71
+ from datacut.mobject.three_dimensions import *
72
+ from datacut.mobject.types.dot_cloud import *
73
+ from datacut.mobject.types.image_mobject import *
74
+ from datacut.mobject.types.point_cloud_mobject import *
75
+ from datacut.mobject.types.shader_mobject import *
76
+ from datacut.mobject.types.surface import *
77
+ from datacut.mobject.types.video_mobject import *
78
+ from datacut.mobject.types.vectorized_mobject import *
79
+ from datacut.mobject.value_tracker import *
80
+ from datacut.mobject.vector_field import *
81
+ from datacut.mobject.mesh3d import *
82
+ from datacut.mobject.materials import *
83
+ from datacut.mobject.lights import *
84
+ from datacut.mobject.model import *
85
+
86
+ from datacut.scene.interactive_scene import *
87
+ from datacut.scene.presentation_scene import *
88
+ from datacut.scene.scene import *
89
+ from datacut.scene.safe_zones import *
90
+ from datacut.scene.sound import *
91
+ from datacut.scene.sfx import *
92
+ from datacut.scene.transcript import *
93
+ from datacut.scene.scene_task import *
94
+
95
+ from datacut.renderer.shader_source import get_colormap_code
96
+ from datacut.renderer.uniform_block import *
97
+
98
+ from datacut.utils.vfx_presets import *
99
+ from datacut.utils.browser_fonts import *
100
+ from datacut.utils.bezier import *
101
+ from datacut.utils.cache import *
102
+ from datacut.utils.color import *
103
+ from datacut.utils.dict_ops import *
104
+ from datacut.utils.debug import *
105
+ from datacut.utils.directories import *
106
+ from datacut.utils.file_ops import *
107
+ from datacut.utils.images import *
108
+ from datacut.utils.iterables import *
109
+ from datacut.utils.paths import *
110
+ from datacut.utils.rate_functions import *
111
+ from datacut.utils.simple_functions import *
112
+ from datacut.utils.sounds import *
113
+ from datacut.utils.space_ops import *
114
+ from datacut.utils.svg_export import *
115
+ from datacut.utils.tex import *
116
+
117
+ from datacut.reactive import *
118
+ from datacut.css import *
119
+ from datacut.layout import *
120
+
121
+
datacut/__main__.py ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env python
2
+ from addict import Dict
3
+
4
+ from datacut import __version__
5
+ from datacut.config import manim_config
6
+ from datacut.config import parse_cli
7
+ import datacut.extract_scene
8
+ from datacut.utils.cache import clear_cache
9
+ from datacut.window import Window
10
+
11
+
12
+ from IPython.terminal.embed import KillEmbedded
13
+
14
+ import os
15
+ import sys
16
+ import time
17
+ import traceback
18
+
19
+ from datacut.logger import log
20
+ from datacut.scene.scene import ReloadScene
21
+
22
+ sys.path.insert(0, os.getcwd())
23
+
24
+ from typing import TYPE_CHECKING
25
+ if TYPE_CHECKING:
26
+ from argparse import Namespace
27
+
28
+
29
+ def run_scenes():
30
+ """
31
+ Runs the scenes in a loop and detects when a scene reload is requested.
32
+ """
33
+ # Create a new dict to be able to upate without
34
+ # altering global configuration
35
+ scene_config = Dict(manim_config.scene)
36
+ run_config = manim_config.run
37
+
38
+ if run_config.show_in_window:
39
+ # Create a reusable window
40
+ window = Window(**manim_config.window)
41
+ scene_config.update(window=window)
42
+
43
+ scene = None
44
+ while True:
45
+ try:
46
+ # Blocking call since a scene may init an IPython shell()
47
+ scenes = datacut.extract_scene.main(scene_config, run_config)
48
+ for scene in scenes:
49
+ scene.run()
50
+ return
51
+ except KillEmbedded:
52
+ # Requested via the `exit_raise` IPython runline magic
53
+ # by means of the reload_scene() command, which starts over
54
+ scene_config.update(resume_time=None, resume_view=None)
55
+ except ReloadScene as reload:
56
+ # The scene's file was saved, see Scene.check_hot_reload: made again, carrying on
57
+ # from where this one had got to
58
+ reload.scene.release_for_reload()
59
+ run_config.is_reload = True
60
+ scene_config.update(resume_time=reload.resume_time, resume_view=reload.resume_view)
61
+ except KeyboardInterrupt:
62
+ break
63
+ except Exception:
64
+ # A scene made again from its file which fails is shown as failing, and made
65
+ # again when the file is next saved, rather than closing the window
66
+ if scene_config.get("resume_time") is None or scene_config.get("window") is None:
67
+ raise
68
+ traceback.print_exc()
69
+ log.error("The scene failed. Fix it and save: it is made again then")
70
+ if scene is not None:
71
+ scene.release_for_reload()
72
+ if not wait_for_change(scene_config.window, run_config.file_name):
73
+ return
74
+ run_config.is_reload = True
75
+
76
+
77
+ def wait_for_change(window: Window, path: str) -> bool:
78
+ """
79
+ Keeps the window answering until the file is saved again so as to compile, True then,
80
+ or until the window is closed, False
81
+ """
82
+ try:
83
+ mtime = os.path.getmtime(path)
84
+ except OSError:
85
+ return False
86
+ while not window.is_closing:
87
+ window.poll_events()
88
+ time.sleep(0.1)
89
+ try:
90
+ new_mtime = os.path.getmtime(path)
91
+ except OSError:
92
+ continue
93
+ if new_mtime == mtime:
94
+ continue
95
+ mtime = new_mtime
96
+ try:
97
+ with open(path, encoding="utf-8") as file:
98
+ compile(file.read(), path, "exec")
99
+ except SyntaxError as error:
100
+ log.error(f"Not reloaded: {path}, line {error.lineno}: {error.msg}")
101
+ continue
102
+ return True
103
+ return False
104
+
105
+
106
+ def main():
107
+ """
108
+ Main entry point for DataCut.
109
+ """
110
+ print(f"DataCut \033[32mv{__version__}\033[0m")
111
+
112
+ args = parse_cli()
113
+ if args.version and args.file is None:
114
+ return
115
+ if args.clear_cache:
116
+ clear_cache()
117
+
118
+ run_scenes()
119
+
120
+
121
+ if __name__ == "__main__":
122
+ main()
File without changes
@@ -0,0 +1,336 @@
1
+ from __future__ import annotations
2
+
3
+ # What the Visual Editor files this module's classes under
4
+ __editor_category__ = 'Composition'
5
+
6
+ from copy import deepcopy
7
+ import inspect
8
+
9
+ from datacut.mobject.mobject import _AnimationBuilder
10
+ from datacut.mobject.mobject import Mobject
11
+ from datacut.utils.iterables import remove_list_redundancies
12
+ from datacut.utils.rate_functions import smooth
13
+ from datacut.utils.simple_functions import clip
14
+ from datacut.typing import Duration, UnsignedInt
15
+
16
+ from typing import TYPE_CHECKING
17
+
18
+ if TYPE_CHECKING:
19
+ from datacut.typing import Duration, Proportion, RateFunction
20
+ from typing import Callable
21
+
22
+ from datacut.scene.scene import Scene
23
+
24
+
25
+ DEFAULT_ANIMATION_RUN_TIME = 1.0
26
+ DEFAULT_ANIMATION_LAG_RATIO = 0
27
+
28
+
29
+ class Animation(object):
30
+ def __init__(
31
+ self,
32
+ mobject: Mobject,
33
+ run_time: Duration = DEFAULT_ANIMATION_RUN_TIME,
34
+ # Tuple of times, between which the animation will run
35
+ time_span: tuple[float, float] | None = None,
36
+ # If 0, the animation is applied to all submobjects at the same time
37
+ # If 1, it is applied to each successively.
38
+ # If 0 < lag_ratio < 1, its applied to each with lagged start times
39
+ lag_ratio: Proportion = DEFAULT_ANIMATION_LAG_RATIO,
40
+ rate_func: RateFunction = smooth,
41
+ name: str = "",
42
+ # Does this animation add or remove a mobject from the screen
43
+ remover: bool = False,
44
+ # What to enter into the update function upon completion
45
+ final_alpha_value: float = 1.0,
46
+ # If set to True, the mobject itself will have its internal updaters called,
47
+ # but the start or target mobjects would not be suspended. To completely suspend
48
+ # updating, call mobject.suspend_updating() before the animation
49
+ suspend_mobject_updating: bool = False,
50
+ ):
51
+ self._validate_input_type(mobject)
52
+ self.mobject = mobject
53
+ self.run_time = run_time
54
+ self.time_span = time_span
55
+ self.rate_func = rate_func
56
+ self.name = name or self.__class__.__name__ + str(self.mobject)
57
+ # Named by whoever made it, rather than after its kind, which is what a scene's
58
+ # timeline calls the play it is in, see Scene._animations_label
59
+ self.has_given_name = bool(name)
60
+ self.remover = remover
61
+ self.final_alpha_value = final_alpha_value
62
+ self.lag_ratio = lag_ratio
63
+ self.suspend_mobject_updating = suspend_mobject_updating
64
+
65
+ def _validate_input_type(self, mobject: Mobject) -> None:
66
+ if not isinstance(mobject, Mobject):
67
+ raise TypeError("Animation only works for Mobjects.")
68
+
69
+ def __str__(self) -> str:
70
+ return self.name
71
+
72
+ @classmethod
73
+ async def create(cls, *args, **kwargs):
74
+ """Asynchronously construct an animation and any awaited arguments."""
75
+ args = await resolve_async(args)
76
+ kwargs = await resolve_async(kwargs)
77
+ return cls(*args, **kwargs)
78
+
79
+ def begin(self) -> None:
80
+ # This is called right as an animation is being
81
+ # played. As much initialization as possible,
82
+ # especially any mobject copying, should live in
83
+ # this method
84
+ if self.time_span is not None:
85
+ start, end = self.time_span
86
+ self.run_time = max(end, self.run_time)
87
+ self.mobject.set_animating_status(True)
88
+ self.starting_mobject = self.create_starting_mobject()
89
+ if self.suspend_mobject_updating:
90
+ self.mobject_was_updating = not self.mobject.updating_suspended
91
+ self.mobject.suspend_updating()
92
+ self.families = list(self.get_all_families_zipped())
93
+ self.prepare_interpolation()
94
+ self.interpolate(0)
95
+
96
+ def prepare_interpolation(self) -> None:
97
+ """
98
+ Whatever holds of the two ends for the whole of the animation, settled here rather
99
+ than found again in every blend, see Mobject.prepare_interpolation.
100
+
101
+ One which changes its ends after they have been made says so by calling this again,
102
+ see FadeTransform.
103
+ """
104
+ ends = self.get_interpolation_ends()
105
+ if ends is not None:
106
+ self.mobject.prepare_interpolation(*ends)
107
+ # The alpha each family was last put at, see interpolate_mobject
108
+ self.last_sub_alphas = [None] * len(self.families)
109
+
110
+ def get_interpolation_ends(self) -> tuple[Mobject, Mobject] | None:
111
+ """
112
+ The two states every blend this animation makes runs between, in the order it blends
113
+ them, or none where it makes no such blend and so has nothing to settle in advance.
114
+
115
+ Saying so is the animation's to do rather than something read off the mobjects it
116
+ gathers: those same three may be two ends with the mobject between them, or a mobject
117
+ and two others put to some other use entirely.
118
+ """
119
+ return None
120
+
121
+ def finish(self) -> None:
122
+ self.interpolate(self.final_alpha_value)
123
+ self.mobject.turn_off_interpolation_skip()
124
+ self.mobject.set_animating_status(False)
125
+ if self.suspend_mobject_updating and self.mobject_was_updating:
126
+ self.mobject.resume_updating()
127
+
128
+ def clean_up_from_scene(self, scene: Scene) -> None:
129
+ if self.is_remover():
130
+ for mob in self.mobject.get_family():
131
+ if getattr(mob, "_sync_volume_with_opacity", False):
132
+ mob._record_audio_opacity(0.0)
133
+ scene.remove(self.mobject)
134
+
135
+ def create_starting_mobject(self) -> Mobject:
136
+ # Keep track of where the mobject starts
137
+ return self.mobject.copy()
138
+
139
+ def get_all_mobjects(self) -> tuple[Mobject, Mobject]:
140
+ """
141
+ Ordering must match the ording of arguments to interpolate_submobject
142
+ """
143
+ return self.mobject, self.starting_mobject
144
+
145
+ def get_all_families_zipped(self) -> zip[tuple[Mobject]]:
146
+ return zip(*[
147
+ mob.get_family()
148
+ for mob in self.get_all_mobjects()
149
+ ])
150
+
151
+ def update_reference_mobjects(self, dt: float, frame_rate: float | None = None) -> None:
152
+ """
153
+ Updates things like starting_mobject, and (for
154
+ Transforms) target_mobject.
155
+ """
156
+ for mob in self.get_reference_mobjects():
157
+ mob.update(dt, frame_rate=frame_rate)
158
+
159
+ def get_reference_mobjects(self) -> list[Mobject]:
160
+ """
161
+ Returns mobjects the Animation tracks other than
162
+ self.mobject, e.g. the start and end points of
163
+ interpolation.
164
+ """
165
+ # Remove redundancies for cases like Transform where target and target_copy
166
+ # are the same, which happens when the already align.
167
+ return remove_list_redundancies([
168
+ mob for mob in self.get_all_mobjects()
169
+ if mob is not self.mobject
170
+ ])
171
+
172
+ def copy(self):
173
+ return deepcopy(self)
174
+
175
+ def update_rate_info(
176
+ self,
177
+ run_time: Duration | None = None,
178
+ rate_func: Callable[[float], float] | None = None,
179
+ lag_ratio: float | None = None,
180
+ ):
181
+ self.run_time = run_time or self.run_time
182
+ self.rate_func = rate_func or self.rate_func
183
+ self.lag_ratio = lag_ratio or self.lag_ratio
184
+ return self
185
+
186
+ # Methods for interpolation, the mean of an Animation
187
+ def interpolate(self, alpha: float) -> None:
188
+ self.interpolate_mobject(alpha)
189
+
190
+ def update(self, alpha: float) -> None:
191
+ """
192
+ This method shouldn't exist, but it's here to
193
+ keep many old scenes from breaking
194
+ """
195
+ self.interpolate(alpha)
196
+
197
+ def time_spanned_alpha(self, alpha: float) -> float:
198
+ if self.time_span is not None:
199
+ start, end = self.time_span
200
+ return clip(alpha * self.run_time - start, 0, end - start) / (end - start)
201
+ return alpha
202
+
203
+ def interpolate_mobject(self, alpha: float) -> None:
204
+ t_alpha = self.time_spanned_alpha(alpha)
205
+ n_families = len(self.families)
206
+ if self.lag_ratio == 0:
207
+ sub_alpha = self.rate_func(clip(t_alpha, 0, 1))
208
+ for mobs in self.families:
209
+ self.interpolate_submobject(*mobs, sub_alpha)
210
+ else:
211
+ # A family put at the alpha it was already put at would be put back just where
212
+ # it is: interpolate_submobject works out each from its two ends rather than from
213
+ # where it last was. With a lag across many families, most are at one end or the
214
+ # other most of the time, waiting to start or done, so this is most of them.
215
+ # Only so long as nothing but this animation moves the mobject in between, which
216
+ # an updater running on it would
217
+ last = getattr(self, "last_sub_alphas", None)
218
+ if self.mobject.has_updaters() and not self.suspend_mobject_updating:
219
+ last = None
220
+ self.last_sub_alphas = [None] * n_families
221
+ elif last is None or len(last) != n_families:
222
+ last = self.last_sub_alphas = [None] * n_families
223
+ # Nor so long as another family of this animation moves it. The families are a
224
+ # mobject's family in order, so each member's own family comes right after it,
225
+ # and one putting its submobject in place may move all of those too, as become
226
+ # and shift do. So every family after one put in place, up to the end of what
227
+ # its submobject holds, is put in place again after it, as it would have been
228
+ # with none of them passed over.
229
+ spans = self.get_family_spans() if last is not None else None
230
+ redo_through = -1
231
+ for i, mobs in enumerate(self.families):
232
+ sub_alpha = self.get_sub_alpha(t_alpha, i, n_families)
233
+ if last is not None:
234
+ if last[i] == sub_alpha and i > redo_through:
235
+ continue
236
+ last[i] = sub_alpha
237
+ redo_through = max(redo_through, i + spans[i] - 1)
238
+ self.interpolate_submobject(*mobs, sub_alpha)
239
+
240
+ def get_family_spans(self) -> list[int]:
241
+ """
242
+ For each family, how many families from it on its submobject's own family reaches
243
+ across, itself included, see interpolate_mobject. Worked out again whenever the
244
+ families are made anew.
245
+ """
246
+ if getattr(self, "_spans_of", None) is not self.families:
247
+ self._family_spans = [len(mobs[0].get_family()) for mobs in self.families]
248
+ self._spans_of = self.families
249
+ return self._family_spans
250
+
251
+ def interpolate_submobject(
252
+ self,
253
+ submobject: Mobject,
254
+ starting_submobject: Mobject,
255
+ alpha: float
256
+ ):
257
+ # Typically ipmlemented by subclass
258
+ pass
259
+
260
+ def get_sub_alpha(
261
+ self,
262
+ alpha: float,
263
+ index: int,
264
+ num_submobjects: UnsignedInt
265
+ ) -> float:
266
+ lag_ratio = self.lag_ratio
267
+ if lag_ratio == 0:
268
+ return self.rate_func(clip(alpha, 0, 1))
269
+ full_length = (num_submobjects - 1) * lag_ratio + 1
270
+ value = alpha * full_length
271
+ lower = index * lag_ratio
272
+ raw_sub_alpha = clip((value - lower), 0, 1)
273
+ return self.rate_func(raw_sub_alpha)
274
+
275
+ # Getters and setters
276
+ def set_run_time(self, run_time: Duration):
277
+ self.run_time = run_time
278
+ return self
279
+
280
+ def get_run_time(self) -> float:
281
+ if self.time_span:
282
+ return max(self.run_time, self.time_span[1])
283
+ return self.run_time
284
+
285
+ def set_rate_func(self, rate_func: Callable[[float], float]):
286
+ self.rate_func = rate_func
287
+ return self
288
+
289
+ def get_rate_func(self) -> Callable[[float], float]:
290
+ return self.rate_func
291
+
292
+ def set_name(self, name: str):
293
+ self.name = name
294
+ return self
295
+
296
+ def is_remover(self) -> bool:
297
+ return self.remover
298
+
299
+ editor_thumbnail = (
300
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
301
+ '<path d="M14.2 5.9Q8.1 5.9 2.0 5.9Q2.0 12.0 2.0 18.1Q8.1 18.1 14.2 18.1Q14.2 12.0 14.2 5.9Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
302
+ '<path d="M30.1 5.9Q24.0 5.9 17.9 5.9Q17.9 12.0 17.9 18.1Q24.0 18.1 30.1 18.1Q30.1 12.0 30.1 5.9Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
303
+ '<path d="M46.0 5.9Q39.9 5.9 33.8 5.9Q33.8 12.0 33.8 18.1Q39.9 18.1 46.0 18.1Q46.0 12.0 46.0 5.9Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
304
+ '</svg>'
305
+ )
306
+
307
+
308
+ async def resolve_async(value):
309
+ """Recursively await async scene objects before constructing animations."""
310
+ if inspect.isawaitable(value):
311
+ return await resolve_async(await value)
312
+ if isinstance(value, tuple):
313
+ return tuple([await resolve_async(item) for item in value])
314
+ if isinstance(value, list):
315
+ return [await resolve_async(item) for item in value]
316
+ if isinstance(value, dict):
317
+ return {
318
+ key: await resolve_async(item)
319
+ for key, item in value.items()
320
+ }
321
+ return value
322
+
323
+
324
+ def prepare_animation(anim: Animation | _AnimationBuilder):
325
+ if isinstance(anim, _AnimationBuilder):
326
+ return anim.build()
327
+
328
+ if isinstance(anim, Animation):
329
+ return anim
330
+
331
+ raise TypeError(f"Object {anim} cannot be converted to an animation")
332
+
333
+
334
+ async def prepare_animation_async(anim):
335
+ anim = await resolve_async(anim)
336
+ return prepare_animation(anim)