A community-maintained Python framework for creating mathematical animations.
sort_submobject -> sort and shuffle_submobjects -> shuffle
Grant Sandersoneb0c63606de6
diff --git a/active_projects/eop/combinations.py b/active_projects/eop/combinations.pyindex 479ea7ab5..4ec6c9a76 100644--- a/active_projects/eop/combinations.py+++ b/active_projects/eop/combinations.py@@ -2366,13 +2366,13 @@ class ChooseThreeFromFive(InitialFiveChooseThreeExample, PiCreatureScene):for x in range(6):line.generate_target()resorter = VGroup(*line.target)- resorter.sort_submobjects(lambda p : random.random())+ resorter.sort(lambda p : random.random())resorter.arrange(RIGHT, buff = SMALL_BUFF)resorter.move_to(line)self.play(MoveToTarget(line, path_arc = np.pi))self.play(FadeOut(q_marks))- line.sort_submobjects(lambda p : p[0])+ line.sort(lambda p : p[0])words = VGroup(*list(map(TextMobject, ["First", "Second", "Fifth"])))words.set_color(YELLOW)words.scale(0.75)diff --git a/active_projects/eop/independence.py b/active_projects/eop/independence.pyindex 8aeb3ffb6..c84208dd0 100644--- a/active_projects/eop/independence.py+++ b/active_projects/eop/independence.py@@ -903,7 +903,7 @@ class ThousandPossibleQuizzes(Scene):top_split = VGroup(*self.quizzes[:n])bottom_split = VGroup(*self.quizzes[n:])for split, color, vect in (top_split, GREEN, UP), (bottom_split, RED, DOWN):- split.sort_submobjects(lambda p : p[0])+ split.sort(lambda p : p[0])split.generate_target()split.target.shift(MED_LARGE_BUFF*vect)for quiz in split.target:@@ -1175,7 +1175,7 @@ class ThousandPossibleQuizzes(Scene):proportions = [0.9, 0.8, 0.8, 0.4]for split, prop in zip(all_splits, proportions):n = int(prop*len(split))- split.sort_submobjects(lambda p : -p[1])+ split.sort(lambda p : -p[1])split.generate_target()top_part = VGroup(*split.target[:n])top_part.shift(MED_SMALL_BUFF*UP)@@ -2111,7 +2111,7 @@ class CorrelationsWith35Percent(ThousandPossibleQuizzes):self.wait()self.quizzes = bottom_part- self.quizzes.sort_submobjects(lambda p : p[0])+ self.quizzes.sort(lambda p : p[0])def show_second_split(self):n = int(0.45*len(self.quizzes))@@ -2143,7 +2143,7 @@ class CorrelationsWith35Percent(ThousandPossibleQuizzes):self.play(left_part.fade, 0.8)self.quizzes = right_part- self.quizzes.sort_submobjects(lambda p : -p[1])+ self.quizzes.sort(lambda p : -p[1])def show_third_split(self):quizzes = self.quizzesdiff --git a/manimlib/mobject/mobject.py b/manimlib/mobject/mobject.pyindex 445c8be39..077c7dc80 100644--- a/manimlib/mobject/mobject.py+++ b/manimlib/mobject/mobject.py@@ -859,10 +859,6 @@ class Mobject(Container):self.center()return self- # Just here to keep from breaking old scenes.- def arrange_submobjects(self, *args, **kwargs):- return self.arrange(*args, **kwargs)-def arrange_in_grid(self, n_rows=None, n_cols=None, **kwargs):submobs = self.submobjectsif n_rows is None and n_cols is None:@@ -882,16 +878,16 @@ class Mobject(Container):]).arrange(v2, **kwargs)return self- def sort_submobjects(self, point_to_num_func=lambda p: p[0]):+ def sort(self, point_to_num_func=lambda p: p[0]):self.submobjects.sort(key=lambda m: point_to_num_func(m.get_center()))return self- def shuffle_submobjects(self, recursive=False):+ def shuffle(self, recursive=False):if recursive:for submob in self.submobjects:- submob.shuffle_submobjects(recursive=True)+ submob.shuffle(recursive=True)random.shuffle(self.submobjects)def print_family(self, n_tabs=0):@@ -900,6 +896,16 @@ class Mobject(Container):for submob in self.submobjects:submob.print_family(n_tabs + 1)+ # Just here to keep from breaking old scenes.+ def arrange_submobjects(self, *args, **kwargs):+ return self.arrange(*args, **kwargs)++ def sort_submobjects(self, *args, **kwargs):+ return self.sort(*args, **kwargs)++ def shuffle_submobjects(self, *args, **kwargs):+ return self.shuffle(*args, **kwargs)+# Alignmentdef align_data(self, mobject):self.align_submobjects(mobject)diff --git a/manimlib/mobject/svg/drawings.py b/manimlib/mobject/svg/drawings.pyindex a2802a653..4553b93b9 100644--- a/manimlib/mobject/svg/drawings.py+++ b/manimlib/mobject/svg/drawings.py@@ -223,7 +223,7 @@ class Laptop(VGroup):body.stretch(scale_factor, dim=dim)body.set_width(self.width)body.set_fill(self.shaded_body_color, opacity=1)- body.sort_submobjects(lambda p: p[2])+ body.sort(lambda p: p[2])body[-1].set_fill(self.body_color)screen_plate = body.copy()keyboard = VGroup(*[diff --git a/manimlib/mobject/svg/tex_mobject.py b/manimlib/mobject/svg/tex_mobject.pyindex 4fdb2ba22..6a33eb1bf 100644--- a/manimlib/mobject/svg/tex_mobject.py+++ b/manimlib/mobject/svg/tex_mobject.py@@ -125,7 +125,7 @@ class SingleStringTexMobject(SVGMobject):return TexSymbol(path_string)def organize_submobjects_left_to_right(self):- self.sort_submobjects(lambda p: p[0])+ self.sort(lambda p: p[0])return self@@ -231,7 +231,7 @@ class TexMobject(SingleStringTexMobject):part = self.get_part_by_tex(tex, **kwargs)return self.index_of_part(part)- def sort_submobjects_alphabetically(self):+ def sort_alphabetically(self):self.submobjects.sort(key=lambda m: m.get_tex_string())diff --git a/old_projects/256.py b/old_projects/256.pyindex e67b84430..10b2955d2 100644--- a/old_projects/256.py+++ b/old_projects/256.py@@ -679,7 +679,7 @@ class StateOfBitcoin(TeacherStudentsScene):third = TexMobject("1 \\over 3")third.next_to(kilo, LEFT)kilogoogle = VGroup(*it.chain(third, kilo, google))- kilogoogle.sort_submobjects()+ kilogoogle.sort()kilogoogle.next_to(rate, DOWN, MED_LARGE_BUFF)rate.save_state()@@ -818,7 +818,7 @@ class QAndA(PiCreatureScene):dots.next_to(self.pi_creature, UP)dots = VGroup(*it.chain(*dots))top = dots.get_top()- dots.sort_submobjects(+ dots.sort(lambda p : get_norm(p-top))diff --git a/old_projects/WindingNumber_G.py b/old_projects/WindingNumber_G.pyindex 0aa946761..2e9bff091 100644--- a/old_projects/WindingNumber_G.py+++ b/old_projects/WindingNumber_G.py@@ -597,7 +597,7 @@ class TransitionFromEquationSolverToZeroFinder(Introduce1DFunctionCase):new_equation[2].match_style(equation[2])new_equation.move_to(equation, RIGHT)for tex in equation, new_equation:- tex.sort_submobjects_alphabetically()+ tex.sort_alphabetically()self.play(ShowCreation(rect))self.play(FadeOut(rect))@@ -636,7 +636,7 @@ class RewriteEquationWithTeacher(AltTeacherStudentsScene):TexMobject("x^2", "-", "2", "=", "0"),)for equation in root_two_equations:- equation.sort_submobjects_alphabetically()+ equation.sort_alphabetically()for part in equation.get_parts_by_tex("text"):part[2:-1].set_color(YELLOW)part[2:-1].scale(0.9)@@ -1425,7 +1425,7 @@ class Rearrange2DEquation(AltTeacherStudentsScene):for equation in equations:equation.set_color_by_tex(g_tex, BLUE)equation.set_color_by_tex(h_tex, YELLOW)- equation.sort_submobjects_alphabetically()+ equation.sort_alphabetically()self.teacher_holds_up(equations[0])@@ -2937,7 +2937,7 @@ class MentionQAndA(Scene):"Sridhar" : YELLOW,})patreon_logo = VGroup(*PatreonLogo().family_members_with_points())- patreon_logo.sort_submobjects()+ patreon_logo.sort()patreon_logo.replace(title.get_parts_by_tex("Patreon"))patreon_logo.scale(1.3, about_edge = LEFT)patreon_logo.shift(0.5*SMALL_BUFF*DOWN)diff --git a/old_projects/alt_calc.py b/old_projects/alt_calc.pyindex a5c77a601..2f414e7a8 100644--- a/old_projects/alt_calc.py+++ b/old_projects/alt_calc.py@@ -3555,7 +3555,7 @@ class PrinciplesOverlay(PiCreatureScene):mark.set_stroke(BLACK, 1)q_marks.next_to(morty, UP)q_marks.shift_onto_screen()- q_marks.sort_submobjects(+ q_marks.sort(lambda p: get_norm(p - morty.get_top()))diff --git a/old_projects/bell.py b/old_projects/bell.pyindex e324dd252..0a54ff0be 100644--- a/old_projects/bell.py+++ b/old_projects/bell.py@@ -1582,12 +1582,12 @@ class VennDiagramProofByContradiction(Scene):)B_center = B.target.get_center()- photons.sort_submobjects(+ photons.sort(lambda p : get_norm(p-B_center))in_B = VGroup(*photons[:85])out_of_B = VGroup(*photons[85:])- out_of_B.sort_submobjects(lambda p : np.dot(p, 2*UP+LEFT))+ out_of_B.sort(lambda p : np.dot(p, 2*UP+LEFT))self.play(MoveToTarget(B),@@ -1661,7 +1661,7 @@ class VennDiagramProofByContradiction(Scene):DOWN+RIGHT, buff = SMALL_BUFF)- in_B.sort_submobjects(+ in_B.sort(lambda p : get_norm(p - C_center))in_C = VGroup(*in_B[:-11])@@ -1923,7 +1923,7 @@ class VennDiagramProofByContradiction(Scene):def photons_jump_to_A_not_C_region(self):in_C = self.in_C- in_C.sort_submobjects(lambda p : np.dot(p, DOWN+RIGHT))+ in_C.sort(lambda p : np.dot(p, DOWN+RIGHT))movers = VGroup(*self.in_C[:30])for mover in movers:mover.generate_target()diff --git a/old_projects/borsuk.py b/old_projects/borsuk.pyindex aff5d92fb..175617517 100644--- a/old_projects/borsuk.py+++ b/old_projects/borsuk.py@@ -719,7 +719,7 @@ class PointOutVSauce(CheckOutMathologer):logo.to_corner(UP+LEFT)logo.set_stroke(width = 0)logo.set_fill(GREEN)- logo.sort_submobjects()+ logo.sort()return logodef get_logo_intro_animation(self, logo):@@ -1569,7 +1569,7 @@ class MakeTwoJewelCaseContinuous(IntroduceStolenNecklaceProblem):left_segment.parts[0],right_segment.parts[1],)- emerald_segments.sort_submobjects()+ emerald_segments.sort()self.play(v_lines.shift, segment_width*RIGHT/2)self.play(*[@@ -2158,7 +2158,7 @@ class TotalLengthOfEachJewelEquals(NecklaceDivisionSphereAssociation, ThreeDScendef find_fair_division(self):segments, tick_marks = self.necklace- segments.sort_submobjects()+ segments.sort()segment_colors = [segment.get_color()for segment in segmentsdiff --git a/old_projects/crypto.py b/old_projects/crypto.pyindex 20b6a390d..741045e02 100644--- a/old_projects/crypto.py+++ b/old_projects/crypto.py@@ -4889,7 +4889,7 @@ class ShowBitcoinBlockSize(LedgerScene):fill_opacity = 1,)visa_logo[-1].set_color("#faa61a")- visa_logo.sort_submobjects()+ visa_logo.sort()avg_rate = TextMobject("Avg: $1{,}700$/second")max_rate = TextMobject("Max: $>24{,}000$/second")rates = VGroup(avg_rate, max_rate)diff --git a/old_projects/div_curl.py b/old_projects/div_curl.pyindex 93f8a624a..2a1ec4f63 100644--- a/old_projects/div_curl.py+++ b/old_projects/div_curl.py@@ -487,7 +487,7 @@ class Introduction(MovingCameraScene):stream_lines = StreamLines(div_func, **self.stream_lines_config)- stream_lines.shuffle_submobjects()+ stream_lines.shuffle()div_title = self.get_title("Divergence")self.add(div_vector_field)@@ -507,7 +507,7 @@ class Introduction(MovingCameraScene):stream_lines = StreamLines(curl_func, **self.stream_lines_config)- stream_lines.shuffle_submobjects()+ stream_lines.shuffle()curl_title = self.get_title("Curl")self.play(diff --git a/old_projects/for_flammy.py b/old_projects/for_flammy.pyindex 912a2bc71..e08c771b6 100644--- a/old_projects/for_flammy.py+++ b/old_projects/for_flammy.py@@ -216,7 +216,7 @@ class SphereRings(SecondProof):def flash_through_rings(self):rings = self.north_rings.copy()rings.fade(1)- rings.sort_submobjects(lambda p: p[2])+ rings.sort(lambda p: p[2])for x in range(8):self.play(LaggedStart(diff --git a/old_projects/fourier.py b/old_projects/fourier.pyindex 6aff695bd..60ef57f1f 100644--- a/old_projects/fourier.py+++ b/old_projects/fourier.py@@ -2929,7 +2929,7 @@ class WriteComplexExponentialExpression(DrawFrequencyPlot):self.play(ghost_dot.move_to, ORIGIN)exp_expression[1].add(minus, f)- exp_expression[1].sort_submobjects(lambda p : p[0])+ exp_expression[1].sort(lambda p : p[0])self.set_variables_as_attrs(ambient_ghost_dot_movement, ghost_dot,diff --git a/old_projects/leibniz.py b/old_projects/leibniz.pyindex f85a42c65..5c8a0e6a4 100644--- a/old_projects/leibniz.py+++ b/old_projects/leibniz.py@@ -56,7 +56,7 @@ class LatticePointScene(Scene):)dot.r_squared = r_squaredself.lattice_points.add(dot)- self.lattice_points.sort_submobjects(+ self.lattice_points.sort(lambda p : get_norm(p - self.plane_center))@@ -92,7 +92,7 @@ class LatticePointScene(Scene):def get_lattice_points_on_r_squared_circle(self, r_squared):points = VGroup(*[dot for dot in self.lattice_points if dot.r_squared == r_squared])- points.sort_submobjects(+ points.sort(lambda p : angle_of_vector(p-self.plane_center)%(2*np.pi))return points@@ -573,7 +573,7 @@ class Outline(PiCreatureScene):for b in range(-10, 11)if a**2 + b**2 <= 10**2])- lattice_points.sort_submobjects(+ lattice_points.sort(lambda p : get_norm(p - plane_center))lattice_group = VGroup(plane, circle, lattice_points)@@ -4173,7 +4173,7 @@ class CountLatticePointsInBigCircle(LatticePointScene):if (x**2 + y**2) > self.max_lattice_point_radius**2if (x**2 + y**2) < new_max**2])- new_dots.sort_submobjects(get_norm)+ new_dots.sort(get_norm)self.play(*list(map(ShowCreation, [circle, arrow])))self.play(*list(map(FadeOut, [circle, arrow])))diff --git a/old_projects/lost_lecture.py b/old_projects/lost_lecture.pyindex b096867e1..74873dc61 100644--- a/old_projects/lost_lecture.py+++ b/old_projects/lost_lecture.py@@ -1017,7 +1017,7 @@ class FeynmanElementaryQuote(Scene):self.add_foreground_mobjects(nothing)self.play(ShowWord(nothing))self.wait(0.2)- nothing.sort_submobjects(lambda p: -p[0])+ nothing.sort(lambda p: -p[0])self.play(LaggedStart(FadeOut, nothing,run_time=1@@ -2600,7 +2600,7 @@ class AngularMomentumArgument(KeplersSecondLaw):get_force_field_func((sun_center, -1)))vector_field.set_fill(opacity=0.8)- vector_field.sort_submobjects(+ vector_field.sort(lambda p: -get_norm(p - sun_center))@@ -4131,7 +4131,7 @@ class ShowSunVectorField(Scene):get_force_field_func((sun_center, -1)))vector_field.set_fill(opacity=0.8)- vector_field.sort_submobjects(+ vector_field.sort(lambda p: -get_norm(p - sun_center))diff --git a/old_projects/mug.py b/old_projects/mug.pyindex 54cd585b3..94d523cc0 100644--- a/old_projects/mug.py+++ b/old_projects/mug.py@@ -1880,7 +1880,7 @@ class EulersFormulaForGeneralPlanarGraph(LightUpNodes, ThreeDScene):self.play(FadeOut(self.vertices))self.play(ReplacementTransform(regions, cube, run_time = 2))- cube.sort_submobjects(lambda p : -p[2])+ cube.sort(lambda p : -p[2])self.add(ContinualRotation(cube, axis = UP, in_place = False))self.wait(3)self.play(diff --git a/old_projects/nn/part1.py b/old_projects/nn/part1.pyindex 7f2c798cd..a560efeb3 100644--- a/old_projects/nn/part1.py+++ b/old_projects/nn/part1.py@@ -337,7 +337,7 @@ class ExampleThrees(PiCreatureScene):self.three_mobs = self.get_three_mobs()three_mob = self.three_mobs[0]three_mob_copy = three_mob[1].copy()- three_mob_copy.sort_submobjects(lambda p : np.dot(p, DOWN+RIGHT))+ three_mob_copy.sort(lambda p : np.dot(p, DOWN+RIGHT))braces = VGroup(*[Brace(three_mob, v) for v in (LEFT, UP)])brace_labels = VGroup(*[@@ -545,7 +545,7 @@ class WriteAProgram(Scene):three_array = get_organized_images()[3][0]im_mob = ImageMobject(layer_to_image_array(three_array))three = PixelsAsSquares(im_mob)- three.sort_submobjects(lambda p : np.dot(p, DOWN+RIGHT))+ three.sort(lambda p : np.dot(p, DOWN+RIGHT))three.set_height(6)three.next_to(ORIGIN, LEFT)three_rect = SurroundingRectangle(diff --git a/old_projects/nn/part3.py b/old_projects/nn/part3.pyindex 3bd7e6bc9..534b46537 100644--- a/old_projects/nn/part3.py+++ b/old_projects/nn/part3.py@@ -1914,7 +1914,7 @@ class OrganizeDataIntoMiniBatches(Scene):def divide_into_minibatches(self):examples = self.examples- examples.sort_submobjects(lambda p : -p[1])+ examples.sort(lambda p : -p[1])rows = Group(*[Group(*examples[i*self.n_cols:(i+1)*self.n_cols])for i in range(self.n_rows)@@ -1956,7 +1956,7 @@ class OrganizeDataIntoMiniBatches(Scene):buff = SMALL_BUFF)def indicate_row(row):- row.sort_submobjects(lambda p : p[0])+ row.sort(lambda p : p[0])return LaggedStart(ApplyFunction, row,lambda row : (diff --git a/old_projects/quat3d.py b/old_projects/quat3d.pyindex f9e37b02b..55e41ca07 100644--- a/old_projects/quat3d.py+++ b/old_projects/quat3d.py@@ -779,7 +779,7 @@ class EulerAnglesAndGimbal(ShowSeveralQuaternionRotations):)for u in [-1, 1]]))- line.sort_submobjects(get_norm)+ line.sort(get_norm)line.set_shade_in_3d(True)line.set_stroke(YELLOW, 5)line.center()diff --git a/old_projects/quaternions.py b/old_projects/quaternions.pyindex 3b9d8aee7..f29ae3385 100644--- a/old_projects/quaternions.py+++ b/old_projects/quaternions.py@@ -411,7 +411,7 @@ class RubiksCube(VGroup):# return VGroup(square, back)def get_face(self, vect):- self.sort_submobjects(lambda p: np.dot(p, vect))+ self.sort(lambda p: np.dot(p, vect))return self[-(12 + 9):]@@ -1931,7 +1931,7 @@ class WalkThroughComplexMultiplication(ShowComplexMultiplicationExamples):pair = VGroup(p1, p2)pair.scale(0.3)sparkly_plane.add(pair)- sparkly_plane.sort_submobjects(+ sparkly_plane.sort(lambda p: 0.1 * get_norm(p) + random.random())sparkly_plane.set_color_by_gradient(YELLOW, RED, PINK, BLUE)diff --git a/old_projects/triples.py b/old_projects/triples.pyindex c3821277e..7a3cca2f2 100644--- a/old_projects/triples.py+++ b/old_projects/triples.py@@ -942,7 +942,7 @@ class ReframeOnLattice(PiCreatureScene):for x in range(int(x_min), int(x_max)+1)for y in range(int(y_min), int(y_max)+1)])- result.sort_submobjects(lambda p : np.dot(p, UP+RIGHT))+ result.sort(lambda p : np.dot(p, UP+RIGHT))return resultdef create_pi_creature(self):@@ -1682,7 +1682,7 @@ class VisualizeZSquared(Scene):for x in range(x_min, x_max+1)for y in range(y_min, y_max+1)])- dots.sort_submobjects(lambda p : np.dot(p, UP+RIGHT))+ dots.sort(lambda p : np.dot(p, UP+RIGHT))self.add_foreground_mobject(self.coordinate_labels)self.play(LaggedStart(@@ -1906,7 +1906,7 @@ class PointsWeMiss(VisualizeZSquared):)for z in z_list])- dots.sort_submobjects(get_norm)+ dots.sort(get_norm)self.add(dots)self.dots = dots@@ -2423,7 +2423,7 @@ class ProjectPointsOntoUnitCircle(DrawRadialLines):def project_all_dots(self):dots = self.dotsdots.add(*self.new_dots)- dots.sort_submobjects(+ dots.sort(lambda p : get_norm(p - self.plane_center))unit_length = self.unit_circle.get_width()/2.0diff --git a/old_projects/turbulence.py b/old_projects/turbulence.pyindex db8e915d1..eea6c9442 100644--- a/old_projects/turbulence.py+++ b/old_projects/turbulence.py@@ -248,7 +248,7 @@ class Diffusion(VMobject):dots.arrange_in_grid(buff=SMALL_BUFF)dots.center()dots.set_height(self.height)- dots.sort_submobjects(lambda p: p[0])+ dots.sort(lambda p: p[0])dots[:len(dots) // 2].set_color(self.colors[0])dots[len(dots) // 2:].set_color(self.colors[1])dots.set_fill(opacity=0.8)diff --git a/old_projects/waves.py b/old_projects/waves.pyindex b1a4db58a..3c26ae154 100644--- a/old_projects/waves.py+++ b/old_projects/waves.py@@ -693,7 +693,7 @@ class IntroduceElectricField(PiCreatureScene):)VGroup(*shading_list).set_color_by_gradient(*self.vector_field_colors)result.set_fill(opacity = 0.75)- result.sort_submobjects(get_norm)+ result.sort(get_norm)return result