1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| from manim import * import numpy as np from numpy import array run_time = 1 data = [[1, 2], [3, 4]] def dot(pos, **kwargs): return Dot(pos, **kwargs) import numpy as np config.background_color = WHITE class DynamicMullerLyer(Scene): def construct(self): self.vertexes = [] count = 11 lines = self.create_lines(count) self.play(Create(lines)) self.wait(1) self.clear() wings = self.create_wings(self.vertexes) self.play(*[FadeIn(_o) for _o in [*wings]], run_time=1.0) self.rotate_wings( wings, self.vertexes, list(np.random.uniform(0.5, 1.5, len(wings))), repeat=4, ) self.wait(1) self.play(*[FadeIn(_o) for _o in [lines]], run_time=1.0) self.rotate_wings( wings, self.vertexes, list(np.random.uniform(0.5, 1.5, len(wings))), repeat=8, ) self.wait(0.5) def create_lines(self, count=11, interval=0.4) -> VGroup: l_group = VGroup() for i in range(count // 2 + 1): vertical_l_group = VGroup() vertical_l_group.add( Line(UP * 2.5, UP * 1.5, stroke_width=2, color=PURE_BLUE) ) vertical_l_group.add( Line(UP * 1.5, UP * 0.5, stroke_width=2, color=PURE_RED) ) vertical_l_group.add( Line(UP * 0.5, DOWN * 0.5, stroke_width=2, color=PURE_BLUE) ) vertical_l_group.add( Line(DOWN * 0.5, DOWN * 1.5, stroke_width=2, color=PURE_RED) ) vertical_l_group.add( Line(DOWN * 1.5, DOWN * 2.5, stroke_width=2, color=PURE_BLUE) ) vertical_l_group.shift(LEFT * i * interval) self.vertexes.append(UP * 2.5 + LEFT * i * interval) self.vertexes.append(UP * 1.5 + LEFT * i * interval) self.vertexes.append(UP * 0.5 + LEFT * i * interval) self.vertexes.append(DOWN * 0.5 + LEFT * i * interval) self.vertexes.append(DOWN * 1.5 + LEFT * i * interval) self.vertexes.append(DOWN * 2.5 + LEFT * i * interval) l_group.add(vertical_l_group) for i in range(1, count // 2 + 1): vertical_l_group = VGroup() vertical_l_group.add( Line(UP * 2.5, UP * 1.5, stroke_width=2, color=PURE_BLUE) ) vertical_l_group.add( Line(UP * 1.5, UP * 0.5, stroke_width=2, color=PURE_RED) ) vertical_l_group.add( Line(UP * 0.5, DOWN * 0.5, stroke_width=2, color=PURE_BLUE) ) vertical_l_group.add( Line(DOWN * 0.5, DOWN * 1.5, stroke_width=2, color=PURE_RED) ) vertical_l_group.add( Line(DOWN * 1.5, DOWN * 2.5, stroke_width=2, color=PURE_BLUE) ) vertical_l_group.shift(RIGHT * i * interval) self.vertexes.append(UP * 2.5 + RIGHT * i * interval) self.vertexes.append(UP * 1.5 + RIGHT * i * interval) self.vertexes.append(UP * 0.5 + RIGHT * i * interval) self.vertexes.append(DOWN * 0.5 + RIGHT * i * interval) self.vertexes.append(DOWN * 1.5 + RIGHT * i * interval) self.vertexes.append(DOWN * 2.5 + RIGHT * i * interval) l_group.add(vertical_l_group) return l_group def create_wings(self, vertexes, wing_radio=0.1): groups = [] for vertex in vertexes: left_line = Line( vertex, vertex + (UP + LEFT) * wing_radio, stroke_width=2, color=BLACK ) right_line = Line( vertex, vertex + (UP + RIGHT) * wing_radio, stroke_width=2, color=BLACK ) groups.append(VGroup(left_line, right_line)) return groups def rotate_wings(self, wings, vertexes, run_times, repeat=4): anims = [] for i in range(len(wings)): ag1 = AnimationGroup( Rotate( wings[i][0], angle=90 * DEGREES, about_point=vertexes[i] ).set_run_time(run_times[i]), Rotate( wings[i][1], angle=-90 * DEGREES, about_point=vertexes[i] ).set_run_time(run_times[i]), ) ag2 = AnimationGroup( Rotate( wings[i][0], angle=-90 * DEGREES, about_point=vertexes[i] ).set_run_time(run_times[i]), Rotate( wings[i][1], angle=90 * DEGREES, about_point=vertexes[i] ).set_run_time(run_times[i]), ) anim = Succession([ag1, ag2] * repeat) anims.append(anim) self.play( AnimationGroup(*anims), run_time=max(run_times) * repeat, )
|