|
| 1 | +from manimlib.imports import* |
| 2 | +import math |
| 3 | + |
| 4 | +class intro(Scene): |
| 5 | + def construct(self): |
| 6 | + introText1=TextMobject("Let's analyse") |
| 7 | + introText2=TextMobject("for") |
| 8 | + function_main=TextMobject("$\sum { { (-1) }^{ n }{ x }^{ 2n } }$") |
| 9 | + function_main.set_color(GREEN) |
| 10 | + introText1.scale(1.2) |
| 11 | + introText1.shift(2*UP) |
| 12 | + introText2.scale(0.7) |
| 13 | + introText2.shift(UP) |
| 14 | + function_main.scale(2) |
| 15 | + function_main.shift(DOWN) |
| 16 | + function_expan=TextMobject("$1-{ x }^{ 2 }+{ x }^{ 4 }-{ x }^{ 6 }+{ x }^{ 8 }+..$") |
| 17 | + function_expan.set_color(RED) |
| 18 | + function_expan.scale(1.2) |
| 19 | + function_expan.shift(2*UP) |
| 20 | + |
| 21 | + self.play(Write(introText1)) |
| 22 | + self.play(FadeIn(introText2)) |
| 23 | + self.wait(0.5) |
| 24 | + self.play(Write(function_main)) |
| 25 | + self.wait(1) |
| 26 | + |
| 27 | + self.play(FadeOut(introText1),FadeOut(introText2)) |
| 28 | + self.play(ApplyMethod(function_main.shift,3*UP)) |
| 29 | + self.wait(0.5) |
| 30 | + self.play(ReplacementTransform(function_main,function_expan)) |
| 31 | + self.wait(1) |
| 32 | + self.play(ApplyMethod(function_expan.scale,0.5)) |
| 33 | + function_expan.to_edge(UP+RIGHT) |
| 34 | + self.play(ReplacementTransform(function_expan,function_expan)) |
| 35 | + self.wait(1) |
| 36 | + |
| 37 | + |
| 38 | +class graphScene(GraphScene): |
| 39 | + CONFIG = { |
| 40 | + "x_min": -8, |
| 41 | + "x_max": 8, |
| 42 | + "y_min": -8, |
| 43 | + "y_max": 8, |
| 44 | + "graph_origin": ORIGIN, |
| 45 | + "function_color": RED, |
| 46 | + "axes_color": GREEN, |
| 47 | + "x_axis_label": "$x$", |
| 48 | + "y_axis_label": "$y$", |
| 49 | + "exclude_zero_label": True, |
| 50 | + "x_labeled_nums": range(-1, 2, 1), |
| 51 | + "y_labeled_nums": range(0,2,1) |
| 52 | + } |
| 53 | + |
| 54 | + def construct(self): |
| 55 | + |
| 56 | + x_each_unit = self.x_axis_width / (self.x_max - self.x_min) |
| 57 | + y_each_unit = self.y_axis_height / (self.y_max - self.y_min) |
| 58 | + |
| 59 | + function_expan=TextMobject("$1-{ x }^{ 2 }+{ x }^{ 4 }-{ x }^{ 6 }+{ x }^{ 8 }+..$") |
| 60 | + function_expan.set_color(RED) |
| 61 | + function_expan.scale(0.6) |
| 62 | + function_expan.to_edge(UP+RIGHT) |
| 63 | + self.add(function_expan) |
| 64 | + |
| 65 | + self.setup_axes(animate=True) |
| 66 | + |
| 67 | + eqText=[TextMobject("$1$"),TextMobject("$1-{ x }^{ 2 }$"),TextMobject("$1-{ x }^{ 2 }+{ x }^{ 4 }$"),TextMobject("$1-{ x }^{ 2 }+{ x }^{ 4 }-{ x }^{ 6 }$")] |
| 68 | + for i in range(0,len(eqText)): |
| 69 | + eqText[i].scale(0.6) |
| 70 | + eqText[i].set_color(BLUE) |
| 71 | + eqText[i].shift(ORIGIN+UP*2*y_each_unit+RIGHT*3.3*x_each_unit) |
| 72 | + eqTextTerm=TextMobject("And so on..!") |
| 73 | + eqTextTerm.set_color(BLUE) |
| 74 | + eqTextTerm.scale(0.6) |
| 75 | + eqTextTerm.shift(ORIGIN+UP*2*y_each_unit+3*RIGHT*x_each_unit) |
| 76 | + equation1 = self.get_graph(lambda x : 1,color = RED,x_min = -8,x_max=8) |
| 77 | + equation2 = self.get_graph(lambda x : 1-math.pow(x,2),color = RED,x_min = -1.7,x_max=1.7) |
| 78 | + equation3 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4),color = RED,x_min = -1.6,x_max=1.6) |
| 79 | + equation4 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4)-math.pow(x,6),color = RED,x_min = -1.45,x_max=1.45) |
| 80 | + equation5 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4)-math.pow(x,6)+math.pow(x,8),color = RED,x_min = -1.35,x_max=1.35) |
| 81 | + equation6 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4)-math.pow(x,6)+math.pow(x,8)-math.pow(x,10),color = RED,x_min = -1.3,x_max=1.3) |
| 82 | + equation7 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4)-math.pow(x,6)+math.pow(x,8)-math.pow(x,10)+math.pow(x,12),color = RED,x_min = -1.25,x_max=1.25) |
| 83 | + equation8 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4)-math.pow(x,6)+math.pow(x,8)-math.pow(x,10)+math.pow(x,12)-math.pow(x,14),color = RED,x_min = -1.2,x_max=1.2) |
| 84 | + equation9 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4)-math.pow(x,6)+math.pow(x,8)-math.pow(x,10)+math.pow(x,12)-math.pow(x,14)+math.pow(x,16),color = RED,x_min = -1.15,x_max=1.15) |
| 85 | + equation10 = self.get_graph(lambda x : 1-math.pow(x,2)+math.pow(x,4)-math.pow(x,6)+math.pow(x,8)-math.pow(x,10)+math.pow(x,12)-math.pow(x,14)+math.pow(x,16)-math.pow(x,18),color = RED,x_min = -1.15,x_max=1.15) |
| 86 | + |
| 87 | + textBtwAnim1=TextMobject("Here the graph just","oscilates") |
| 88 | + textBtwAnim1.set_color_by_tex_to_color_map({"oscilates":BLUE}) |
| 89 | + textBtwAnim2=TextMobject("after","the","point","(as we add higher order terms)") |
| 90 | + textBtwAnim2.set_color_by_tex_to_color_map({"after":BLUE,"point":YELLOW}) |
| 91 | + textBtwAnim3=TextMobject("$x=1$") |
| 92 | + textBtwAnim1.scale(0.4) |
| 93 | + textBtwAnim2.scale(0.4) |
| 94 | + textBtwAnim3.scale(1.2) |
| 95 | + textBtwAnim1.shift(2.1*DOWN+4.3*RIGHT) |
| 96 | + textBtwAnim2.shift(2.4*DOWN+4.1*RIGHT) |
| 97 | + textBtwAnim3.shift(2.9*DOWN+4.3*RIGHT) |
| 98 | + |
| 99 | + self.play(ShowCreation(equation1),run_time=0.8) |
| 100 | + self.add(eqText[0]) |
| 101 | + self.wait(1) |
| 102 | + self.play(ReplacementTransform(equation1,equation2),ReplacementTransform(eqText[0],eqText[1])) |
| 103 | + self.wait(0.5) |
| 104 | + self.play(ReplacementTransform(equation2,equation3),ReplacementTransform(eqText[1],eqText[2])) |
| 105 | + self.wait(0.4) |
| 106 | + self.play(ReplacementTransform(equation3,equation4),ReplacementTransform(eqText[2],eqText[3])) |
| 107 | + self.wait(0.3) |
| 108 | + self.play(FadeOut(eqText[3])) |
| 109 | + self.play(FadeIn(eqTextTerm)) |
| 110 | + self.play(Write(textBtwAnim1),Write(textBtwAnim2)) |
| 111 | + self.play(FadeIn(textBtwAnim3)) |
| 112 | + self.play(ReplacementTransform(equation4,equation5)) |
| 113 | + self.wait(0.2) |
| 114 | + self.play(ReplacementTransform(equation5,equation6)) |
| 115 | + self.wait(0.2) |
| 116 | + self.play(ReplacementTransform(equation6,equation7)) |
| 117 | + self.wait(0.2) |
| 118 | + self.play(ReplacementTransform(equation7,equation8)) |
| 119 | + self.wait(0.2) |
| 120 | + self.play(ReplacementTransform(equation8,equation9)) |
| 121 | + self.wait(0.2) |
| 122 | + self.play(ReplacementTransform(equation9,equation10)) |
| 123 | + self.wait(1) |
| 124 | + |
| 125 | + self.play(FadeOut(textBtwAnim1),FadeOut(textBtwAnim2),FadeOut(textBtwAnim3),FadeOut(equation10),FadeOut(eqTextTerm)) |
| 126 | + self.wait(1) |
| 127 | + |
| 128 | + convergeLine=Line(start=ORIGIN+x_each_unit*LEFT,end=ORIGIN+x_each_unit*RIGHT,color=WHITE) |
| 129 | + divergeLineLeft=Line(start=ORIGIN+x_each_unit*LEFT,end=ORIGIN+x_each_unit*LEFT*8,color=RED) |
| 130 | + divergeLineRight=Line(start=ORIGIN+x_each_unit*RIGHT,end=ORIGIN+x_each_unit*8*RIGHT,color=RED) |
| 131 | + circle1=Circle(radius=0.01,color=PURPLE_E) |
| 132 | + circle2=Circle(radius=0.01,color=PURPLE_E) |
| 133 | + circle1.shift(ORIGIN+LEFT*x_each_unit) |
| 134 | + circle2.shift(ORIGIN+RIGHT*x_each_unit) |
| 135 | + convergeText=TextMobject("Converges") |
| 136 | + divergeText1=TextMobject("Diverges") |
| 137 | + divergeText2=TextMobject("Diverges") |
| 138 | + convergeText.set_color(GREEN) |
| 139 | + divergeText1.set_color(RED) |
| 140 | + divergeText2.set_color(RED) |
| 141 | + convergeText.scale(0.5) |
| 142 | + divergeText1.scale(0.5) |
| 143 | + divergeText2.scale(0.5) |
| 144 | + convergeText.shift(1.6*UP) |
| 145 | + divergeText1.shift(0.3*UP+1.5*LEFT) |
| 146 | + divergeText2.shift(0.3*UP+1.5*RIGHT) |
| 147 | + self.play(Write(divergeLineLeft),Write(divergeLineRight)) |
| 148 | + self.play(FadeIn(convergeLine)) |
| 149 | + self.wait(0.5) |
| 150 | + self.play(FadeOut(self.axes)) |
| 151 | + self.play(Write(circle1),Write(circle2)) |
| 152 | + self.wait(0.5) |
| 153 | + self.play(ApplyMethod(convergeLine.shift,1.3*UP),ApplyMethod(function_expan.shift,5*LEFT+DOWN)) |
| 154 | + self.play(FadeIn(convergeText),FadeIn(divergeText1),FadeIn(divergeText2)) |
| 155 | + self.wait(2) |
| 156 | + |
0 commit comments