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.
- datacut/__init__.py +121 -0
- datacut/__main__.py +122 -0
- datacut/animation/__init__.py +0 -0
- datacut/animation/animation.py +336 -0
- datacut/animation/composition.py +258 -0
- datacut/animation/creation.py +315 -0
- datacut/animation/fading.py +328 -0
- datacut/animation/growing.py +90 -0
- datacut/animation/indication.py +608 -0
- datacut/animation/movement.py +165 -0
- datacut/animation/numbers.py +92 -0
- datacut/animation/physics.py +453 -0
- datacut/animation/rotation.py +95 -0
- datacut/animation/specialized.py +956 -0
- datacut/animation/transform.py +505 -0
- datacut/animation/transform_matching_parts.py +343 -0
- datacut/animation/update.py +95 -0
- datacut/camera/__init__.py +0 -0
- datacut/camera/camera.py +795 -0
- datacut/camera/camera_frame.py +320 -0
- datacut/camera/cinematography.py +1166 -0
- datacut/config.py +479 -0
- datacut/constants.py +160 -0
- datacut/css/__init__.py +189 -0
- datacut/css/easing.py +328 -0
- datacut/css/engine.py +1727 -0
- datacut/css/gradients.py +678 -0
- datacut/css/motion.py +1615 -0
- datacut/css/parser.py +741 -0
- datacut/css/presets.py +143 -0
- datacut/css/shader_fill.py +703 -0
- datacut/css/values.py +650 -0
- datacut/default_config.yml +224 -0
- datacut/event_handler/__init__.py +6 -0
- datacut/event_handler/event_dispatcher.py +161 -0
- datacut/event_handler/event_listner.py +31 -0
- datacut/event_handler/event_type.py +11 -0
- datacut/event_handler/picking.py +111 -0
- datacut/event_keys.py +53 -0
- datacut/extract_scene.py +200 -0
- datacut/layout/__init__.py +39 -0
- datacut/layout/components.py +425 -0
- datacut/layout/containers.py +1520 -0
- datacut/logger.py +13 -0
- datacut/mobject/__init__.py +0 -0
- datacut/mobject/boolean_ops.py +168 -0
- datacut/mobject/changing.py +209 -0
- datacut/mobject/coordinate_systems.py +1056 -0
- datacut/mobject/fractals.py +348 -0
- datacut/mobject/frame.py +80 -0
- datacut/mobject/functions.py +147 -0
- datacut/mobject/geometry.py +1834 -0
- datacut/mobject/gltf.py +243 -0
- datacut/mobject/interactive.py +906 -0
- datacut/mobject/lights.py +366 -0
- datacut/mobject/materials.py +207 -0
- datacut/mobject/matrix.py +570 -0
- datacut/mobject/mesh3d.py +2288 -0
- datacut/mobject/mobject.py +2885 -0
- datacut/mobject/mobject_update_utils.py +123 -0
- datacut/mobject/model.py +543 -0
- datacut/mobject/number_line.py +517 -0
- datacut/mobject/numbers.py +441 -0
- datacut/mobject/probability.py +536 -0
- datacut/mobject/shape_matchers.py +161 -0
- datacut/mobject/subtitles.py +260 -0
- datacut/mobject/svg/__init__.py +0 -0
- datacut/mobject/svg/brace.py +356 -0
- datacut/mobject/svg/drawings.py +1041 -0
- datacut/mobject/svg/old_tex_mobject.py +335 -0
- datacut/mobject/svg/path_cache.py +155 -0
- datacut/mobject/svg/special_tex.py +216 -0
- datacut/mobject/svg/string_mobject.py +622 -0
- datacut/mobject/svg/svg_mobject.py +657 -0
- datacut/mobject/svg/svg_parse.py +437 -0
- datacut/mobject/svg/tex_mobject.py +499 -0
- datacut/mobject/svg/text_mobject.py +702 -0
- datacut/mobject/svg/typst_mobject.py +864 -0
- datacut/mobject/three_dimensions.py +686 -0
- datacut/mobject/types/__init__.py +0 -0
- datacut/mobject/types/dot_cloud.py +220 -0
- datacut/mobject/types/image_mobject.py +130 -0
- datacut/mobject/types/point_cloud_mobject.py +138 -0
- datacut/mobject/types/shader_mobject.py +268 -0
- datacut/mobject/types/surface.py +848 -0
- datacut/mobject/types/vectorized_mobject.py +1749 -0
- datacut/mobject/types/video_mobject.py +3902 -0
- datacut/mobject/value_tracker.py +110 -0
- datacut/mobject/vector_field.py +585 -0
- datacut/module_loader.py +176 -0
- datacut/reactive/__init__.py +25 -0
- datacut/reactive/signals.py +610 -0
- datacut/renderer/__init__.py +4 -0
- datacut/renderer/drawing.py +1066 -0
- datacut/renderer/gpu.py +800 -0
- datacut/renderer/material.py +88 -0
- datacut/renderer/pipeline.py +179 -0
- datacut/renderer/post_process.py +577 -0
- datacut/renderer/renderer.py +1285 -0
- datacut/renderer/shader_source.py +146 -0
- datacut/renderer/shared_buffer.py +185 -0
- datacut/renderer/texture.py +217 -0
- datacut/renderer/uniform_block.py +118 -0
- datacut/scene/__init__.py +0 -0
- datacut/scene/incremental.py +233 -0
- datacut/scene/interactive_scene.py +758 -0
- datacut/scene/performance.py +226 -0
- datacut/scene/presentation_scene.py +783 -0
- datacut/scene/recording.py +541 -0
- datacut/scene/safe_zones.py +323 -0
- datacut/scene/scene.py +2849 -0
- datacut/scene/scene_embed.py +277 -0
- datacut/scene/scene_file_writer.py +1014 -0
- datacut/scene/scene_task.py +183 -0
- datacut/scene/sfx.py +164 -0
- datacut/scene/sound.py +702 -0
- datacut/scene/sound_clip.py +580 -0
- datacut/scene/timeline.py +1689 -0
- datacut/scene/transcript.py +503 -0
- datacut/shaders/fill.wgsl +107 -0
- datacut/shaders/fill_depth.wgsl +198 -0
- datacut/shaders/image.wgsl +25 -0
- datacut/shaders/inserts/NOTE.md +16 -0
- datacut/shaders/inserts/clip_test.wgsl +14 -0
- datacut/shaders/inserts/complex_functions.wgsl +20 -0
- datacut/shaders/inserts/fill_color.wgsl +10 -0
- datacut/shaders/inserts/finalize_color.wgsl +44 -0
- datacut/shaders/inserts/frame_uniforms.wgsl +37 -0
- datacut/shaders/inserts/frame_units.wgsl +18 -0
- datacut/shaders/inserts/image_quad.wgsl +28 -0
- datacut/shaders/inserts/mobject_uniforms.wgsl +11 -0
- datacut/shaders/inserts/project_point.wgsl +44 -0
- datacut/shaders/inserts/quad_corners.wgsl +12 -0
- datacut/shaders/inserts/read_data.wgsl +33 -0
- datacut/shaders/inserts/surface_mesh.wgsl +106 -0
- datacut/shaders/mandelbrot_fractal.wgsl +100 -0
- datacut/shaders/mesh.wgsl +474 -0
- datacut/shaders/newton_fractal.wgsl +200 -0
- datacut/shaders/present.wgsl +62 -0
- datacut/shaders/stroke.wgsl +1141 -0
- datacut/shaders/stroke_depth.wgsl +1136 -0
- datacut/shaders/surface.wgsl +40 -0
- datacut/shaders/textured_surface.wgsl +59 -0
- datacut/shaders/true_dot.wgsl +78 -0
- datacut/shaders/video.wgsl +42 -0
- datacut/tex_templates.yml +736 -0
- datacut/transcribe.py +32 -0
- datacut/typing.py +412 -0
- datacut/utils/__init__.py +0 -0
- datacut/utils/bezier.py +467 -0
- datacut/utils/browser_audio.py +423 -0
- datacut/utils/browser_code_transform.py +1293 -0
- datacut/utils/browser_completions.py +2255 -0
- datacut/utils/browser_fonts.py +143 -0
- datacut/utils/browser_pathops.py +47 -0
- datacut/utils/browser_scheduler.py +18 -0
- datacut/utils/browser_typst.py +82 -0
- datacut/utils/cache.py +34 -0
- datacut/utils/cinematic_vfx.py +779 -0
- datacut/utils/color.py +203 -0
- datacut/utils/debug.py +46 -0
- datacut/utils/dict_ops.py +22 -0
- datacut/utils/directories.py +55 -0
- datacut/utils/editor_signatures.py +1806 -0
- datacut/utils/editor_thumbnails.py +769 -0
- datacut/utils/family_ops.py +48 -0
- datacut/utils/file_ops.py +65 -0
- datacut/utils/images.py +52 -0
- datacut/utils/iterables.py +216 -0
- datacut/utils/native.py +280 -0
- datacut/utils/paths.py +83 -0
- datacut/utils/rate_functions.py +154 -0
- datacut/utils/render_geometry.py +186 -0
- datacut/utils/simple_functions.py +99 -0
- datacut/utils/sounds.py +43 -0
- datacut/utils/space_ops.py +460 -0
- datacut/utils/structured_array.py +256 -0
- datacut/utils/svg_export.py +102 -0
- datacut/utils/tex.py +139 -0
- datacut/utils/tex_file_writing.py +164 -0
- datacut/utils/tex_to_symbol_count.py +186 -0
- datacut/utils/typst_file_writing.py +205 -0
- datacut/utils/vfx_presets.py +4543 -0
- datacut/utils/visual_css.py +737 -0
- datacut/utils/visual_editor.py +4292 -0
- datacut/utils/window_audio.py +760 -0
- datacut/window.py +910 -0
- datacut-0.1.0.dist-info/METADATA +226 -0
- datacut-0.1.0.dist-info/RECORD +193 -0
- datacut-0.1.0.dist-info/WHEEL +5 -0
- datacut-0.1.0.dist-info/entry_points.txt +2 -0
- datacut-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- datacut-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# What the Visual Editor files this module's classes under
|
|
4
|
+
__editor_category__ = 'Movement & Rotation'
|
|
5
|
+
|
|
6
|
+
from datacut.animation.animation import Animation
|
|
7
|
+
from datacut.utils.rate_functions import linear
|
|
8
|
+
|
|
9
|
+
from typing import TYPE_CHECKING
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from datacut.typing import Annotated, Example
|
|
13
|
+
from datacut.typing import Duration, RateFunction
|
|
14
|
+
from typing import Callable, Sequence
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
from datacut.mobject.mobject import Mobject
|
|
19
|
+
from datacut.mobject.types.vectorized_mobject import VMobject
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Homotopy(Animation):
|
|
23
|
+
apply_function_config: dict = dict()
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
homotopy: Annotated[Callable[[float, float, float, float], Sequence[float]], Example('lambda x, y, z, t: [x, y + 0.5 * np.sin(x + t * TAU), z]')],
|
|
28
|
+
mobject: Mobject,
|
|
29
|
+
run_time: Duration = 3.0,
|
|
30
|
+
**kwargs
|
|
31
|
+
):
|
|
32
|
+
"""
|
|
33
|
+
Homotopy is a function from
|
|
34
|
+
(x, y, z, t) to (x', y', z')
|
|
35
|
+
"""
|
|
36
|
+
self.homotopy = homotopy
|
|
37
|
+
super().__init__(mobject, run_time=run_time, **kwargs)
|
|
38
|
+
|
|
39
|
+
def function_at_time_t(self, t: float) -> Callable[[np.ndarray], Sequence[float]]:
|
|
40
|
+
def result(p):
|
|
41
|
+
return self.homotopy(*p, t)
|
|
42
|
+
return result
|
|
43
|
+
|
|
44
|
+
def interpolate_submobject(
|
|
45
|
+
self,
|
|
46
|
+
submob: Mobject,
|
|
47
|
+
start: Mobject,
|
|
48
|
+
alpha: float
|
|
49
|
+
) -> None:
|
|
50
|
+
submob.match_points(start)
|
|
51
|
+
submob.apply_function(
|
|
52
|
+
self.function_at_time_t(alpha),
|
|
53
|
+
**self.apply_function_config
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
editor_thumbnail = (
|
|
57
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
|
|
58
|
+
'<path d="M14.2 2.3Q8.1 4.4 2.0 7.4Q2.0 13.5 2.0 19.6Q8.1 16.6 14.2 14.5Q14.2 8.4 14.2 2.3Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
59
|
+
'<path d="M30.1 9.5Q24.0 7.9 17.9 5.0Q17.9 11.1 17.9 17.2Q24.0 20.1 30.1 21.7Q30.1 15.6 30.1 9.5Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
60
|
+
'<path d="M46.0 3.0Q39.9 5.8 33.8 8.5Q33.8 14.6 33.8 20.7Q39.9 18.0 46.0 15.2Q46.0 9.1 46.0 3.0Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
61
|
+
'</svg>'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class SmoothedVectorizedHomotopy(Homotopy):
|
|
66
|
+
apply_function_config: dict = dict(make_smooth=True)
|
|
67
|
+
|
|
68
|
+
editor_thumbnail = (
|
|
69
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
|
|
70
|
+
'<path d="M12.2 5.4Q8.1 5.1 4.0 8.8Q2.0 13.8 4.0 17.0Q8.1 17.3 12.2 13.6Q14.2 8.6 12.2 5.4Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
71
|
+
'<path d="M28.1 10.3Q24.0 6.7 19.9 7.2Q17.9 10.5 19.9 15.4Q24.0 18.9 28.1 18.4Q30.1 15.1 28.1 10.3Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
72
|
+
'<path d="M44.0 5.9Q39.9 5.7 35.8 9.6Q33.8 14.6 35.8 17.7Q39.9 17.9 44.0 14.1Q46.0 9.1 44.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"/>'
|
|
73
|
+
'</svg>'
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class ComplexHomotopy(Homotopy):
|
|
78
|
+
def __init__(
|
|
79
|
+
self,
|
|
80
|
+
complex_homotopy: Annotated[Callable[[complex, float], complex], Example('lambda z, t: z * (1 + t)')],
|
|
81
|
+
mobject: Mobject,
|
|
82
|
+
**kwargs
|
|
83
|
+
):
|
|
84
|
+
"""
|
|
85
|
+
Given a function form (z, t) -> w, where z and w
|
|
86
|
+
are complex numbers and t is time, this animates
|
|
87
|
+
the state over time
|
|
88
|
+
"""
|
|
89
|
+
def homotopy(x, y, z, t):
|
|
90
|
+
c = complex_homotopy(complex(x, y), t)
|
|
91
|
+
return (c.real, c.imag, z)
|
|
92
|
+
|
|
93
|
+
super().__init__(homotopy, mobject, **kwargs)
|
|
94
|
+
|
|
95
|
+
editor_thumbnail = (
|
|
96
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
|
|
97
|
+
'<path d="M11.3 8.8Q8.1 8.8 4.9 8.8Q4.9 12.0 4.9 15.2Q8.1 15.2 11.3 15.2Q11.3 12.0 11.3 8.8Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
98
|
+
'<path d="M28.9 7.1Q24.0 7.1 19.1 7.1Q19.1 12.0 19.1 16.9Q24.0 16.9 28.9 16.9Q28.9 12.0 28.9 7.1Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
99
|
+
'<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"/>'
|
|
100
|
+
'</svg>'
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class PhaseFlow(Animation):
|
|
105
|
+
def __init__(
|
|
106
|
+
self,
|
|
107
|
+
function: Annotated[Callable[[np.ndarray], np.ndarray], Example('lambda p: np.array([-p[1], p[0], 0])')],
|
|
108
|
+
mobject: Mobject,
|
|
109
|
+
virtual_time: float | None = None,
|
|
110
|
+
suspend_mobject_updating: bool = False,
|
|
111
|
+
rate_func: RateFunction = linear,
|
|
112
|
+
run_time: Duration =3.0,
|
|
113
|
+
**kwargs
|
|
114
|
+
):
|
|
115
|
+
self.function = function
|
|
116
|
+
self.virtual_time = virtual_time or run_time
|
|
117
|
+
super().__init__(
|
|
118
|
+
mobject,
|
|
119
|
+
rate_func=rate_func,
|
|
120
|
+
run_time=run_time,
|
|
121
|
+
suspend_mobject_updating=suspend_mobject_updating,
|
|
122
|
+
**kwargs
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
def interpolate_mobject(self, alpha: float) -> None:
|
|
126
|
+
if hasattr(self, "last_alpha"):
|
|
127
|
+
dt = self.virtual_time * (alpha - self.last_alpha)
|
|
128
|
+
self.mobject.apply_function(
|
|
129
|
+
lambda p: p + dt * self.function(p)
|
|
130
|
+
)
|
|
131
|
+
self.last_alpha = alpha
|
|
132
|
+
|
|
133
|
+
editor_thumbnail = (
|
|
134
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
|
|
135
|
+
'<path d="M8.9 8.7Q6.9 9.9 4.8 11.2Q6.1 13.2 7.3 15.3Q9.3 14.1 11.4 12.8Q10.2 10.8 8.9 8.7Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
136
|
+
'<path d="M21.1 8.7Q20.9 11.8 20.7 14.9Q23.8 15.1 26.9 15.3Q27.1 12.2 27.3 9.1Q24.2 8.9 21.1 8.7Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
137
|
+
'<path d="M33.8 13.9Q37.8 16.0 41.8 18.1Q43.9 14.1 46.0 10.1Q42.0 8.0 38.0 5.9Q35.9 9.9 33.8 13.9Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
138
|
+
'</svg>'
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class MoveAlongPath(Animation):
|
|
143
|
+
def __init__(
|
|
144
|
+
self,
|
|
145
|
+
mobject: Mobject,
|
|
146
|
+
path: VMobject,
|
|
147
|
+
suspend_mobject_updating: bool = False,
|
|
148
|
+
**kwargs
|
|
149
|
+
):
|
|
150
|
+
self.path = path
|
|
151
|
+
super().__init__(mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs)
|
|
152
|
+
|
|
153
|
+
def interpolate_mobject(self, alpha: float) -> None:
|
|
154
|
+
point = self.path.quick_point_from_proportion(
|
|
155
|
+
self.rate_func(self.time_spanned_alpha(alpha))
|
|
156
|
+
)
|
|
157
|
+
self.mobject.move_to(point)
|
|
158
|
+
|
|
159
|
+
editor_thumbnail = (
|
|
160
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 24">'
|
|
161
|
+
'<path d="M14.0 7.5Q11.0 7.5 8.0 7.5Q8.0 10.5 8.0 13.5Q11.0 13.5 14.0 13.5Q14.0 10.5 14.0 7.5Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
162
|
+
'<path d="M23.9 10.5Q20.9 10.5 17.9 10.5Q17.9 13.5 17.9 16.5Q20.9 16.5 23.9 16.5Q23.9 13.5 23.9 10.5Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
163
|
+
'<path d="M46.0 8.7Q43.0 8.7 40.0 8.7Q40.0 11.7 40.0 14.7Q43.0 14.7 46.0 14.7Q46.0 11.7 46.0 8.7Z" fill="#58C4DD" fill-opacity="0.60" stroke="#C7E9F1" stroke-opacity="1.00" stroke-width="1.3" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
164
|
+
'</svg>'
|
|
165
|
+
)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# What the Visual Editor files this module's classes under
|
|
4
|
+
__editor_category__ = 'Numbers & Camera'
|
|
5
|
+
|
|
6
|
+
from datacut.animation.animation import Animation
|
|
7
|
+
from datacut.mobject.numbers import DecimalNumber
|
|
8
|
+
from datacut.utils.bezier import interpolate
|
|
9
|
+
from datacut.utils.simple_functions import clip
|
|
10
|
+
|
|
11
|
+
from typing import TYPE_CHECKING
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from datacut.typing import Annotated, Example
|
|
15
|
+
from typing import Callable
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ChangingDecimal(Animation):
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
decimal_mob: DecimalNumber,
|
|
22
|
+
number_update_func: Annotated[Callable[[float], float], Example('lambda a: 100 * a')],
|
|
23
|
+
suspend_mobject_updating: bool = False,
|
|
24
|
+
**kwargs
|
|
25
|
+
):
|
|
26
|
+
assert isinstance(decimal_mob, DecimalNumber)
|
|
27
|
+
self.number_update_func = number_update_func
|
|
28
|
+
super().__init__(
|
|
29
|
+
decimal_mob,
|
|
30
|
+
suspend_mobject_updating=suspend_mobject_updating,
|
|
31
|
+
**kwargs
|
|
32
|
+
)
|
|
33
|
+
self.mobject = decimal_mob
|
|
34
|
+
|
|
35
|
+
def interpolate_mobject(self, alpha: float) -> None:
|
|
36
|
+
true_alpha = self.rate_func(self.time_spanned_alpha(alpha))
|
|
37
|
+
new_value = self.number_update_func(true_alpha)
|
|
38
|
+
self.mobject.set_value(new_value)
|
|
39
|
+
|
|
40
|
+
editor_thumbnail = (
|
|
41
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
42
|
+
'<text x="12" y="12.5" text-anchor="middle" fill="#DDDDDD" font-size="10" font-weight="700" font-family="sans-serif">4.2</text>'
|
|
43
|
+
'<path d="M3 18Q6 14.5 9 18T15 18T21 18" stroke="#58C4DD" stroke-width="1.3" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
|
|
44
|
+
'</svg>'
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ChangeDecimalToValue(ChangingDecimal):
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
decimal_mob: DecimalNumber,
|
|
52
|
+
target_number: Annotated[float | complex, Example('100')],
|
|
53
|
+
**kwargs
|
|
54
|
+
):
|
|
55
|
+
start_number = decimal_mob.number
|
|
56
|
+
super().__init__(
|
|
57
|
+
decimal_mob,
|
|
58
|
+
lambda a: interpolate(start_number, target_number, a),
|
|
59
|
+
**kwargs
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
editor_thumbnail = (
|
|
63
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
64
|
+
'<text x="10" y="16" text-anchor="middle" fill="#DDDDDD" font-size="10" font-weight="700" font-family="sans-serif">2.5</text>'
|
|
65
|
+
'<path d="M20 18V8" stroke="#83C167" stroke-width="1.6" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
|
|
66
|
+
'<path d="M20 6L21.5 8.6L18.5 8.6Z" fill="#83C167"/>'
|
|
67
|
+
'</svg>'
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class CountInFrom(ChangingDecimal):
|
|
72
|
+
def __init__(
|
|
73
|
+
self,
|
|
74
|
+
decimal_mob: DecimalNumber,
|
|
75
|
+
source_number: float | complex = 0,
|
|
76
|
+
**kwargs
|
|
77
|
+
):
|
|
78
|
+
start_number = decimal_mob.get_value()
|
|
79
|
+
super().__init__(
|
|
80
|
+
decimal_mob,
|
|
81
|
+
lambda a: interpolate(source_number, start_number, clip(a, 0, 1)),
|
|
82
|
+
**kwargs
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
editor_thumbnail = (
|
|
86
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
87
|
+
'<text x="5.5" y="15.5" text-anchor="middle" fill="#DDDDDD" fill-opacity="0.4" font-size="9" font-weight="700" font-family="sans-serif">0</text>'
|
|
88
|
+
'<path d="M9 12H13.5" stroke="#94A3B8" stroke-width="1.3" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
|
|
89
|
+
'<path d="M15.5 12L13.4 13.2L13.4 10.8Z" fill="#94A3B8"/>'
|
|
90
|
+
'<text x="19.5" y="16.5" text-anchor="middle" fill="#DDDDDD" font-size="11" font-weight="700" font-family="sans-serif">9</text>'
|
|
91
|
+
'</svg>'
|
|
92
|
+
)
|