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
@@ -0,0 +1,258 @@
1
+ from __future__ import annotations
2
+
3
+ # What the Visual Editor files this module's classes under
4
+ __editor_category__ = 'Composition'
5
+
6
+ from datacut.animation.animation import Animation
7
+ from datacut.animation.animation import prepare_animation
8
+ from datacut.mobject.mobject import _AnimationBuilder
9
+ from datacut.mobject.mobject import Group
10
+ from datacut.mobject.types.vectorized_mobject import VGroup
11
+ from datacut.mobject.types.vectorized_mobject import VMobject
12
+ from datacut.utils.bezier import integer_interpolate
13
+ from datacut.utils.bezier import interpolate
14
+ from datacut.utils.iterables import remove_list_redundancies
15
+ from datacut.utils.simple_functions import clip
16
+
17
+ from typing import TYPE_CHECKING, Union, Iterable
18
+ from datacut.typing import Annotated, OneOf
19
+ AnimationType = Union[Animation, _AnimationBuilder]
20
+
21
+ if TYPE_CHECKING:
22
+ from datacut.typing import Duration, Proportion
23
+ from typing import Callable, Optional
24
+
25
+ from datacut.mobject.mobject import Mobject
26
+ from datacut.scene.scene import Scene
27
+
28
+
29
+ DEFAULT_LAGGED_START_LAG_RATIO = 0.05
30
+
31
+
32
+ class AnimationGroup(Animation):
33
+ def __init__(
34
+ self,
35
+ *args: AnimationType | Iterable[AnimationType],
36
+ run_time: Optional[Duration] = None, # If None, default to sum of inputed animation runtimes
37
+ lag_ratio: Proportion = 0.0,
38
+ group: Annotated[Mobject | None, OneOf("group")] = None,
39
+ group_type: Annotated[type | None, OneOf("group")] = None,
40
+ time_span: tuple[float, float] | None = None,
41
+ **kwargs
42
+ ):
43
+ animations = args[0] if isinstance(args[0], Iterable) else args
44
+ self.animations = [prepare_animation(anim) for anim in animations]
45
+ self.build_animations_with_timings(lag_ratio)
46
+ self.max_end_time = max((awt[2] for awt in self.anims_with_timings), default=0)
47
+ self.run_time = self.max_end_time if run_time is None else run_time
48
+ if time_span is not None:
49
+ # The contents are laid out over their own natural stretch of time, and it is
50
+ # time_spanned_alpha which fits that stretch into the span, see interpolate. So
51
+ # the run_time here is what the scene plays for, which has to reach the span's end.
52
+ self.run_time = max(self.run_time, time_span[1])
53
+ self.lag_ratio = lag_ratio
54
+ mobs = remove_list_redundancies([a.mobject for a in self.animations])
55
+ if group is not None:
56
+ self.group = group
57
+ elif group_type is not None:
58
+ self.group = group_type(*mobs)
59
+ elif all(isinstance(anim.mobject, VMobject) for anim in animations):
60
+ self.group = VGroup(*mobs)
61
+ else:
62
+ self.group = Group(*mobs)
63
+
64
+ super().__init__(
65
+ self.group,
66
+ run_time=self.run_time,
67
+ lag_ratio=lag_ratio,
68
+ time_span=time_span,
69
+ **kwargs
70
+ )
71
+
72
+ def get_all_mobjects(self) -> Mobject:
73
+ return self.group
74
+
75
+ def begin(self) -> None:
76
+ self.group.set_animating_status(True)
77
+ for anim in self.animations:
78
+ anim.begin()
79
+ # self.init_run_time()
80
+
81
+ def finish(self) -> None:
82
+ self.group.set_animating_status(False)
83
+ for anim in self.animations:
84
+ anim.finish()
85
+
86
+ def clean_up_from_scene(self, scene: Scene) -> None:
87
+ for anim in self.animations:
88
+ anim.clean_up_from_scene(scene)
89
+
90
+ def update_reference_mobjects(self, dt: float, frame_rate: float | None = None) -> None:
91
+ for anim in self.animations:
92
+ anim.update_reference_mobjects(dt, frame_rate)
93
+
94
+ def build_animations_with_timings(self, lag_ratio: float) -> None:
95
+ """
96
+ Creates a list of triplets of the form
97
+ (anim, start_time, end_time)
98
+ """
99
+ self.anims_with_timings = []
100
+ curr_time = 0
101
+ for anim in self.animations:
102
+ start_time = curr_time
103
+ end_time = start_time + anim.get_run_time()
104
+ self.anims_with_timings.append(
105
+ (anim, start_time, end_time)
106
+ )
107
+ # Start time of next animation is based on the lag_ratio
108
+ curr_time = interpolate(
109
+ start_time, end_time, lag_ratio
110
+ )
111
+
112
+ def interpolate(self, alpha: float) -> None:
113
+ # Note, if the run_time of AnimationGroup has been
114
+ # set to something other than its default, these
115
+ # times might not correspond to actual times,
116
+ # e.g. of the surrounding scene. Instead they'd
117
+ # be a rescaled version. But that's okay!
118
+ time = self.time_spanned_alpha(alpha) * self.max_end_time
119
+ for anim, start_time, end_time in self.anims_with_timings:
120
+ anim_time = end_time - start_time
121
+ if anim_time == 0:
122
+ sub_alpha = 0
123
+ else:
124
+ sub_alpha = clip((time - start_time) / anim_time, 0, 1)
125
+ anim.interpolate(sub_alpha)
126
+
127
+ editor_thumbnail = (
128
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
129
+ '<path d="M7.6 9.2Q4.8 9.2 2.0 9.2Q2.0 12.0 2.0 14.8Q4.8 14.8 7.6 14.8Q7.6 12.0 7.6 9.2Z" fill="#58C4DD" fill-opacity="0.03" stroke="#C7E9F1" stroke-opacity="0.06" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
130
+ '<path d="M11.3 12.0Q11.3 12.0 11.2 11.9Q11.2 11.9 11.2 11.9Q11.2 11.8 11.1 11.8Q11.1 11.8 11.1 11.8Q11.0 11.8 11.0 11.8Q11.0 11.8 11.0 11.9Q10.9 11.9 10.9 11.9Q10.9 12.0 10.9 12.0Q10.9 12.0 10.9 12.1Q10.9 12.1 11.0 12.1Q11.0 12.2 11.0 12.2Q11.0 12.2 11.1 12.2Q11.1 12.2 11.1 12.2Q11.2 12.2 11.2 12.1Q11.2 12.1 11.2 12.1Q11.3 12.0 11.3 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
131
+ '<path d="M23.5 9.2Q20.7 9.2 17.9 9.2Q17.9 12.0 17.9 14.8Q20.7 14.8 23.5 14.8Q23.5 12.0 23.5 9.2Z" fill="#58C4DD" fill-opacity="0.36" stroke="#C7E9F1" stroke-opacity="0.59" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
132
+ '<path d="M28.8 12.0Q28.8 11.6 28.7 11.3Q28.5 10.9 28.3 10.7Q28.0 10.4 27.7 10.3Q27.3 10.1 27.0 10.1Q26.6 10.1 26.3 10.3Q25.9 10.4 25.7 10.7Q25.4 10.9 25.2 11.3Q25.1 11.6 25.1 12.0Q25.1 12.4 25.2 12.7Q25.4 13.1 25.7 13.3Q25.9 13.6 26.3 13.7Q26.6 13.9 27.0 13.9Q27.3 13.9 27.7 13.7Q28.0 13.6 28.3 13.3Q28.5 13.1 28.7 12.7Q28.8 12.4 28.8 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
133
+ '<path d="M39.4 9.2Q36.6 9.2 33.8 9.2Q33.8 12.0 33.8 14.8Q36.6 14.8 39.4 14.8Q39.4 12.0 39.4 9.2Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
134
+ '<path d="M46.0 12.0Q46.0 11.4 45.8 10.8Q45.5 10.2 45.1 9.8Q44.6 9.3 44.1 9.1Q43.5 8.9 42.9 8.9Q42.2 8.9 41.7 9.1Q41.1 9.3 40.6 9.8Q40.2 10.2 40.0 10.8Q39.7 11.4 39.7 12.0Q39.7 12.6 40.0 13.2Q40.2 13.8 40.6 14.2Q41.1 14.7 41.7 14.9Q42.2 15.1 42.9 15.1Q43.5 15.1 44.1 14.9Q44.6 14.7 45.1 14.2Q45.5 13.8 45.8 13.2Q46.0 12.6 46.0 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
135
+ '</svg>'
136
+ )
137
+
138
+
139
+ class Succession(AnimationGroup):
140
+ def __init__(
141
+ self,
142
+ *animations: Animation,
143
+ lag_ratio: Proportion = 1.0,
144
+ **kwargs
145
+ ):
146
+ super().__init__(*animations, lag_ratio=lag_ratio, **kwargs)
147
+
148
+ def begin(self) -> None:
149
+ assert len(self.animations) > 0
150
+ self.active_index = 0
151
+ self.active_animation = self.animations[0]
152
+ self.active_animation.begin()
153
+
154
+ def finish(self) -> None:
155
+ self.active_animation.finish()
156
+
157
+ def update_reference_mobjects(self, dt: float, frame_rate: float | None = None) -> None:
158
+ # Only the active animation, since the rest are yet to begin, and so
159
+ # have no starting_mobject or target to speak of
160
+ self.active_animation.update_reference_mobjects(dt, frame_rate)
161
+
162
+ def interpolate(self, alpha: float) -> None:
163
+ if self.max_end_time == 0:
164
+ index = len(self.animations) - 1
165
+ subalpha = 1.0
166
+ else:
167
+ time = self.time_spanned_alpha(alpha) * self.max_end_time
168
+ index = len(self.anims_with_timings) - 1
169
+ subalpha = 1.0
170
+ for i, (anim, start_time, end_time) in enumerate(self.anims_with_timings):
171
+ if time < end_time or i == len(self.anims_with_timings) - 1:
172
+ index = i
173
+ anim_time = end_time - start_time
174
+ subalpha = 1.0 if anim_time == 0 else clip((time - start_time) / anim_time, 0, 1)
175
+ break
176
+
177
+ if index != self.active_index:
178
+ self.active_animation.finish()
179
+ step = 1 if index > self.active_index else -1
180
+ for i in range(self.active_index + step, index, step):
181
+ skipped = self.animations[i]
182
+ skipped.begin()
183
+ skipped.interpolate(1.0 if step > 0 else 0.0)
184
+ skipped.finish()
185
+ self.active_index = index
186
+ self.active_animation = self.animations[index]
187
+ self.active_animation.begin()
188
+
189
+ self.active_animation.interpolate(subalpha)
190
+
191
+ editor_thumbnail = (
192
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
193
+ '<path d="M7.6 9.2Q4.8 9.2 2.0 9.2Q2.0 12.0 2.0 14.8Q4.8 14.8 7.6 14.8Q7.6 12.0 7.6 9.2Z" fill="#58C4DD" fill-opacity="0.19" stroke="#C7E9F1" stroke-opacity="0.32" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
194
+ '<path d="M14.2 12.0Q14.2 11.4 14.0 10.8Q13.7 10.2 13.3 9.8Q12.9 9.3 12.3 9.1Q11.7 8.9 11.1 8.9Q10.5 8.9 9.9 9.1Q9.3 9.3 8.9 9.8Q8.4 10.2 8.2 10.8Q7.9 11.4 7.9 12.0Q7.9 12.6 8.2 13.2Q8.4 13.8 8.9 14.2Q9.3 14.7 9.9 14.9Q10.5 15.1 11.1 15.1Q11.7 15.1 12.3 14.9Q12.9 14.7 13.3 14.2Q13.7 13.8 14.0 13.2Q14.2 12.6 14.2 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
195
+ '<path d="M23.5 9.2Q20.7 9.2 17.9 9.2Q17.9 12.0 17.9 14.8Q20.7 14.8 23.5 14.8Q23.5 12.0 23.5 9.2Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
196
+ '<path d="M27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 26.9 12.0Q26.9 12.0 26.9 12.0Q26.9 12.0 26.9 12.0Q26.9 12.0 26.9 12.0Q26.9 12.0 26.9 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Q27.0 12.0 27.0 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
197
+ '<path d="M39.4 9.2Q36.6 9.2 33.8 9.2Q33.8 12.0 33.8 14.8Q36.6 14.8 39.4 14.8Q39.4 12.0 39.4 9.2Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
198
+ '<path d="M46.0 12.0Q46.0 11.4 45.8 10.8Q45.5 10.2 45.1 9.8Q44.6 9.3 44.1 9.1Q43.5 8.9 42.9 8.9Q42.2 8.9 41.7 9.1Q41.1 9.3 40.6 9.8Q40.2 10.2 40.0 10.8Q39.7 11.4 39.7 12.0Q39.7 12.6 40.0 13.2Q40.2 13.8 40.6 14.2Q41.1 14.7 41.7 14.9Q42.2 15.1 42.9 15.1Q43.5 15.1 44.1 14.9Q44.6 14.7 45.1 14.2Q45.5 13.8 45.8 13.2Q46.0 12.6 46.0 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
199
+ '</svg>'
200
+ )
201
+
202
+
203
+ class LaggedStart(AnimationGroup):
204
+ def __init__(
205
+ self,
206
+ *animations,
207
+ lag_ratio: Proportion = DEFAULT_LAGGED_START_LAG_RATIO,
208
+ **kwargs
209
+ ):
210
+ super().__init__(*animations, lag_ratio=lag_ratio, **kwargs)
211
+
212
+ editor_thumbnail = (
213
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
214
+ '<path d="M7.6 9.2Q4.8 9.2 2.0 9.2Q2.0 12.0 2.0 14.8Q4.8 14.8 7.6 14.8Q7.6 12.0 7.6 9.2Z" fill="#58C4DD" fill-opacity="0.04" stroke="#C7E9F1" stroke-opacity="0.07" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
215
+ '<path d="M11.2 12.0Q11.2 12.0 11.2 12.0Q11.2 11.9 11.1 11.9Q11.1 11.9 11.1 11.9Q11.1 11.9 11.1 11.9Q11.1 11.9 11.0 11.9Q11.0 11.9 11.0 11.9Q11.0 11.9 11.0 12.0Q11.0 12.0 11.0 12.0Q11.0 12.0 11.0 12.0Q11.0 12.1 11.0 12.1Q11.0 12.1 11.0 12.1Q11.1 12.1 11.1 12.1Q11.1 12.1 11.1 12.1Q11.1 12.1 11.1 12.1Q11.2 12.1 11.2 12.0Q11.2 12.0 11.2 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
216
+ '<path d="M23.5 9.2Q20.7 9.2 17.9 9.2Q17.9 12.0 17.9 14.8Q20.7 14.8 23.5 14.8Q23.5 12.0 23.5 9.2Z" fill="#58C4DD" fill-opacity="0.39" stroke="#C7E9F1" stroke-opacity="0.64" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
217
+ '<path d="M28.7 12.0Q28.7 11.7 28.6 11.3Q28.4 11.0 28.2 10.8Q28.0 10.5 27.6 10.4Q27.3 10.3 27.0 10.3Q26.6 10.3 26.3 10.4Q26.0 10.5 25.7 10.8Q25.5 11.0 25.4 11.3Q25.2 11.7 25.2 12.0Q25.2 12.3 25.4 12.7Q25.5 13.0 25.7 13.2Q26.0 13.5 26.3 13.6Q26.6 13.7 27.0 13.7Q27.3 13.7 27.6 13.6Q28.0 13.5 28.2 13.2Q28.4 13.0 28.6 12.7Q28.7 12.3 28.7 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
218
+ '<path d="M39.4 9.2Q36.6 9.2 33.8 9.2Q33.8 12.0 33.8 14.8Q36.6 14.8 39.4 14.8Q39.4 12.0 39.4 9.2Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
219
+ '<path d="M46.0 12.0Q46.0 11.4 45.8 10.8Q45.5 10.2 45.1 9.8Q44.6 9.3 44.1 9.1Q43.5 8.9 42.9 8.9Q42.2 8.9 41.7 9.1Q41.1 9.3 40.6 9.8Q40.2 10.2 40.0 10.8Q39.7 11.4 39.7 12.0Q39.7 12.6 40.0 13.2Q40.2 13.8 40.6 14.2Q41.1 14.7 41.7 14.9Q42.2 15.1 42.9 15.1Q43.5 15.1 44.1 14.9Q44.6 14.7 45.1 14.2Q45.5 13.8 45.8 13.2Q46.0 12.6 46.0 12.0Z" fill="#FFFF00" fill-opacity="0.60" stroke="#FFF1B6" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
220
+ '</svg>'
221
+ )
222
+
223
+
224
+ class LaggedStartMap(LaggedStart):
225
+ def __init__(
226
+ self,
227
+ anim_func: Callable[[Mobject], Animation],
228
+ group: Mobject,
229
+ run_time: Optional[Duration] = None,
230
+ lag_ratio: Proportion = DEFAULT_LAGGED_START_LAG_RATIO,
231
+ time_span: tuple[float, float] | None = None,
232
+ **kwargs
233
+ ):
234
+ # Named rather than left in kwargs, which are handed to each member rather than
235
+ # to the group, and a span belongs to the group
236
+ anim_kwargs = dict(kwargs)
237
+ anim_kwargs.pop("lag_ratio", None)
238
+ super().__init__(
239
+ *(anim_func(submob, **anim_kwargs) for submob in group),
240
+ run_time=run_time,
241
+ lag_ratio=lag_ratio,
242
+ group=group,
243
+ time_span=time_span,
244
+ )
245
+
246
+ editor_thumbnail = (
247
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
248
+ '<path d="M5.4 10.3Q3.7 10.3 2.0 10.3Q2.0 12.0 2.0 13.7Q3.7 13.7 5.4 13.7Q5.4 12.0 5.4 10.3Z" fill="#58C4DD" fill-opacity="0.60" stroke="#DDDDDD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
249
+ '<path d="M9.9 12.0Q9.9 11.6 9.8 11.3Q9.6 11.0 9.4 10.7Q9.1 10.4 8.8 10.3Q8.4 10.2 8.0 10.2Q7.7 10.2 7.3 10.3Q7.0 10.4 6.7 10.7Q6.5 11.0 6.3 11.3Q6.2 11.6 6.2 12.0Q6.2 12.4 6.3 12.7Q6.5 13.0 6.7 13.3Q7.0 13.6 7.3 13.7Q7.7 13.8 8.0 13.8Q8.4 13.8 8.8 13.7Q9.1 13.6 9.4 13.3Q9.6 13.0 9.8 12.7Q9.9 12.4 9.9 12.0Z" fill="#5CD0B3" fill-opacity="0.60" stroke="#FC6255" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
250
+ '<path d="M12.5 10.5Q11.6 12.0 10.7 13.5Q12.5 13.5 14.2 13.5Q13.3 12.0 12.5 10.5Z" fill="#83C167" fill-opacity="0.60" stroke="#DDDDDD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
251
+ '<path d="M21.2 10.3Q19.6 10.3 17.9 10.3Q17.9 12.0 17.9 13.7Q19.6 13.7 21.2 13.7Q21.2 12.0 21.2 10.3Z" fill="#58C4DD" fill-opacity="0.60" stroke="#DDDDDD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
252
+ '<path d="M25.8 12.0Q25.8 11.6 25.6 11.3Q25.5 11.0 25.2 10.7Q25.0 10.4 24.6 10.3Q24.3 10.2 23.9 10.2Q23.6 10.2 23.2 10.3Q22.9 10.4 22.6 10.7Q22.4 11.0 22.2 11.3Q22.1 11.6 22.1 12.0Q22.1 12.4 22.2 12.7Q22.4 13.0 22.6 13.3Q22.9 13.6 23.2 13.7Q23.6 13.8 23.9 13.8Q24.3 13.8 24.6 13.7Q25.0 13.6 25.2 13.3Q25.5 13.0 25.6 12.7Q25.8 12.4 25.8 12.0Z" fill="#5CD0B3" fill-opacity="0.60" stroke="#FC6255" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
253
+ '<path d="M28.4 10.5Q27.5 12.0 26.6 13.5Q28.4 13.5 30.1 13.5Q29.2 12.0 28.4 10.5Z" fill="#83C167" fill-opacity="0.60" stroke="#DDDDDD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
254
+ '<path d="M37.1 10.3Q35.5 10.3 33.8 10.3Q33.8 12.0 33.8 13.7Q35.5 13.7 37.1 13.7Q37.1 12.0 37.1 10.3Z" fill="#58C4DD" fill-opacity="0.60" stroke="#DDDDDD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
255
+ '<path d="M41.7 12.0Q41.7 11.6 41.5 11.3Q41.4 11.0 41.1 10.7Q40.9 10.4 40.5 10.3Q40.2 10.2 39.8 10.2Q39.5 10.2 39.1 10.3Q38.8 10.4 38.5 10.7Q38.3 11.0 38.1 11.3Q38.0 11.6 38.0 12.0Q38.0 12.4 38.1 12.7Q38.3 13.0 38.5 13.3Q38.8 13.6 39.1 13.7Q39.5 13.8 39.8 13.8Q40.2 13.8 40.5 13.7Q40.9 13.6 41.1 13.3Q41.4 13.0 41.5 12.7Q41.7 12.4 41.7 12.0Z" fill="#5CD0B3" fill-opacity="0.60" stroke="#FC6255" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
256
+ '<path d="M44.3 10.5Q43.4 12.0 42.5 13.5Q44.3 13.5 46.0 13.5Q45.1 12.0 44.3 10.5Z" fill="#83C167" fill-opacity="0.60" stroke="#DDDDDD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
257
+ '</svg>'
258
+ )
@@ -0,0 +1,315 @@
1
+ from __future__ import annotations
2
+
3
+ # What the Visual Editor files this module's classes under
4
+ __editor_category__ = 'Creation'
5
+
6
+ from abc import ABC, abstractmethod
7
+
8
+ import numpy as np
9
+
10
+ from datacut.animation.animation import Animation
11
+ from datacut.mobject.svg.string_mobject import StringMobject
12
+ from datacut.mobject.types.vectorized_mobject import VMobject
13
+ from datacut.utils.bezier import integer_interpolate
14
+ from datacut.utils.rate_functions import linear
15
+ from datacut.utils.rate_functions import double_smooth
16
+ from datacut.utils.rate_functions import smooth
17
+ from datacut.utils.simple_functions import clip
18
+ from datacut.typing import Duration, UnsignedInt
19
+
20
+ from typing import TYPE_CHECKING
21
+
22
+ if TYPE_CHECKING:
23
+ from datacut.typing import Duration, Proportion, RateFunction, StrokeWidth
24
+ from typing import Callable
25
+ from datacut.mobject.mobject import Mobject
26
+ from datacut.scene.scene import Scene
27
+ from datacut.typing import ManimColor
28
+
29
+
30
+ class ShowPartial(Animation, ABC):
31
+ """
32
+ Abstract class for ShowCreation and ShowPassingFlash
33
+ """
34
+ def __init__(self, mobject: Mobject, should_match_start: bool = False, **kwargs):
35
+ self.should_match_start = should_match_start
36
+ super().__init__(mobject, **kwargs)
37
+
38
+ def interpolate_submobject(
39
+ self,
40
+ submob: Mobject,
41
+ start_submob: Mobject,
42
+ alpha: float
43
+ ) -> None:
44
+ submob.pointwise_become_partial(
45
+ start_submob, *self.get_bounds(alpha)
46
+ )
47
+
48
+ @abstractmethod
49
+ def get_bounds(self, alpha: float) -> tuple[float, float]:
50
+ raise Exception("Not Implemented")
51
+
52
+
53
+ class ShowCreation(ShowPartial):
54
+ def __init__(self, mobject: Mobject, lag_ratio: Proportion = 1.0, **kwargs):
55
+ super().__init__(mobject, lag_ratio=lag_ratio, **kwargs)
56
+
57
+ def get_bounds(self, alpha: float) -> tuple[float, float]:
58
+ return (0, alpha)
59
+
60
+ editor_thumbnail = (
61
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
62
+ '<path d="M14.2 5.9Q12.8 5.9 11.4 5.9Q11.4 5.9 11.4 5.9Q11.4 5.9 11.4 5.9Q11.4 5.9 11.4 5.9" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
63
+ '<path d="M30.1 5.9Q24.0 5.9 17.9 5.9Q17.9 12.0 17.9 18.1Q20.2 18.1 22.4 18.1Q22.4 18.1 22.4 18.1" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
64
+ '<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"/>'
65
+ '</svg>'
66
+ )
67
+
68
+
69
+ class Uncreate(ShowCreation):
70
+ def __init__(
71
+ self,
72
+ mobject: Mobject,
73
+ rate_func: RateFunction = lambda t: smooth(1 - t),
74
+ remover: bool = True,
75
+ should_match_start: bool = True,
76
+ **kwargs,
77
+ ):
78
+ final_alpha_value = kwargs.pop("final_alpha_value", 0.0 if remover else 1.0)
79
+ super().__init__(
80
+ mobject,
81
+ rate_func=rate_func,
82
+ remover=remover,
83
+ should_match_start=should_match_start,
84
+ final_alpha_value=final_alpha_value,
85
+ **kwargs,
86
+ )
87
+
88
+ editor_thumbnail = (
89
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
90
+ '<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 13.4 14.2 8.7" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
91
+ '<path d="M30.1 5.9Q24.0 5.9 17.9 5.9Q17.9 9.7 17.9 13.6Q17.9 13.6 17.9 13.6Q17.9 13.6 17.9 13.6" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
92
+ '<path d="M46.0 5.9Q46.0 5.9 46.0 5.9Q46.0 5.9 46.0 5.9Q46.0 5.9 46.0 5.9Q46.0 5.9 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"/>'
93
+ '</svg>'
94
+ )
95
+
96
+
97
+ class DrawBorderThenFill(Animation):
98
+ def __init__(
99
+ self,
100
+ vmobject: VMobject,
101
+ run_time: Duration = 2.0,
102
+ rate_func: RateFunction = double_smooth,
103
+ stroke_width: StrokeWidth = 2.0,
104
+ stroke_color: ManimColor = None,
105
+ draw_border_animation_config: dict = {},
106
+ fill_animation_config: dict = {},
107
+ **kwargs
108
+ ):
109
+ assert isinstance(vmobject, VMobject)
110
+ self.sm_to_index = {hash(sm): 0 for sm in vmobject.get_family()}
111
+ self.stroke_width = stroke_width
112
+ self.stroke_color = stroke_color
113
+ self.draw_border_animation_config = draw_border_animation_config
114
+ self.fill_animation_config = fill_animation_config
115
+ super().__init__(
116
+ vmobject,
117
+ run_time=run_time,
118
+ rate_func=rate_func,
119
+ **kwargs
120
+ )
121
+ self.mobject = vmobject
122
+
123
+ def begin(self) -> None:
124
+ self.mobject.set_animating_status(True)
125
+ self.outline = self.get_outline()
126
+ super().begin()
127
+ self.mobject.match_style(self.outline)
128
+
129
+ def get_outline(self) -> VMobject:
130
+ outline = self.mobject.copy()
131
+ outline.set_fill(opacity=0)
132
+ for sm in outline.family_members_with_points():
133
+ sm.set_stroke(
134
+ color=self.stroke_color or sm.get_stroke_color(),
135
+ width=self.stroke_width,
136
+ behind=self.mobject.stroke_behind,
137
+ )
138
+ return outline
139
+
140
+ def get_all_mobjects(self) -> list[Mobject]:
141
+ return [*super().get_all_mobjects(), self.outline]
142
+
143
+ def get_interpolation_ends(self) -> tuple[VMobject, VMobject]:
144
+ """
145
+ The second half blends between these two, and the first half never blends at all: it
146
+ traces the outline with pointwise_become_partial, which writes the points itself and
147
+ refreshes the box from them, so what is settled here is read only where it holds.
148
+
149
+ The outline being a copy of the mobject in another style, the two agree about every
150
+ point and about the box, and only the style has anywhere to go.
151
+ """
152
+ return self.outline, self.starting_mobject
153
+
154
+ def interpolate_submobject(
155
+ self,
156
+ submob: VMobject,
157
+ start: VMobject,
158
+ outline: VMobject,
159
+ alpha: float
160
+ ) -> None:
161
+ index, subalpha = integer_interpolate(0, 2, alpha)
162
+
163
+ if index == 1 and self.sm_to_index[hash(submob)] == 0:
164
+ # First time crossing over
165
+ submob.set_data(outline.data)
166
+ self.sm_to_index[hash(submob)] = 1
167
+
168
+ if index == 0:
169
+ submob.pointwise_become_partial(outline, 0, subalpha)
170
+ else:
171
+ submob.interpolate(outline, start, subalpha)
172
+
173
+ editor_thumbnail = (
174
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
175
+ '<path d="M14.2 5.9Q8.1 5.9 2.0 5.9Q2.0 7.5 2.0 9.2Q2.0 9.2 2.0 9.2Q2.0 9.2 2.0 9.2" fill="none" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
176
+ '<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="none" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
177
+ '<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"/>'
178
+ '</svg>'
179
+ )
180
+
181
+
182
+ class Write(DrawBorderThenFill):
183
+ def __init__(
184
+ self,
185
+ vmobject: VMobject,
186
+ run_time: Duration = -1, # If negative, this will be reassigned
187
+ lag_ratio: Proportion = -1, # If negative, this will be reassigned
188
+ rate_func: RateFunction = linear,
189
+ stroke_color: ManimColor = None,
190
+ **kwargs
191
+ ):
192
+ if stroke_color is None:
193
+ stroke_color = vmobject.get_color()
194
+ family_size = len(vmobject.family_members_with_points())
195
+ super().__init__(
196
+ vmobject,
197
+ run_time=self.compute_run_time(family_size, run_time),
198
+ lag_ratio=self.compute_lag_ratio(family_size, lag_ratio),
199
+ rate_func=rate_func,
200
+ stroke_color=stroke_color,
201
+ **kwargs
202
+ )
203
+
204
+ def compute_run_time(self, family_size: UnsignedInt, run_time: Duration):
205
+ if run_time < 0:
206
+ return 1 if family_size < 15 else 2
207
+ return run_time
208
+
209
+ def compute_lag_ratio(self, family_size: UnsignedInt, lag_ratio: float):
210
+ if lag_ratio < 0:
211
+ return min(4.0 / (family_size + 1.0), 0.2)
212
+ return lag_ratio
213
+
214
+ editor_thumbnail = (
215
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
216
+ '<path d="M14.2 5.9Q8.1 5.9 2.0 5.9Q2.0 9.6 2.0 13.2Q2.0 13.2 2.0 13.2Q2.0 13.2 2.0 13.2" fill="none" stroke="#58C4DD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
217
+ '<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.06" stroke="#63C8DF" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
218
+ '<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"/>'
219
+ '</svg>'
220
+ )
221
+
222
+
223
+ class ShowIncreasingSubsets(Animation):
224
+ def __init__(
225
+ self,
226
+ group: Mobject,
227
+ int_func: Callable[[float], float] = np.round,
228
+ suspend_mobject_updating: bool = False,
229
+ **kwargs
230
+ ):
231
+ self.all_submobs = list(group.submobjects)
232
+ self.int_func = int_func
233
+ super().__init__(
234
+ group,
235
+ suspend_mobject_updating=suspend_mobject_updating,
236
+ **kwargs
237
+ )
238
+
239
+ def interpolate_mobject(self, alpha: float) -> None:
240
+ n_submobs = len(self.all_submobs)
241
+ alpha = self.rate_func(alpha)
242
+ index = int(self.int_func(alpha * n_submobs))
243
+ self.update_submobject_list(index)
244
+
245
+ def update_submobject_list(self, index: int) -> None:
246
+ self.mobject.set_submobjects(self.all_submobs[:index])
247
+
248
+ editor_thumbnail = (
249
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
250
+ '<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"/>'
251
+ '<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"/>'
252
+ '<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"/>'
253
+ '</svg>'
254
+ )
255
+
256
+
257
+ class ShowSubmobjectsOneByOne(ShowIncreasingSubsets):
258
+ def __init__(
259
+ self,
260
+ group: Mobject,
261
+ int_func: Callable[[float], float] = np.ceil,
262
+ **kwargs
263
+ ):
264
+ super().__init__(group, int_func=int_func, **kwargs)
265
+
266
+ def update_submobject_list(self, index: int) -> None:
267
+ index = int(clip(index, 0, len(self.all_submobs) - 1))
268
+ if index == 0:
269
+ self.mobject.set_submobjects([])
270
+ else:
271
+ self.mobject.set_submobjects([self.all_submobs[index - 1]])
272
+
273
+ editor_thumbnail = (
274
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
275
+ '<path d="M7.2 9.4Q4.6 9.4 2.0 9.4Q2.0 12.0 2.0 14.6Q4.6 14.6 7.2 14.6Q7.2 12.0 7.2 9.4Z" fill="#58C4DD" fill-opacity="0.60" stroke="#DDDDDD" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
276
+ '<path d="M30.1 12.0Q30.1 11.4 29.9 10.9Q29.7 10.4 29.3 10.0Q28.9 9.6 28.3 9.4Q27.8 9.1 27.3 9.1Q26.7 9.1 26.2 9.4Q25.6 9.6 25.2 10.0Q24.8 10.4 24.6 10.9Q24.4 11.4 24.4 12.0Q24.4 12.6 24.6 13.1Q24.8 13.6 25.2 14.0Q25.6 14.4 26.2 14.6Q26.7 14.9 27.3 14.9Q27.8 14.9 28.3 14.6Q28.9 14.4 29.3 14.0Q29.7 13.6 29.9 13.1Q30.1 12.6 30.1 12.0Z" fill="#5CD0B3" fill-opacity="0.60" stroke="#FC6255" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
277
+ '<path d="M46.0 12.0Q46.0 11.4 45.8 10.9Q45.6 10.4 45.2 10.0Q44.8 9.6 44.2 9.4Q43.7 9.1 43.1 9.1Q42.6 9.1 42.0 9.4Q41.5 9.6 41.1 10.0Q40.7 10.4 40.5 10.9Q40.3 11.4 40.3 12.0Q40.3 12.6 40.5 13.1Q40.7 13.6 41.1 14.0Q41.5 14.4 42.0 14.6Q42.6 14.9 43.1 14.9Q43.7 14.9 44.2 14.6Q44.8 14.4 45.2 14.0Q45.6 13.6 45.8 13.1Q46.0 12.6 46.0 12.0Z" fill="#5CD0B3" fill-opacity="0.60" stroke="#FC6255" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
278
+ '</svg>'
279
+ )
280
+
281
+
282
+ class AddTextWordByWord(ShowIncreasingSubsets):
283
+ def __init__(
284
+ self,
285
+ string_mobject: StringMobject,
286
+ time_per_word: float = 0.2,
287
+ run_time: Duration = -1.0, # If negative, it will be recomputed with time_per_word
288
+ rate_func: RateFunction = linear,
289
+ **kwargs
290
+ ):
291
+ assert isinstance(string_mobject, StringMobject)
292
+ grouped_mobject = string_mobject.build_groups()
293
+ if run_time < 0:
294
+ run_time = time_per_word * len(grouped_mobject)
295
+ super().__init__(
296
+ grouped_mobject,
297
+ run_time=run_time,
298
+ rate_func=rate_func,
299
+ **kwargs
300
+ )
301
+ self.string_mobject = string_mobject
302
+
303
+ def clean_up_from_scene(self, scene: Scene) -> None:
304
+ scene.remove(self.mobject)
305
+ if not self.is_remover():
306
+ scene.add(self.string_mobject)
307
+
308
+ editor_thumbnail = (
309
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
310
+ '<path d="M3 9H9M11.5 9H19" stroke="#DDDDDD" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
311
+ '<path d="M3 15H8.5" stroke="#DDDDDD" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
312
+ '<path d="M11 15H16" stroke="#DDDDDD" stroke-opacity="0.3" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
313
+ '<path d="M18.5 12.5V17.5" stroke="#58C4DD" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
314
+ '</svg>'
315
+ )