From c7ef8404b743a272c4a905cbfac164d7ad1b41af Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 10 Jun 2025 08:02:32 -0700 Subject: [PATCH] Video work (#2356) * Only use -no-pdf for xelatex rendering * Instead of tracking du and dv points on surface, track points off the surface in the normal direction This means that surface shading will not necessarily work well for arbitrary transformations of the surface. But the existing solution was flimsy anyway, and caused annoying issues with singularity points. * Have density of anchor points on arcs depend on arc length * Allow for specifying true normals and orientation of Sphere * Change miter threshold on stroke shader * Add get_start_and_end to DashedLine * Add min_total_width option to DecimalNumber * Have BackgroundRectangle.set_style absorb (and ignore) added configuration Note, this feels suboptimal * Add LineBrace * Update font_size adjustment in Tex * Add scale_factor parameter to BulletedList.fade_all_but * Minor import tweaks * Add play_sound * Small if -> elif update * Always use Group for FadeTransform * Use time_spanned_alpha in ChangingDecimal * Change priority of number_config vs. self.decimal_number_config in NumberLine init * Fix clock animation * Allow sample_coords to be passed into VectorField --- manimlib/animation/composition.py | 2 +- manimlib/animation/fading.py | 3 ++- manimlib/animation/numbers.py | 6 +++--- manimlib/mobject/number_line.py | 2 +- manimlib/mobject/svg/drawings.py | 2 ++ manimlib/mobject/vector_field.py | 10 +++++++--- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/manimlib/animation/composition.py b/manimlib/animation/composition.py index 40b09dcf..aa99860b 100644 --- a/manimlib/animation/composition.py +++ b/manimlib/animation/composition.py @@ -43,7 +43,7 @@ class AnimationGroup(Animation): mobs = remove_list_redundancies([a.mobject for a in self.animations]) if group is not None: self.group = group - if group_type is not None: + elif group_type is not None: self.group = group_type(*mobs) elif all(isinstance(anim.mobject, VMobject) for anim in animations): self.group = VGroup(*mobs) diff --git a/manimlib/animation/fading.py b/manimlib/animation/fading.py index c4840ab8..18fa9ff8 100644 --- a/manimlib/animation/fading.py +++ b/manimlib/animation/fading.py @@ -6,6 +6,7 @@ from manimlib.animation.animation import Animation from manimlib.animation.transform import Transform from manimlib.constants import ORIGIN from manimlib.mobject.types.vectorized_mobject import VMobject +from manimlib.mobject.mobject import Group from manimlib.utils.bezier import interpolate from manimlib.utils.rate_functions import there_and_back @@ -101,7 +102,7 @@ class FadeTransform(Transform): self.dim_to_match = dim_to_match mobject.save_state() - super().__init__(mobject.get_group_class()(mobject, target_mobject.copy()), **kwargs) + super().__init__(Group(mobject, target_mobject.copy()), **kwargs) def begin(self) -> None: self.ending_mobject = self.mobject.copy() diff --git a/manimlib/animation/numbers.py b/manimlib/animation/numbers.py index 4a192b6a..d62b5ae4 100644 --- a/manimlib/animation/numbers.py +++ b/manimlib/animation/numbers.py @@ -29,9 +29,9 @@ class ChangingDecimal(Animation): self.mobject = decimal_mob def interpolate_mobject(self, alpha: float) -> None: - self.mobject.set_value( - self.number_update_func(alpha) - ) + true_alpha = self.time_spanned_alpha(alpha) + new_value = self.number_update_func(true_alpha) + self.mobject.set_value(new_value) class ChangeDecimalToValue(ChangingDecimal): diff --git a/manimlib/mobject/number_line.py b/manimlib/mobject/number_line.py index 7f27f6a9..57456eff 100644 --- a/manimlib/mobject/number_line.py +++ b/manimlib/mobject/number_line.py @@ -164,7 +164,7 @@ class NumberLine(Line): **number_config ) -> DecimalNumber: number_config = merge_dicts_recursively( - number_config, self.decimal_number_config, + self.decimal_number_config, number_config, ) if direction is None: direction = self.line_to_number_direction diff --git a/manimlib/mobject/svg/drawings.py b/manimlib/mobject/svg/drawings.py index fa278f40..4f105627 100644 --- a/manimlib/mobject/svg/drawings.py +++ b/manimlib/mobject/svg/drawings.py @@ -344,6 +344,8 @@ class ClockPassesTime(AnimationGroup): angle=12 * hour_radians, **rot_kwargs ), + group=clock, + run_time=run_time, **kwargs ) diff --git a/manimlib/mobject/vector_field.py b/manimlib/mobject/vector_field.py index b349e7e5..89e3d9ae 100644 --- a/manimlib/mobject/vector_field.py +++ b/manimlib/mobject/vector_field.py @@ -145,6 +145,7 @@ class VectorField(VMobject): func: Callable[[VectArray], VectArray], # Typically a set of Axes or NumberPlane coordinate_system: CoordinateSystem, + sample_coords: Optional[VectArray] = None, density: float = 2.0, magnitude_range: Optional[Tuple[float, float]] = None, color: Optional[ManimColor] = None, @@ -168,14 +169,17 @@ class VectorField(VMobject): self.norm_to_opacity_func = norm_to_opacity_func # Search for sample_points - self.sample_coords = get_sample_coords(coordinate_system, density) + if sample_coords is not None: + self.sample_coords = sample_coords + else: + self.sample_coords = get_sample_coords(coordinate_system, density) self.update_sample_points() if max_vect_len is None: step_size = get_norm(self.sample_points[1] - self.sample_points[0]) self.max_displayed_vect_len = max_vect_len_to_step_size * step_size else: - self.max_displayed_vect_len = max_vect_len * coordinate_system.get_x_unit_size() + self.max_displayed_vect_len = max_vect_len * coordinate_system.x_axis.get_unit_size() # Prepare the color map if magnitude_range is None: @@ -406,7 +410,7 @@ class StreamLines(VGroup): noise_factor = self.noise_factor if noise_factor is None: - noise_factor = (cs.get_x_unit_size() / self.density) * 0.5 + noise_factor = (cs.x_axis.get_unit_size() / self.density) * 0.5 return np.array([ coords + noise_factor * np.random.random(coords.shape)