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,260 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Subtitles drawn in the video, of what a scene's narration says, the word being said lit up.
|
|
3
|
+
|
|
4
|
+
voice = self.add_sound("overview1.wav", voice=True)
|
|
5
|
+
self.add_subtitles() # every voice of the scene, as Text
|
|
6
|
+
self.add_subtitles(text=MyTypstText, text_config=dict(font_size=40), highlight_color=YELLOW)
|
|
7
|
+
|
|
8
|
+
Each line is what the .srt has, see Transcript.groups, drawn by `text` when its first word is
|
|
9
|
+
said and kept until a little after its last, and each word in it is lit up from when it is said
|
|
10
|
+
until the next one is. The narration is transcribed with faster-whisper, see
|
|
11
|
+
datacut.scene.transcript, once for each sound.
|
|
12
|
+
|
|
13
|
+
`text` is a class, Text, TypstText or one of your own, or a function making a mobject from a
|
|
14
|
+
line. A Typst class is handed the line with Typst's markup escaped, which narration is not
|
|
15
|
+
written in; a function is handed it as it is, escape_typst being there for one making Typst.
|
|
16
|
+
|
|
17
|
+
Which glyphs are which word is worked out by counting: the glyphs of a Text or TypstText come in
|
|
18
|
+
the order of the characters they draw, spaces left out. Where the count is off, a ligature
|
|
19
|
+
drawing two letters as one say, they are shared out between the words from left to right in
|
|
20
|
+
proportion to how long each is.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
# What the Visual Editor files this module's classes under
|
|
25
|
+
__editor_category__ = 'Media & Shaders'
|
|
26
|
+
|
|
27
|
+
import re
|
|
28
|
+
from dataclasses import dataclass
|
|
29
|
+
|
|
30
|
+
import numpy as np
|
|
31
|
+
|
|
32
|
+
from datacut.constants import BLACK, DOWN, FRAME_WIDTH, WHITE, YELLOW
|
|
33
|
+
from datacut.mobject.shape_matchers import SurroundingRectangle
|
|
34
|
+
from datacut.mobject.types.vectorized_mobject import VGroup
|
|
35
|
+
from datacut.typing import UnsignedFloat
|
|
36
|
+
|
|
37
|
+
from typing import TYPE_CHECKING
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from datacut.typing import Opacity
|
|
41
|
+
from typing import Callable
|
|
42
|
+
from datacut.mobject.types.vectorized_mobject import VMobject
|
|
43
|
+
from datacut.scene.scene import Scene
|
|
44
|
+
from datacut.scene.sound_clip import SoundClip
|
|
45
|
+
from datacut.scene.transcript import Word
|
|
46
|
+
from datacut.typing import ManimColor, Vect3
|
|
47
|
+
|
|
48
|
+
__all__ = ["Subtitles", "escape_typst"]
|
|
49
|
+
|
|
50
|
+
# Characters Typst's markup gives a meaning to, which a backslash makes plain text again
|
|
51
|
+
_TYPST_SPECIAL = re.compile(r"([\\#$*_`<>@~=\-+/\[\]])")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def escape_typst(text: str) -> str:
|
|
55
|
+
"""`text` as Typst markup which shows it as it is"""
|
|
56
|
+
return _TYPST_SPECIAL.sub(r"\\\1", text)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class _Line:
|
|
61
|
+
"""One subtitle: its words, timed on the scene's clock"""
|
|
62
|
+
start: float
|
|
63
|
+
end: float
|
|
64
|
+
words: list[Word]
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def text(self) -> str:
|
|
68
|
+
return " ".join(w.text.strip() for w in self.words)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def word_glyphs(mob: VMobject, words: list[str]) -> list[list[VMobject]]:
|
|
72
|
+
"""
|
|
73
|
+
For a mobject drawing `words` separated by spaces, which of its glyphs draw each word: by
|
|
74
|
+
count where there are as many glyphs as characters other than spaces, otherwise shared out
|
|
75
|
+
from left to right in proportion to each word's length, see the module's docstring.
|
|
76
|
+
"""
|
|
77
|
+
glyphs = mob.family_members_with_points()
|
|
78
|
+
counts = [len(re.sub(r"\s", "", w)) for w in words]
|
|
79
|
+
total = sum(counts)
|
|
80
|
+
out: list[list[VMobject]] = []
|
|
81
|
+
if len(glyphs) == total:
|
|
82
|
+
i = 0
|
|
83
|
+
for n in counts:
|
|
84
|
+
out.append(glyphs[i:i + n])
|
|
85
|
+
i += n
|
|
86
|
+
return out
|
|
87
|
+
ordered = sorted(glyphs, key=lambda g: g.get_center()[0])
|
|
88
|
+
bounds = np.round(np.cumsum([0] + counts) / max(total, 1) * len(ordered)).astype(int)
|
|
89
|
+
return [ordered[a:b] for a, b in zip(bounds[:-1], bounds[1:])]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class Subtitles(VGroup):
|
|
93
|
+
"""
|
|
94
|
+
Subtitles of what `clips` say, drawn as the scene's clock reaches them, see the module's
|
|
95
|
+
docstring. Usually made with Scene.add_subtitles.
|
|
96
|
+
|
|
97
|
+
scene: whose clock to follow
|
|
98
|
+
clips: the narration, a list which sounds added later may still join, see
|
|
99
|
+
Scene.add_subtitles
|
|
100
|
+
text: a class or function making a line's mobject; Text at 36 points unless said otherwise
|
|
101
|
+
text_config: keyword arguments for `text`, where it is a class
|
|
102
|
+
highlight_color: what the word being said turns, None for no word to be lit up
|
|
103
|
+
edge, buff: where the lines sit, against which edge of the frame and how far in
|
|
104
|
+
max_width: how wide a line may be before it is shrunk to fit
|
|
105
|
+
background_opacity, background_color, background_buff: a box behind each line, none at 0
|
|
106
|
+
linger: how long a line stays after its last word, unless the next one comes sooner
|
|
107
|
+
transcription: options for transcribing, over the scene's, see Scene.set_transcription
|
|
108
|
+
group_options: max_chars, max_duration and max_gap, see Transcript.groups
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
def __init__(
|
|
112
|
+
self,
|
|
113
|
+
scene: Scene,
|
|
114
|
+
clips: list[SoundClip],
|
|
115
|
+
text: type | Callable[[str], VMobject] | None = None,
|
|
116
|
+
text_config: dict | None = None,
|
|
117
|
+
highlight_color: ManimColor | None = YELLOW,
|
|
118
|
+
edge: Vect3 = DOWN,
|
|
119
|
+
buff: float = 0.5,
|
|
120
|
+
max_width: UnsignedFloat = FRAME_WIDTH - 1.0,
|
|
121
|
+
background_opacity: Opacity = 0.0,
|
|
122
|
+
background_color: ManimColor = BLACK,
|
|
123
|
+
background_buff: float = 0.15,
|
|
124
|
+
linger: float = 0.4,
|
|
125
|
+
z_index: int = 100,
|
|
126
|
+
transcription: dict | None = None,
|
|
127
|
+
**group_options,
|
|
128
|
+
):
|
|
129
|
+
super().__init__()
|
|
130
|
+
self.scene = scene
|
|
131
|
+
self.clips = clips
|
|
132
|
+
self.make_line = self._line_maker(text, text_config or {})
|
|
133
|
+
self.highlight_color = highlight_color
|
|
134
|
+
self.edge = edge
|
|
135
|
+
self.buff = buff
|
|
136
|
+
self.max_width = max_width
|
|
137
|
+
self.background_opacity = background_opacity
|
|
138
|
+
self.background_color = background_color
|
|
139
|
+
self.background_buff = background_buff
|
|
140
|
+
self.linger = linger
|
|
141
|
+
self.line_z_index = z_index
|
|
142
|
+
self.transcription = dict(transcription or {})
|
|
143
|
+
self.group_options = group_options
|
|
144
|
+
# Each clip's lines, worked out the first time it is followed
|
|
145
|
+
self._lines: dict[int, list[_Line]] = {}
|
|
146
|
+
self._shown: _Line | None = None
|
|
147
|
+
self._lit: int | None = None
|
|
148
|
+
self._glyphs: list[list[VMobject]] = []
|
|
149
|
+
self._pristine: list[list[VMobject]] = []
|
|
150
|
+
self.fix_in_frame()
|
|
151
|
+
self.add_updater(lambda m: m.follow())
|
|
152
|
+
|
|
153
|
+
@staticmethod
|
|
154
|
+
def _line_maker(text, config: dict) -> Callable[[str], VMobject]:
|
|
155
|
+
if text is None:
|
|
156
|
+
from datacut.mobject.svg.text_mobject import Text
|
|
157
|
+
return lambda line: Text(line, **{"font_size": 36, **config})
|
|
158
|
+
if isinstance(text, type):
|
|
159
|
+
from datacut.mobject.svg.typst_mobject import SingleStringTypst
|
|
160
|
+
if issubclass(text, SingleStringTypst):
|
|
161
|
+
return lambda line: text(escape_typst(line), **config)
|
|
162
|
+
return lambda line: text(line, **config)
|
|
163
|
+
return text
|
|
164
|
+
|
|
165
|
+
# Following the clock
|
|
166
|
+
|
|
167
|
+
def lines(self) -> list[_Line]:
|
|
168
|
+
"""Every line of every clip followed, timed on the scene's clock, in order"""
|
|
169
|
+
out = []
|
|
170
|
+
for clip in list(self.clips):
|
|
171
|
+
key = id(clip)
|
|
172
|
+
if key not in self._lines:
|
|
173
|
+
transcript = clip.transcript(**self.transcription)
|
|
174
|
+
self._lines[key] = [
|
|
175
|
+
_Line(g[0].start + clip.scene_start, g[-1].end + clip.scene_start, [
|
|
176
|
+
type(w)(w.text, w.start + clip.scene_start, w.end + clip.scene_start, w.probability)
|
|
177
|
+
for w in g
|
|
178
|
+
])
|
|
179
|
+
for g in transcript.groups(**self.group_options)
|
|
180
|
+
]
|
|
181
|
+
out.extend(self._lines[key])
|
|
182
|
+
return sorted(out, key=lambda line: line.start)
|
|
183
|
+
|
|
184
|
+
def line_at(self, time: float) -> _Line | None:
|
|
185
|
+
"""The line showing at `time`: the last one begun, until it lingers no more"""
|
|
186
|
+
shown = None
|
|
187
|
+
for line in self.lines():
|
|
188
|
+
if line.start > time:
|
|
189
|
+
break
|
|
190
|
+
shown = line
|
|
191
|
+
if shown is not None and time >= shown.end + self.linger:
|
|
192
|
+
return None
|
|
193
|
+
return shown
|
|
194
|
+
|
|
195
|
+
@staticmethod
|
|
196
|
+
def word_at(line: _Line, time: float) -> int | None:
|
|
197
|
+
"""Which word of `line` is being said at `time`: the last begun, held until the next"""
|
|
198
|
+
lit = None
|
|
199
|
+
for i, word in enumerate(line.words):
|
|
200
|
+
if word.start <= time:
|
|
201
|
+
lit = i
|
|
202
|
+
return lit
|
|
203
|
+
|
|
204
|
+
def follow(self) -> Subtitles:
|
|
205
|
+
"""Shows the line and lights up the word the scene's clock is at"""
|
|
206
|
+
time = float(self.scene.get_time())
|
|
207
|
+
line = self.line_at(time)
|
|
208
|
+
if line is not self._shown:
|
|
209
|
+
self.show(line)
|
|
210
|
+
if line is not None and self.highlight_color is not None:
|
|
211
|
+
self.light(self.word_at(line, time))
|
|
212
|
+
return self
|
|
213
|
+
|
|
214
|
+
# Drawing
|
|
215
|
+
|
|
216
|
+
def show(self, line: _Line | None) -> None:
|
|
217
|
+
self._shown = line
|
|
218
|
+
self._lit = None
|
|
219
|
+
if line is None:
|
|
220
|
+
self._glyphs = []
|
|
221
|
+
self._pristine = []
|
|
222
|
+
self.set_submobjects([])
|
|
223
|
+
return
|
|
224
|
+
mob = self.make_line(line.text)
|
|
225
|
+
if mob.get_width() > self.max_width:
|
|
226
|
+
mob.set_width(self.max_width)
|
|
227
|
+
mob.to_edge(self.edge, buff=self.buff)
|
|
228
|
+
words = [w.text.strip() for w in line.words]
|
|
229
|
+
self._glyphs = word_glyphs(mob, words)
|
|
230
|
+
pristine = mob.copy()
|
|
231
|
+
self._pristine = word_glyphs(pristine, words)
|
|
232
|
+
parts = []
|
|
233
|
+
if self.background_opacity > 0:
|
|
234
|
+
box = SurroundingRectangle(mob, buff=self.background_buff)
|
|
235
|
+
box.set_fill(self.background_color, opacity=self.background_opacity)
|
|
236
|
+
box.set_stroke(width=0)
|
|
237
|
+
parts.append(box)
|
|
238
|
+
parts.append(mob)
|
|
239
|
+
self.set_submobjects(parts)
|
|
240
|
+
self.set_z_index(self.line_z_index)
|
|
241
|
+
self.fix_in_frame()
|
|
242
|
+
|
|
243
|
+
def light(self, index: int | None) -> None:
|
|
244
|
+
"""Lights up word `index`, putting back the one lit before"""
|
|
245
|
+
if index == self._lit:
|
|
246
|
+
return
|
|
247
|
+
if self._lit is not None and self._lit < len(self._glyphs):
|
|
248
|
+
for glyph, original in zip(self._glyphs[self._lit], self._pristine[self._lit]):
|
|
249
|
+
glyph.match_style(original)
|
|
250
|
+
if index is not None and index < len(self._glyphs):
|
|
251
|
+
for glyph in self._glyphs[index]:
|
|
252
|
+
glyph.set_color(self.highlight_color)
|
|
253
|
+
self._lit = index
|
|
254
|
+
|
|
255
|
+
editor_thumbnail = (
|
|
256
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
257
|
+
'<rect x="2" y="4" width="20" height="16" rx="1.5" fill="#1E293B" stroke="#94A3B8" stroke-width="1.2"/>'
|
|
258
|
+
'<path d="M6 14.5H18M8.5 17.5H15.5" stroke="#FFFF00" stroke-width="1.6" fill="none" stroke-linecap="round" stroke-linejoin="round"/>'
|
|
259
|
+
'</svg>'
|
|
260
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# What the Visual Editor files this module's classes under
|
|
4
|
+
__editor_category__ = 'Text & Math'
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
import math
|
|
8
|
+
import copy
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from datacut.constants import DEFAULT_MOBJECT_TO_MOBJECT_BUFF, SMALL_BUFF
|
|
13
|
+
from datacut.constants import DOWN, LEFT, ORIGIN, RIGHT, DL, DR, UL, UP
|
|
14
|
+
from datacut.constants import PI
|
|
15
|
+
from datacut.animation.composition import AnimationGroup
|
|
16
|
+
from datacut.animation.fading import FadeIn
|
|
17
|
+
from datacut.animation.growing import GrowFromCenter
|
|
18
|
+
from datacut.mobject.svg.tex_mobject import Tex
|
|
19
|
+
from datacut.mobject.svg.tex_mobject import TexText
|
|
20
|
+
from datacut.mobject.svg.text_mobject import Text
|
|
21
|
+
from datacut.mobject.types.vectorized_mobject import VGroup
|
|
22
|
+
from datacut.mobject.types.vectorized_mobject import VMobject
|
|
23
|
+
from datacut.utils.iterables import listify
|
|
24
|
+
from datacut.utils.space_ops import get_norm
|
|
25
|
+
from datacut.typing import UnsignedFloat
|
|
26
|
+
|
|
27
|
+
from typing import TYPE_CHECKING
|
|
28
|
+
|
|
29
|
+
if TYPE_CHECKING:
|
|
30
|
+
from typing import Iterable
|
|
31
|
+
|
|
32
|
+
from datacut.animation.animation import Animation
|
|
33
|
+
from datacut.mobject.mobject import Mobject
|
|
34
|
+
from datacut.typing import Vect3
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Brace(Tex):
|
|
38
|
+
# Drawn 24px wide in the editor's shelf: what reads at that size
|
|
39
|
+
editor_thumbnail_args = ('Square(side_length=0.5)',)
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
mobject: Mobject,
|
|
44
|
+
direction: Vect3 = DOWN,
|
|
45
|
+
buff: float = 0.2,
|
|
46
|
+
tex_string: str = R"\underbrace{\qquad}",
|
|
47
|
+
**kwargs
|
|
48
|
+
):
|
|
49
|
+
super().__init__(tex_string, **kwargs)
|
|
50
|
+
self._apply_brace_layout(mobject, direction, buff)
|
|
51
|
+
|
|
52
|
+
def _apply_brace_layout(
|
|
53
|
+
self,
|
|
54
|
+
mobject: Mobject,
|
|
55
|
+
direction: Vect3 = DOWN,
|
|
56
|
+
buff: float = 0.2,
|
|
57
|
+
) -> None:
|
|
58
|
+
points = self.get_all_points()
|
|
59
|
+
if len(points) == 0:
|
|
60
|
+
self.tip_point_index = 0
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
angle = -math.atan2(*direction[:2]) + PI
|
|
64
|
+
mobject.rotate(-angle, about_point=ORIGIN)
|
|
65
|
+
left = mobject.get_corner(DL)
|
|
66
|
+
right = mobject.get_corner(DR)
|
|
67
|
+
target_width = right[0] - left[0]
|
|
68
|
+
|
|
69
|
+
self.tip_point_index = int(np.argmin(points[:, 1]))
|
|
70
|
+
self.set_initial_width(target_width)
|
|
71
|
+
self.shift(left - self.get_corner(UL) + buff * DOWN)
|
|
72
|
+
for mob in mobject, self:
|
|
73
|
+
mob.rotate(angle, about_point=ORIGIN)
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
async def create(
|
|
77
|
+
cls,
|
|
78
|
+
mobject: Mobject,
|
|
79
|
+
direction: Vect3 = DOWN,
|
|
80
|
+
buff: float = 0.2,
|
|
81
|
+
tex_string: str = R"\underbrace{\qquad}",
|
|
82
|
+
**kwargs
|
|
83
|
+
) -> Brace:
|
|
84
|
+
if sys.platform != "emscripten":
|
|
85
|
+
return cls(mobject, direction=direction, buff=buff, tex_string=tex_string, **kwargs)
|
|
86
|
+
tex_mob = await Tex.create(tex_string, **kwargs)
|
|
87
|
+
obj = cls.__new__(cls)
|
|
88
|
+
obj.__dict__.update(tex_mob.__dict__)
|
|
89
|
+
obj.set_submobjects(list(tex_mob.submobjects))
|
|
90
|
+
obj._apply_brace_layout(mobject, direction, buff)
|
|
91
|
+
return obj
|
|
92
|
+
|
|
93
|
+
def set_initial_width(self, width: UnsignedFloat):
|
|
94
|
+
width_diff = width - self.get_width()
|
|
95
|
+
if width_diff > 0 and len(self) >= 6:
|
|
96
|
+
for tip, rect, vect in [(self[0], self[1], RIGHT), (self[5], self[4], LEFT)]:
|
|
97
|
+
rect.set_width(
|
|
98
|
+
width_diff / 2 + rect.get_width(),
|
|
99
|
+
about_edge=vect, stretch=True
|
|
100
|
+
)
|
|
101
|
+
tip.shift(-width_diff / 2 * vect)
|
|
102
|
+
else:
|
|
103
|
+
self.set_width(width, stretch=True)
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
def put_at_tip(
|
|
107
|
+
self,
|
|
108
|
+
mob: Mobject,
|
|
109
|
+
use_next_to: bool = True,
|
|
110
|
+
**kwargs
|
|
111
|
+
):
|
|
112
|
+
if use_next_to:
|
|
113
|
+
mob.next_to(
|
|
114
|
+
self.get_tip(),
|
|
115
|
+
np.round(self.get_direction()),
|
|
116
|
+
**kwargs
|
|
117
|
+
)
|
|
118
|
+
else:
|
|
119
|
+
mob.move_to(self.get_tip())
|
|
120
|
+
buff = kwargs.get("buff", DEFAULT_MOBJECT_TO_MOBJECT_BUFF)
|
|
121
|
+
shift_distance = mob.get_width() / 2.0 + buff
|
|
122
|
+
mob.shift(self.get_direction() * shift_distance)
|
|
123
|
+
return self
|
|
124
|
+
|
|
125
|
+
def get_text(self, text: str, **kwargs) -> Text:
|
|
126
|
+
buff = kwargs.pop("buff", SMALL_BUFF)
|
|
127
|
+
text_mob = Text(text, **kwargs)
|
|
128
|
+
self.put_at_tip(text_mob, buff=buff)
|
|
129
|
+
return text_mob
|
|
130
|
+
|
|
131
|
+
async def get_text_async(self, text: str, **kwargs) -> Text:
|
|
132
|
+
import inspect
|
|
133
|
+
buff = kwargs.pop("buff", SMALL_BUFF)
|
|
134
|
+
text_mob = Text.create(text, **kwargs)
|
|
135
|
+
if inspect.isawaitable(text_mob):
|
|
136
|
+
text_mob = await text_mob
|
|
137
|
+
self.put_at_tip(text_mob, buff=buff)
|
|
138
|
+
return text_mob
|
|
139
|
+
|
|
140
|
+
def get_tex(self, *tex: str, **kwargs) -> Tex:
|
|
141
|
+
buff = kwargs.pop("buff", SMALL_BUFF)
|
|
142
|
+
tex_mob = Tex(*tex, **kwargs)
|
|
143
|
+
self.put_at_tip(tex_mob, buff=buff)
|
|
144
|
+
return tex_mob
|
|
145
|
+
|
|
146
|
+
async def get_tex_async(self, *tex: str, **kwargs) -> Tex:
|
|
147
|
+
import inspect
|
|
148
|
+
buff = kwargs.pop("buff", SMALL_BUFF)
|
|
149
|
+
tex_mob = Tex.create(*tex, **kwargs)
|
|
150
|
+
if inspect.isawaitable(tex_mob):
|
|
151
|
+
tex_mob = await tex_mob
|
|
152
|
+
self.put_at_tip(tex_mob, buff=buff)
|
|
153
|
+
return tex_mob
|
|
154
|
+
|
|
155
|
+
def get_tip(self) -> np.ndarray:
|
|
156
|
+
# Very specific to the LaTeX representation
|
|
157
|
+
# of a brace, but it's the only way I can think
|
|
158
|
+
# of to get the tip regardless of orientation.
|
|
159
|
+
return self.get_all_points()[self.tip_point_index]
|
|
160
|
+
|
|
161
|
+
def get_direction(self) -> np.ndarray:
|
|
162
|
+
vect = self.get_tip() - self.get_center()
|
|
163
|
+
return vect / get_norm(vect)
|
|
164
|
+
|
|
165
|
+
editor_thumbnail = (
|
|
166
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
167
|
+
'<path d="M22.0 9.2Q22.0 9.1 22.0 9.1Q22.0 9.1 22.0 9.0Q22.0 8.9 22.0 8.9Q21.9 8.8 21.9 8.8Q21.9 8.8 21.8 8.8Q21.8 8.9 21.8 8.9Q21.7 9.6 21.4 10.0Q21.1 10.5 20.6 10.8Q20.2 11.0 19.8 11.1Q19.5 11.3 19.1 11.3Q16.9 11.3 14.8 11.3Q14.4 11.3 14.0 11.4Q13.6 11.6 13.3 11.9Q12.8 12.3 12.5 12.8Q12.2 13.3 12.0 14.0Q11.8 13.3 11.5 12.8Q11.2 12.3 10.7 11.9Q10.4 11.6 10.0 11.4Q9.6 11.3 9.2 11.3Q7.1 11.3 4.9 11.3Q4.5 11.3 4.2 11.1Q3.8 11.0 3.4 10.8Q2.9 10.5 2.6 10.0Q2.3 9.6 2.2 8.9Q2.2 8.9 2.2 8.8Q2.1 8.8 2.1 8.8Q2.1 8.8 2.0 8.9Q2.0 8.9 2.0 9.0Q2.0 9.1 2.0 9.1Q2.0 9.1 2.0 9.2Q2.1 10.0 2.5 10.7Q2.8 11.3 3.2 11.9Q3.7 12.3 4.1 12.5Q4.5 12.8 4.9 12.8Q7.1 12.8 9.2 12.8Q9.8 12.8 10.2 12.9Q10.7 13.1 11.1 13.3Q11.5 13.6 11.7 14.0Q11.9 14.4 11.9 15.0Q11.9 15.1 11.9 15.1Q11.9 15.2 12.0 15.2Q12.1 15.2 12.1 15.1Q12.1 15.1 12.1 15.0Q12.1 14.4 12.3 14.0Q12.5 13.6 12.9 13.3Q13.3 13.1 13.8 12.9Q14.2 12.8 14.8 12.8Q16.9 12.8 19.1 12.8Q19.5 12.8 19.9 12.5Q20.3 12.3 20.8 11.9Q21.2 11.3 21.5 10.7Q21.9 10.0 22.0 9.2Z" fill="#FFFFFF" fill-opacity="1.00" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
168
|
+
'</svg>'
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class BraceLabel(VMobject):
|
|
173
|
+
# Drawn 24px wide in the editor's shelf: what reads at that size
|
|
174
|
+
editor_thumbnail_args = ('Square(side_length=0.9)', 'r"x"')
|
|
175
|
+
|
|
176
|
+
label_constructor: type = Tex
|
|
177
|
+
|
|
178
|
+
def __init__(
|
|
179
|
+
self,
|
|
180
|
+
obj: VMobject | list[VMobject],
|
|
181
|
+
text: str | Iterable[str],
|
|
182
|
+
brace_direction: Vect3 = DOWN,
|
|
183
|
+
label_scale: float = 1.0,
|
|
184
|
+
label_buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFF,
|
|
185
|
+
**kwargs
|
|
186
|
+
) -> None:
|
|
187
|
+
super().__init__(**kwargs)
|
|
188
|
+
self.brace_direction = brace_direction
|
|
189
|
+
self.label_scale = label_scale
|
|
190
|
+
self.label_buff = label_buff
|
|
191
|
+
|
|
192
|
+
if isinstance(obj, list):
|
|
193
|
+
obj = VGroup(*obj)
|
|
194
|
+
self.brace = Brace(obj, brace_direction, **kwargs)
|
|
195
|
+
|
|
196
|
+
self.label = self.label_constructor(*listify(text), **kwargs)
|
|
197
|
+
self.label.scale(self.label_scale)
|
|
198
|
+
|
|
199
|
+
self.brace.put_at_tip(self.label, buff=self.label_buff)
|
|
200
|
+
self.set_submobjects([self.brace, self.label])
|
|
201
|
+
|
|
202
|
+
@classmethod
|
|
203
|
+
async def create(
|
|
204
|
+
cls,
|
|
205
|
+
obj: VMobject | list[VMobject],
|
|
206
|
+
text: str | Iterable[str],
|
|
207
|
+
brace_direction: np.ndarray = DOWN,
|
|
208
|
+
label_scale: float = 1.0,
|
|
209
|
+
label_buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFF,
|
|
210
|
+
**kwargs
|
|
211
|
+
) -> BraceLabel:
|
|
212
|
+
import inspect
|
|
213
|
+
if sys.platform != "emscripten":
|
|
214
|
+
return cls(
|
|
215
|
+
obj,
|
|
216
|
+
text,
|
|
217
|
+
brace_direction=brace_direction,
|
|
218
|
+
label_scale=label_scale,
|
|
219
|
+
label_buff=label_buff,
|
|
220
|
+
**kwargs,
|
|
221
|
+
)
|
|
222
|
+
inst = cls.__new__(cls)
|
|
223
|
+
VMobject.__init__(inst, **kwargs)
|
|
224
|
+
inst.brace_direction = brace_direction
|
|
225
|
+
inst.label_scale = label_scale
|
|
226
|
+
inst.label_buff = label_buff
|
|
227
|
+
|
|
228
|
+
if isinstance(obj, list):
|
|
229
|
+
obj = VGroup(*obj)
|
|
230
|
+
inst.brace = await Brace.create(obj, brace_direction, **kwargs)
|
|
231
|
+
|
|
232
|
+
ctor = getattr(inst.label_constructor, "create", inst.label_constructor)
|
|
233
|
+
label = ctor(*listify(text), **kwargs)
|
|
234
|
+
if inspect.isawaitable(label):
|
|
235
|
+
label = await label
|
|
236
|
+
inst.label = label
|
|
237
|
+
inst.label.scale(inst.label_scale)
|
|
238
|
+
|
|
239
|
+
inst.brace.put_at_tip(inst.label, buff=inst.label_buff)
|
|
240
|
+
inst.set_submobjects([inst.brace, inst.label])
|
|
241
|
+
return inst
|
|
242
|
+
|
|
243
|
+
def creation_anim(
|
|
244
|
+
self,
|
|
245
|
+
label_anim: Animation = FadeIn,
|
|
246
|
+
brace_anim: Animation = GrowFromCenter
|
|
247
|
+
) -> AnimationGroup:
|
|
248
|
+
return AnimationGroup(brace_anim(self.brace), label_anim(self.label))
|
|
249
|
+
|
|
250
|
+
def shift_brace(self, obj: VMobject | list[VMobject], **kwargs):
|
|
251
|
+
if isinstance(obj, list):
|
|
252
|
+
obj = VMobject(*obj)
|
|
253
|
+
self.brace = Brace(obj, self.brace_direction, **kwargs)
|
|
254
|
+
self.brace.put_at_tip(self.label)
|
|
255
|
+
self.submobjects[0] = self.brace
|
|
256
|
+
return self
|
|
257
|
+
|
|
258
|
+
async def shift_brace_async(self, obj: VMobject | list[VMobject], **kwargs):
|
|
259
|
+
if isinstance(obj, list):
|
|
260
|
+
obj = VMobject(*obj)
|
|
261
|
+
self.brace = await Brace.create(obj, self.brace_direction, **kwargs)
|
|
262
|
+
self.brace.put_at_tip(self.label)
|
|
263
|
+
self.submobjects[0] = self.brace
|
|
264
|
+
return self
|
|
265
|
+
|
|
266
|
+
def change_label(self, *text: str, **kwargs):
|
|
267
|
+
self.label = self.label_constructor(*text, **kwargs)
|
|
268
|
+
if self.label_scale != 1:
|
|
269
|
+
self.label.scale(self.label_scale)
|
|
270
|
+
|
|
271
|
+
self.brace.put_at_tip(self.label)
|
|
272
|
+
self.submobjects[1] = self.label
|
|
273
|
+
return self
|
|
274
|
+
|
|
275
|
+
async def change_label_async(self, *text: str, **kwargs):
|
|
276
|
+
import inspect
|
|
277
|
+
ctor = getattr(self.label_constructor, "create", self.label_constructor)
|
|
278
|
+
label = ctor(*text, **kwargs)
|
|
279
|
+
if inspect.isawaitable(label):
|
|
280
|
+
label = await label
|
|
281
|
+
self.label = label
|
|
282
|
+
if self.label_scale != 1:
|
|
283
|
+
self.label.scale(self.label_scale)
|
|
284
|
+
|
|
285
|
+
self.brace.put_at_tip(self.label)
|
|
286
|
+
self.submobjects[1] = self.label
|
|
287
|
+
return self
|
|
288
|
+
|
|
289
|
+
def change_brace_label(self, obj: VMobject | list[VMobject], *text: str):
|
|
290
|
+
self.shift_brace(obj)
|
|
291
|
+
self.change_label(*text)
|
|
292
|
+
return self
|
|
293
|
+
|
|
294
|
+
async def change_brace_label_async(self, obj: VMobject | list[VMobject], *text: str):
|
|
295
|
+
await self.shift_brace_async(obj)
|
|
296
|
+
await self.change_label_async(*text)
|
|
297
|
+
return self
|
|
298
|
+
|
|
299
|
+
def copy(self):
|
|
300
|
+
copy_mobject = copy.copy(self)
|
|
301
|
+
copy_mobject.brace = self.brace.copy()
|
|
302
|
+
copy_mobject.label = self.label.copy()
|
|
303
|
+
copy_mobject.set_submobjects([copy_mobject.brace, copy_mobject.label])
|
|
304
|
+
|
|
305
|
+
return copy_mobject
|
|
306
|
+
|
|
307
|
+
editor_thumbnail = (
|
|
308
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
309
|
+
'<path d="M22.0 5.2Q22.0 5.2 22.0 5.2Q22.0 5.2 22.0 5.1Q22.0 5.1 22.0 5.0Q21.9 5.0 21.9 5.0Q21.9 5.0 21.8 5.0Q21.8 5.0 21.8 5.1Q21.7 5.4 21.4 5.7Q21.1 6.0 20.6 6.1Q20.2 6.3 19.8 6.3Q19.5 6.4 19.1 6.4Q16.9 6.4 14.8 6.4Q14.4 6.4 14.0 6.5Q13.6 6.5 13.3 6.7Q12.8 6.9 12.5 7.2Q12.2 7.5 12.0 7.9Q11.8 7.5 11.5 7.2Q11.2 6.9 10.7 6.7Q10.4 6.5 10.0 6.5Q9.6 6.4 9.2 6.4Q7.1 6.4 4.9 6.4Q4.5 6.4 4.2 6.3Q3.8 6.3 3.4 6.1Q2.9 6.0 2.6 5.7Q2.3 5.4 2.2 5.1Q2.2 5.0 2.2 5.0Q2.1 5.0 2.1 5.0Q2.1 5.0 2.0 5.0Q2.0 5.1 2.0 5.1Q2.0 5.2 2.0 5.2Q2.0 5.2 2.0 5.2Q2.1 5.7 2.5 6.0Q2.8 6.4 3.2 6.7Q3.7 7.0 4.1 7.1Q4.5 7.2 4.9 7.2Q7.1 7.2 9.2 7.2Q9.8 7.2 10.2 7.3Q10.7 7.4 11.1 7.5Q11.5 7.7 11.7 7.9Q11.9 8.1 11.9 8.4Q11.9 8.5 11.9 8.5Q11.9 8.6 12.0 8.6Q12.1 8.6 12.1 8.5Q12.1 8.5 12.1 8.4Q12.1 8.1 12.3 7.9Q12.5 7.7 12.9 7.5Q13.3 7.4 13.8 7.3Q14.2 7.2 14.8 7.2Q16.9 7.2 19.1 7.2Q19.5 7.2 19.9 7.1Q20.3 7.0 20.8 6.7Q21.2 6.4 21.5 6.0Q21.9 5.7 22.0 5.2Z" fill="#FFFFFF" fill-opacity="1.00" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
310
|
+
'<path d="M14.8 14.9L14.5 14.3L13.8 14.1L12.7 14.9L12.2 14.3L10.8 14.3L10.2 14.9L9.9 15.4L9.8 15.9L9.9 15.9L10.1 15.8L10.6 14.9L11.9 14.6L12.0 15.1L11.9 15.9L11.1 18.4L10.5 18.7L10.1 18.6L10.4 18.4L10.5 18.0L10.0 17.6L9.6 17.8L9.7 18.8L10.5 19.0L11.6 18.3L12.0 18.8L12.7 19.0L14.0 18.3L14.3 17.7L14.4 17.2L14.3 17.2L14.2 17.2L13.6 18.2L12.7 18.7L12.2 18.0L12.2 17.7L12.7 15.6L13.1 14.7L13.7 14.4L14.2 14.5L13.8 14.7L13.8 15.4L14.2 15.5L14.8 14.9Z" fill="#FFFFFF" fill-opacity="1.00" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
311
|
+
'</svg>'
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class BraceText(BraceLabel):
|
|
316
|
+
# Drawn 24px wide in the editor's shelf: what reads at that size
|
|
317
|
+
editor_thumbnail_args = ('Square(side_length=0.9)', '"ab"')
|
|
318
|
+
|
|
319
|
+
label_constructor: type = TexText
|
|
320
|
+
|
|
321
|
+
editor_thumbnail = (
|
|
322
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
323
|
+
'<path d="M22.0 3.8Q22.0 3.8 22.0 3.8Q22.0 3.8 22.0 3.8Q22.0 3.7 22.0 3.7Q21.9 3.6 21.9 3.6Q21.9 3.6 21.8 3.7Q21.8 3.7 21.8 3.7Q21.7 4.1 21.4 4.3Q21.1 4.6 20.6 4.8Q20.2 4.9 19.8 5.0Q19.5 5.0 19.1 5.0Q16.9 5.0 14.8 5.0Q14.4 5.0 14.0 5.1Q13.6 5.2 13.3 5.4Q12.8 5.6 12.5 5.9Q12.2 6.2 12.0 6.6Q11.8 6.2 11.5 5.9Q11.2 5.6 10.7 5.4Q10.4 5.2 10.0 5.1Q9.6 5.0 9.2 5.0Q7.1 5.0 4.9 5.0Q4.5 5.0 4.2 5.0Q3.8 4.9 3.4 4.8Q2.9 4.6 2.6 4.3Q2.3 4.1 2.2 3.7Q2.2 3.7 2.2 3.7Q2.1 3.6 2.1 3.6Q2.1 3.6 2.0 3.7Q2.0 3.7 2.0 3.8Q2.0 3.8 2.0 3.8Q2.0 3.8 2.0 3.8Q2.1 4.3 2.5 4.7Q2.8 5.1 3.2 5.4Q3.7 5.6 4.1 5.7Q4.5 5.9 4.9 5.9Q7.1 5.9 9.2 5.9Q9.8 5.9 10.2 5.9Q10.7 6.0 11.1 6.2Q11.5 6.3 11.7 6.6Q11.9 6.8 11.9 7.1Q11.9 7.1 11.9 7.2Q11.9 7.2 12.0 7.2Q12.1 7.2 12.1 7.2Q12.1 7.1 12.1 7.1Q12.1 6.8 12.3 6.6Q12.5 6.3 12.9 6.2Q13.3 6.0 13.8 5.9Q14.2 5.9 14.8 5.9Q16.9 5.9 19.1 5.9Q19.5 5.9 19.9 5.7Q20.3 5.6 20.8 5.4Q21.2 5.1 21.5 4.7Q21.9 4.3 22.0 3.8Z" fill="#FFFFFF" fill-opacity="1.00" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
324
|
+
'<path d="M10.7 17.2L10.7 16.6L10.4 16.0L9.7 15.6L8.8 15.4L7.8 15.7L7.2 16.6L7.4 17.0L7.7 17.1L8.1 17.0L8.2 16.6L8.1 16.3L7.7 16.1L8.2 15.8L8.8 15.6L9.6 16.0L10.0 17.0L7.5 18.1L6.9 19.2L7.5 20.1L8.6 20.4L9.5 20.1L10.0 19.4L10.2 19.9L10.9 20.3L11.5 20.1L11.8 19.3L11.8 18.7L11.5 18.7L11.5 19.3L11.4 19.8L11.1 20.0L10.8 19.8L10.7 17.2ZM10.0 18.7Q10.0 19.4 9.5 19.8Q9.2 20.1 8.7 20.1Q8.3 20.1 8.0 19.8Q7.7 19.6 7.7 19.2Q7.7 18.7 8.2 18.3Q8.7 17.7 10.0 17.7Q10.0 18.2 10.0 18.7Z" fill="#FFFFFF" fill-opacity="1.00" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
325
|
+
'<path d="M13.7 16.2Q13.7 14.5 13.7 12.8Q13.7 12.8 13.7 12.8Q13.6 12.8 12.9 12.8Q12.2 12.9 12.1 12.9Q12.1 13.0 12.1 13.2Q12.2 13.2 12.3 13.2Q12.6 13.2 12.8 13.3Q12.9 13.4 13.0 13.6Q13.0 13.6 13.0 16.4Q13.0 16.7 13.0 16.9Q13.0 18.6 13.0 20.2Q13.1 20.2 13.2 20.2Q13.4 19.9 13.6 19.6Q13.9 20.0 14.4 20.2Q14.7 20.4 15.1 20.4Q16.0 20.4 16.7 19.7Q17.4 19.0 17.4 17.9Q17.4 16.9 16.8 16.2Q16.1 15.5 15.2 15.5Q14.8 15.5 14.5 15.6Q14.0 15.8 13.7 16.2ZM15.0 20.1Q14.7 20.1 14.5 20.0Q14.2 19.9 13.9 19.5Q13.9 19.5 13.9 19.5Q13.7 19.3 13.7 19.1Q13.7 17.9 13.7 16.7Q13.7 16.4 14.1 16.1Q14.5 15.7 15.1 15.7Q15.6 15.7 16.0 16.1Q16.5 16.7 16.5 17.8Q16.5 18.3 16.5 18.7Q16.4 19.3 16.1 19.6Q15.9 19.8 15.6 20.0Q15.3 20.1 15.0 20.1Z" fill="#FFFFFF" fill-opacity="1.00" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
326
|
+
'</svg>'
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class LineBrace(Brace):
|
|
331
|
+
# Drawn 24px wide in the editor's shelf: what reads at that size
|
|
332
|
+
editor_thumbnail_args = ('Line(LEFT * 0.25, RIGHT * 0.25)',)
|
|
333
|
+
|
|
334
|
+
def __init__(self, line: Line, direction: Vect3 = UP, **kwargs):
|
|
335
|
+
angle = line.get_angle()
|
|
336
|
+
line.rotate(-angle)
|
|
337
|
+
super().__init__(line, direction, **kwargs)
|
|
338
|
+
line.rotate(angle)
|
|
339
|
+
self.rotate(angle, about_point=line.get_center())
|
|
340
|
+
|
|
341
|
+
@classmethod
|
|
342
|
+
async def create(cls, line: Line, direction=UP, **kwargs) -> LineBrace:
|
|
343
|
+
if sys.platform != "emscripten":
|
|
344
|
+
return cls(line, direction=direction, **kwargs)
|
|
345
|
+
angle = line.get_angle()
|
|
346
|
+
line.rotate(-angle)
|
|
347
|
+
brace = await super().create(line, direction, **kwargs)
|
|
348
|
+
line.rotate(angle)
|
|
349
|
+
brace.rotate(angle, about_point=line.get_center())
|
|
350
|
+
return brace
|
|
351
|
+
|
|
352
|
+
editor_thumbnail = (
|
|
353
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">'
|
|
354
|
+
'<path d="M2.0 14.8Q2.0 14.9 2.0 14.9Q2.0 14.9 2.0 15.0Q2.0 15.1 2.0 15.1Q2.1 15.2 2.1 15.2Q2.1 15.2 2.2 15.2Q2.2 15.1 2.2 15.1Q2.3 14.4 2.6 14.0Q2.9 13.5 3.4 13.2Q3.8 13.0 4.2 12.9Q4.5 12.7 4.9 12.7Q7.1 12.7 9.2 12.7Q9.6 12.7 10.0 12.6Q10.4 12.4 10.7 12.1Q11.2 11.7 11.5 11.2Q11.8 10.7 12.0 10.0Q12.2 10.7 12.5 11.2Q12.8 11.7 13.3 12.1Q13.6 12.4 14.0 12.6Q14.4 12.7 14.8 12.7Q16.9 12.7 19.1 12.7Q19.5 12.7 19.8 12.9Q20.2 13.0 20.6 13.2Q21.1 13.5 21.4 14.0Q21.7 14.4 21.8 15.1Q21.8 15.1 21.8 15.2Q21.9 15.2 21.9 15.2Q21.9 15.2 22.0 15.1Q22.0 15.1 22.0 15.0Q22.0 14.9 22.0 14.9Q22.0 14.9 22.0 14.8Q21.9 14.0 21.5 13.3Q21.2 12.7 20.8 12.1Q20.3 11.7 19.9 11.5Q19.5 11.2 19.1 11.2Q16.9 11.2 14.8 11.2Q14.2 11.2 13.8 11.1Q13.3 10.9 12.9 10.7Q12.5 10.4 12.3 10.0Q12.1 9.6 12.1 9.0Q12.1 8.9 12.1 8.9Q12.1 8.8 12.0 8.8Q11.9 8.8 11.9 8.9Q11.9 8.9 11.9 9.0Q11.9 9.6 11.7 10.0Q11.5 10.4 11.1 10.7Q10.7 10.9 10.2 11.1Q9.8 11.2 9.2 11.2Q7.1 11.2 4.9 11.2Q4.5 11.2 4.1 11.5Q3.7 11.7 3.2 12.1Q2.8 12.7 2.5 13.3Q2.1 14.0 2.0 14.8Z" fill="#FFFFFF" fill-opacity="1.00" fill-rule="evenodd" stroke-linejoin="round"/>'
|
|
355
|
+
'</svg>'
|
|
356
|
+
)
|