diff --git a/manimlib/continual_animation/continual_animation.py b/manimlib/continual_animation/continual_animation.py index 5552047f..f4837dc1 100644 --- a/manimlib/continual_animation/continual_animation.py +++ b/manimlib/continual_animation/continual_animation.py @@ -68,13 +68,3 @@ class ContinualAnimationGroup(ContinualAnimation): def update_mobject(self, dt): for continual_animation in self.continual_animations: continual_animation.update(dt) - - -class ContinualMovement(ContinualAnimation): - CONFIG = { - "direction": RIGHT, - "rate": 0.05, # Units per second - } - - def update_mobject(self, dt): - self.mobject.shift(dt * self.rate * self.direction) diff --git a/manimlib/for_3b1b_videos/common_scenes.py b/manimlib/for_3b1b_videos/common_scenes.py index 5d268a28..9c06105a 100644 --- a/manimlib/for_3b1b_videos/common_scenes.py +++ b/manimlib/for_3b1b_videos/common_scenes.py @@ -6,7 +6,6 @@ from manimlib.animation.creation import Write from manimlib.animation.fading import FadeIn from manimlib.animation.fading import FadeOut from manimlib.constants import * -from manimlib.continual_animation.continual_animation import ContinualMovement from manimlib.for_3b1b_videos.pi_creature import Mortimer from manimlib.for_3b1b_videos.pi_creature import Randolph from manimlib.for_3b1b_videos.pi_creature_animations import Blink @@ -19,6 +18,7 @@ from manimlib.mobject.svg.drawings import Logo from manimlib.mobject.svg.drawings import PatreonLogo from manimlib.mobject.svg.tex_mobject import TextMobject from manimlib.mobject.types.vectorized_mobject import VGroup +from manimlib.mobject.mobject_update_utils import always_shift from manimlib.scene.moving_camera_scene import MovingCameraScene from manimlib.scene.scene import Scene from manimlib.utils.rate_functions import linear @@ -243,13 +243,13 @@ class PatreonEndScreen(PatreonThanks, PiCreatureScene): vect = columns.target.get_center() - columns.get_center() distance = get_norm(vect) wait_time = 20 - columns_shift = ContinualMovement( + always_shift( columns, direction=normalize(vect), rate=(distance / wait_time) ) - self.add(columns_shift, black_rect, line, thanks) + self.add(columns, black_rect, line, thanks) self.wait(wait_time) diff --git a/manimlib/mobject/mobject_update_utils.py b/manimlib/mobject/mobject_update_utils.py index 20779804..519cae33 100644 --- a/manimlib/mobject/mobject_update_utils.py +++ b/manimlib/mobject/mobject_update_utils.py @@ -22,9 +22,11 @@ def always_shift(mobject, direction=RIGHT, rate=0.1): mobject.add_updater( lambda m, dt: m.shift(dt * rate * direction) ) + return mobject def always_rotate(mobject, rate=20 * DEGREES, **kwargs): mobject.add_updater( lambda m, dt: m.rotate(dt * rate, **kwargs) ) + return mobject diff --git a/old_projects/WindingNumber_G.py b/old_projects/WindingNumber_G.py index 52284387..a6299786 100644 --- a/old_projects/WindingNumber_G.py +++ b/old_projects/WindingNumber_G.py @@ -3074,130 +3074,6 @@ class MentionFree(PiCreatureScene): self.play(morty.change, "gracious", OUT) self.wait(4) -class PatreonScroll(Scene): - CONFIG = { - "specific_patrons" : [ - "Juan Benet", - "Chloe Zhou", - "Ross Garber", - "Desmos", - "Burt Humburg", - "CrypticSwarm", - "Sergei", - "Devin Scott", - "George John", - "Akash Kumar", - "Felix Tripier", - "Arthur Zey", - "David Kedmey", - "Ali Yahya", - "Mayank M. Mehrotra", - "Lukas Biewald", - "Yana Chernobilsky", - "Kaustuv DeBiswas", - "Yu Jun", - "Dave Nicponski", - "Damion Kistler", - "Patrick Mézard", - "Jordan Scales", - "Markus Persson", - "Britt Selvitelle", - "Jonathan Wilson", - "Ryan Atallah", - "Joseph John Cox", - "Luc Ritchie", - "Steven Tomlinson", - "Shìmín Ku$\\overline{\\text{a}}$ng", - "Jameel Syed", - "Bong Choung", - "Ignacio Freiberg", - "Zhilong Yang", - "Karl Niu", - "Dan Esposito (Guardion)", - "Giovanni Filippi", - "Eric Younge", - "Prasant Jagannath", - "Cody Brocious", - "Jacob Kohl", - "James H. Park", - "Norton Wang", - "Kevin Le", - "Alexander Feldman", - "Tianyu Ge", - "David MacCumber", - "Oliver Steele", - "Yaw Etse", - "David B", - "Waleed Hamied", - "George Chiesa", - "supershabam", - "Delton Ding", - "Thomas Tarler", - "Jonathan Eppele", - "Isak Hietala", - "1stViewMaths", - "Jacob Magnuson", - "Mark Govea", - "Clark Gaebel", - "Mathias Jansson", - "David Clark", - "Michael Gardner", - "Mads Elvheim", - "Awoo", - "Dr. David G. Stork", - "Ted Suzman", - "Linh Tran", - "Andrew Busey", - "John Haley", - "Ankalagon", - "Eric Lavault", - "Boris Veselinovich", - "Julian Pulgarin", - "Jeff Linse", - "Cooper Jones", - "Ryan Dahl", - "Robert Teed", - "Jason Hise", - "Meshal Alshammari", - "Bernd Sing", - "James Thornton", - "Mustafa Mahdi", - "Mathew Bramson", - "Jerry Ling", - "Mèngzi Yì", - "Rish Kundalia", - "Achille Brighton", - "Ripta Pasay", - ], - "random_seed" : 1, - } - def construct(self): - patreon_logo = PatreonLogo() - patreon_logo.to_corner(UP+RIGHT) - patreon_logo.shift(SMALL_BUFF*LEFT) - self.add(patreon_logo) - - patrons = VGroup(*list(map(TextMobject, self.specific_patrons))) - patrons.scale(0.75) - random.shuffle(patrons.submobjects) - patrons.arrange(DOWN, aligned_edge = LEFT) - patrons.next_to(ORIGIN, DOWN) - patrons.to_edge(RIGHT) - - # patorons = patrons[:10] ##TO remove - - scroll = ContinualMovement(patrons, direction = UP, rate = 1) - def patrons_opacity_update(patrons): - for patron in patrons: - y = patron.get_center()[1] - if y > 3.5: - patrons.remove(patron) - alpha = smooth(np.clip(2.5 - y, 0, 1)) - patron.set_fill(opacity = alpha) - opacity_update = ContinualUpdate(patrons, patrons_opacity_update) - - self.add(scroll, opacity_update) - self.wait(55) class EndScreen(PatreonEndScreen, PiCreatureScene): CONFIG = { diff --git a/old_projects/basel/basel2.py b/old_projects/basel/basel2.py index f07dee5e..0e547ccb 100644 --- a/old_projects/basel/basel2.py +++ b/old_projects/basel/basel2.py @@ -3844,7 +3844,7 @@ class ThinkBackToHowAmazingThisIs(ThreeDScene): for n in range(0, self.max_shown_n, 2) ]) - zoom_out = ContinualMovement( + zoom_out = always_shift( self.camera.rotation_mobject, direction = OUT, rate = 0.4 ) diff --git a/old_projects/borsuk_addition.py b/old_projects/borsuk_addition.py index 9c3bcae1..d6cc6bd3 100644 --- a/old_projects/borsuk_addition.py +++ b/old_projects/borsuk_addition.py @@ -27,12 +27,12 @@ class Introduction(TeacherStudentsScene): student.add_updater( lambda m: m.move_to(m.center_tracker) ) - movement = ContinualMovement( + always_shift( student.center_tracker, direction=DOWN + 3 * LEFT, rate=1.5 * random.random() ) - movements.append(movement) + movements.append(student.center_tracker) self.add(*movements) self.change_student_modes( "pondering", "sad", "concerned_musician", diff --git a/old_projects/div_curl.py b/old_projects/div_curl.py index 0bdb62fd..32c154e3 100644 --- a/old_projects/div_curl.py +++ b/old_projects/div_curl.py @@ -1889,7 +1889,8 @@ class DefineDivergenceSymbols(Scene): output = DecimalNumber(0, include_sign=True) output.next_to(tex_mob, RIGHT) time_tracker = ValueTracker() - self.add(ContinualMovement(time_tracker, rate=1)) + always_shift(time_tracker, rate=1) + self.add(time_tracker) output_animation = ContinualChangingDecimal( output, lambda a: 3 * np.cos(int(time_tracker.get_value())), ) diff --git a/old_projects/fourier.py b/old_projects/fourier.py index 7c25846c..47601333 100644 --- a/old_projects/fourier.py +++ b/old_projects/fourier.py @@ -2877,17 +2877,15 @@ class WriteComplexExponentialExpression(DrawFrequencyPlot): self.wait() ghost_dot.move_to(ORIGIN) - ambient_ghost_dot_movement = ContinualMovement( - ghost_dot, rate = TAU - ) - self.add(ambient_ghost_dot_movement) + always_shift(ghost_dot, rate = TAU) + self.add(ghost_dot) self.play( Write(time_label), GrowArrow(time_label.arrow), ) self.wait(12.5) #Leave time to say let's slow down - self.remove(ambient_ghost_dot_movement) + self.remove(ghost_dot) self.play( FadeOut(time_label), FadeIn(frequency_label), @@ -2899,10 +2897,9 @@ class WriteComplexExponentialExpression(DrawFrequencyPlot): ) ) ghost_dot.move_to(ORIGIN) - ambient_ghost_dot_movement = ContinualMovement( - ghost_dot, rate = 0.1*TAU - ) - self.add(ambient_ghost_dot_movement) + ghost_dot.clear_updaters() + always_shift(ghost_dot, rate=0.1*TAU) + self.add(ghost_dot) self.wait(3) self.play( FadeOut(frequency_label), @@ -2910,7 +2907,8 @@ class WriteComplexExponentialExpression(DrawFrequencyPlot): ) self.wait(15) #Give time to reference other video #Reverse directions - ambient_ghost_dot_movement.rate *= -1 + ghost_dot.clear_updaters() + always_shift(ghost_dot, rate=-0.1 * TAU) self.play( FadeOut(example_frequency), FadeOut(frequency_label.arrow), @@ -2919,7 +2917,7 @@ class WriteComplexExponentialExpression(DrawFrequencyPlot): ) self.wait(4) - ambient_ghost_dot_movement.rate = 0 + ghost_dot.clear_updaters() self.remove(*updates) self.play(*list(map(FadeOut, [ update.mobject diff --git a/old_projects/gradient.py b/old_projects/gradient.py index aa7bf41b..be6ab754 100644 --- a/old_projects/gradient.py +++ b/old_projects/gradient.py @@ -48,7 +48,8 @@ class ShowSimpleMultivariableFunction(Scene): decimal.scale(scale_val) decimal.next_to(tex, RIGHT) value_tracker = ValueTracker(0) - self.add(ContinualMovement(value_tracker, rate=0.5)) + always_shift(value_tracker, rate=0.5) + self.add(value_tracker) decimal_change = ContinualChangingDecimal( decimal, lambda a: 1 + np.sin(value_tracker.get_value()) diff --git a/old_projects/lost_lecture.py b/old_projects/lost_lecture.py index af2a3670..de1ac3a5 100644 --- a/old_projects/lost_lecture.py +++ b/old_projects/lost_lecture.py @@ -1215,9 +1215,7 @@ class ShowEllipseDefiningProperty(Scene): ) ) ) - position_tracker_wander = ContinualMovement( - position_tracker, rate=0.05, - ) + always_shift(position_tracker, rate=0.05) lines, lines_update_animation = self.get_focal_lines_and_update( self.get_foci, dot @@ -1233,7 +1231,7 @@ class ShowEllipseDefiningProperty(Scene): )) self.play(ShowCreation(lines)) self.add(lines_update_animation) - self.add(position_tracker_wander) + self.add(position_tracker) self.wait(2) self.position_tracker = position_tracker diff --git a/old_projects/uncertainty.py b/old_projects/uncertainty.py index 65a8a57a..2405248d 100644 --- a/old_projects/uncertainty.py +++ b/old_projects/uncertainty.py @@ -531,16 +531,14 @@ class ShowPlan(PiCreatureScene): rect = BackgroundRectangle(wave, fill_opacity = 1) rect.stretch(2, 1) rect.next_to(wave, LEFT, buff = 0) - wave_shift = ContinualMovement( - wave, direction = LEFT, rate = 5 - ) + always_shift(wave, direction=LEFT, rate=5) wave_fader = UpdateFromAlphaFunc( wave, lambda w, a : w.set_stroke(width = 3*a) ) checkmark = self.get_checkmark(word) - self.add(wave_shift) + self.add(wave) self.add_foreground_mobjects(rect, word) self.play( Animation(word), @@ -567,13 +565,13 @@ class ShowPlan(PiCreatureScene): target = Plane() # target.match_height(radar_dish) target.next_to(radar_dish, RIGHT, buff = LARGE_BUFF) - target_movement = ContinualMovement(target, direction = RIGHT, rate = 1.25) + always_shift(target, direction = RIGHT, rate = 1.25) pulse = RadarPulse(radar_dish, target) checkmark = self.get_checkmark(word) - self.add(target_movement) + self.add(target) self.play( Write(word), DrawBorderThenFill(radar_dish), @@ -1653,11 +1651,7 @@ class MentionDopplerRadar(TeacherStudentsScene): plane = Plane() plane.to_edge(RIGHT) plane.align_to(dish) - plane_flight = ContinualMovement( - plane, - direction = LEFT, - rate = 1, - ) + always_shift(plane, LEFT, 1) plane.flip() pulse = RadarPulse(dish, plane) look_at_anims = [ @@ -1667,7 +1661,7 @@ class MentionDopplerRadar(TeacherStudentsScene): for pi in self.get_pi_creatures() ] - self.add(dish, plane_flight, pulse, *look_at_anims) + self.add(dish, plane, pulse, *look_at_anims) self.play( self.teacher.change, "hooray", words.restore @@ -1834,11 +1828,9 @@ class IntroduceDopplerRadar(Scene): ShowCreation(sum_graph, run_time = 8, rate_func=linear) ) pulse = RadarPulse(dish, plane, n_pulse_singletons = 12) - plane_flight = ContinualMovement( - plane, direction = LEFT, rate = 1.5 - ) + always_shift(plane, LEFT, 1.5) - self.add(graph_draw, pulse, plane_flight) + self.add(graph_draw, pulse, plane) self.play(UpdateFromAlphaFunc( plane, lambda m, a : m.set_fill(opacity = a) )) @@ -1859,7 +1851,7 @@ class IntroduceDopplerRadar(Scene): self.wait(0.1) self.play(Write(echo_subtext, run_time = 1)) self.wait() - self.remove(graph_draw, pulse, plane_flight) + self.remove(graph_draw, pulse, plane) pulse_graph.set_stroke(width = 0) echo_graph.set_stroke(width = 0) @@ -2613,7 +2605,7 @@ class AmbiguityInLongEchos(IntroduceDopplerRadar, PiCreatureScene): object_velocities = self.object_velocities movements = self.object_movements = [ - ContinualMovement( + always_shift( obj, direction = v/get_norm(v), rate = get_norm(v) @@ -3289,7 +3281,7 @@ class SortOfDopplerEffect(PiCreatureScene): t_tracker = VectorizedPoint() #x-coordinate gives wave number k_tracker = VectorizedPoint(2*RIGHT) - tk_movement = ContinualMovement(t_tracker, direction = RIGHT, rate = 1) + always_shift(t_tracker, RIGHT, 1) def get_wave(): t = t_tracker.get_center()[0] k = k_tracker.get_center()[0] @@ -3322,7 +3314,8 @@ class SortOfDopplerEffect(PiCreatureScene): rect = ScreenRectangle(height = 2) rect.to_edge(RIGHT) - rect_movement = ContinualMovement(rect, direction = LEFT, rate = 1) + always_shift(rect, LEFT, 1) + rect_movement = rect randy = self.pi_creature randy_look_at = ContinualUpdate( @@ -3341,7 +3334,7 @@ class SortOfDopplerEffect(PiCreatureScene): ref_frame_1_continual_anim = ContinualAnimation(ref_frame1) self.add( - tk_movement, wave_update, rect_movement, randy_look_at, + t_tracker, wave_update, rect_movement, randy_look_at, ref_frame2_follow, ref_frame_1_continual_anim ) self.add(ref_frame1) @@ -3446,7 +3439,8 @@ class HangingWeightsScene(MovingCameraScene): k_tracker = self.k_tracker = VectorizedPoint() t_tracker = self.t_tracker = VectorizedPoint() - self.t_tracker_walk = ContinualMovement(t_tracker, direction = RIGHT, rate = 1) + always_shift(t_tracker, RIGHT, 1) + self.t_tracker_walk = t_tracker equilibrium_height = springs.get_height() def update_springs(springs): for spring in springs: @@ -3560,7 +3554,7 @@ class HangingWeightsScene(MovingCameraScene): def moving_reference_frame(self): rect = ScreenRectangle(height = 2.1*FRAME_Y_RADIUS) - rect_movement = ContinualMovement(rect, direction = LEFT, rate = 2) + rect_movement = always_shift(rect, direction = LEFT, rate = 2) camera_frame = self.camera_frame self.add(rect) @@ -4294,7 +4288,7 @@ class ThinkOfHeisenbergUncertainty(PiCreatureScene): self.add() freq = 1 continual_anims = [ - ContinualMovement(time_tracker, direction = RIGHT, rate = 1), + always_shift(time_tracker, direction = RIGHT, rate = 1), ContinualUpdate( dot_gdw, lambda d : d.set_width(