Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from manim import *
- from MF_Tools import *
- # LIGHT THEME
- config.background_color = WHITE
- # Those are objects which are WHITE by default
- # Define the wanted color for each one
- white_objects ={
- Angle: ('dot_color', BLACK),
- AnnotationDot: ('stroke_color', BLACK),
- AnnularSector: ('color', BLACK),
- Annulus: ('color', BLACK),
- Arrow: ('color', BLACK),
- Arrow3D: ('color', BLACK),
- ArrowVectorField: ('color', BLACK),
- Code: ('background_stroke_color', BLACK),
- CubicBezier: ('color', BLACK),
- DashedVMobject: ('color', BLACK),
- Dot: ('color', BLACK),
- Dot3D: ('color', BLACK),
- Line: ('color', BLACK),
- Line3D: ('color', BLACK),
- MarkupText: ('color', BLACK),
- Polygon: ('color', BLACK),
- Rectangle: ('color', BLACK),
- SingleStringMathTex: ('color', BLACK),
- StreamLines: ('color', BLACK),
- Text: ('color', BLACK),
- TracedPath: ('stroke_color', BLACK),
- VectorField: ('color', BLACK),
- }
- for obj, (attr, color) in white_objects.items():
- obj.set_default(**{attr: color})
- # Other configurations
- Table.set_default(line_config=
- {"stroke_width": 1, "stroke_opacity": 0.5, "color": BLACK})
- Code.set_default(style="pastie")
- YELLOW="#ebe534"
- # ANIMATION
- class EquationAnimation(Scene):
- def construct(self):
- A_COLOR = PURE_GREEN
- B_COLOR = PURE_BLUE
- SCALE = 1.6
- WAIT_TIME = 0.8
- SPACING = 1
- eq1 = MathTex('x_P = ax_A + bx_B').scale(SCALE)
- eq2 = MathTex('y_P = ay_A + by_B').scale(SCALE)
- original_eqs = Group(eq1, eq2)
- eq2.next_to(eq1, DOWN, SPACING)
- original_eqs.move_to(ORIGIN)
- self.wait(WAIT_TIME)
- self.play(Write(eq1), Write(eq2))
- self.play(eq1[0][3].animate.set_color(A_COLOR), eq1[0][7].animate.set_color(B_COLOR), eq2[0][3].animate.set_color(A_COLOR), eq2[0][7].animate.set_color(B_COLOR))
- self.wait(WAIT_TIME)
- eq_b1 = MathTex('y_P - ay_A = by_B').scale(SCALE)
- eq_b1.next_to(eq1, DOWN, SPACING)
- eq_b1[0][3].set_color(A_COLOR)
- eq_b1[0][7].set_color(B_COLOR)
- self.play(TransformByGlyphMap(eq2, eq_b1,
- ([2],[6], {"path_arc": 0.9*PI}),
- ([6],[2], {"path_arc": -0.9*PI}),
- ))
- self.wait(WAIT_TIME)
- eq_b2 = MathTex(r'\frac{y_P-ay_A}{y_B}=b').scale(SCALE)
- eq_b2.next_to(eq1, DOWN, SPACING)
- eq_b2[0][3].set_color(A_COLOR)
- eq_b2[0][10].set_color(B_COLOR)
- self.play(TransformByGlyphMap(eq_b1, eq_b2,
- ([8,9],[7,8], {"path_arc": -0.4*PI}),
- ([], [6], {'shift': UP}),
- ))
- self.wait(WAIT_TIME)
- eq_b = MathTex(r'b = \frac{y_P-ay_A}{y_B}').scale(SCALE)
- eq_b.next_to(eq1, DOWN, SPACING)
- eq_b[0][5].set_color(A_COLOR)
- eq_b[0][0].set_color(B_COLOR)
- self.play(TransformByGlyphMap(eq_b2, eq_b,
- ([10,9],[0,1], {"path_arc": -0.9*PI}),
- ))
- self.wait(WAIT_TIME)
- self.play(eq_b.animate.set_color(B_COLOR))
- self.wait(WAIT_TIME)
- eq_a1 = MathTex(r'x_P = ax_A + \Big( \frac{y_P-ay_A}{y_B} \Big) x_B').scale(SCALE)
- eq_a1.next_to(eq_b, UP, SPACING)
- eq_a1[0][3].set_color(A_COLOR)
- eq_a1[0][8:17].set_color(B_COLOR)
- self.play(TransformByGlyphMap(eq1, eq_a1,
- ([7],range(8,17)),
- ([],[7], {'shift': LEFT, 'delay': 0.16}),
- ([],[17], {'shift': RIGHT, 'delay': 0.16}),
- ))
- self.wait(WAIT_TIME)
- self.play(eq_a1[0][8:11].animate.set_color(BLACK), eq_a1[0][12:17].animate.set_color(BLACK), eq_a1[0][11].animate.set_color(A_COLOR))
- self.wait(WAIT_TIME)
- eq_a2 = MathTex(r'x_P = ax_A + \frac{(y_P - ay_A) x_B}{y_B}').scale(SCALE)
- eq_a2.next_to(eq_b, UP, SPACING)
- eq_a2[0][3].set_color(A_COLOR)
- eq_a2[0][11].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a1, eq_a2,
- ([7],[7]), # (
- ([17],[14]), # )
- ([14],[17]), # \over
- ([18,19],[15,16]),
- ([15,16],[18,19]),
- ))
- self.wait(WAIT_TIME)
- eq_a3 = MathTex(r'x_P = \frac{ax_Ay_B}{y_B} + \frac{(y_P-ay_A)x_B}{y_B}').scale(SCALE)
- eq_a3.next_to(eq_b, UP, SPACING)
- eq_a3[0][3].set_color(A_COLOR)
- eq_a3[0][16].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a2, eq_a3,
- ([],[6,7], {'shift': DOWN}),
- ([],[8], {'shift': UP}),
- ([],[9,10], {'shift': UP}),
- ))
- self.wait(WAIT_TIME)
- eq_a4 = MathTex('x_P y_B = ax_A y_B + (y_P - ay_A) x_B').scale(SCALE)
- eq_a4.next_to(eq_b, UP, SPACING)
- eq_a4[0][5].set_color(A_COLOR)
- eq_a4[0][15].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a3, eq_a4,
- ([8,22],[], {'shift': DOWN}),
- ([9,10],[2,3], {'path_arc': -0.5*PI}),
- ([23,24],[2,3], {'path_arc': -0.26*PI}),
- ([0,1],[0,1]),
- (range(2,8),range(4,10)),
- (range(11,22),range(10,21)),
- ))
- self.wait(WAIT_TIME)
- eq_a5 = MathTex('x_P y_B = ax_A y_B + y_P x_B - ay_A x_B').scale(SCALE)
- eq_a5.next_to(eq_b, UP, SPACING)
- eq_a5[0][5].set_color(A_COLOR)
- eq_a5[0][16].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a4, eq_a5,
- ([11], ShrinkToCenter),
- ([18], ShrinkToCenter),
- ([12,13],[11,12]),
- (range(14,18),range(15,19)),
- ([19,20],[19,20]),
- ([19,20],[13,14], {'path_arc': 0.8*PI}),
- ))
- self.wait(WAIT_TIME)
- eq_a6 = MathTex('x_P y_B - y_P x_B = ax_A y_B - ay_A x_B').scale(SCALE)
- eq_a6.next_to(eq_b, UP, SPACING)
- eq_a6[0][10].set_color(A_COLOR)
- eq_a6[0][16].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a5, eq_a6,
- (range(10,15),range(4,9), {'path_arc': 0.84*PI}),
- ))
- self.wait(WAIT_TIME)
- eq_a7 = MathTex('x_P y_B - y_P x_B = a(x_A y_B - y_A x_B)').scale(SCALE)
- eq_a7.next_to(eq_b, UP, SPACING)
- eq_a7[0][10].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a6, eq_a7,
- ([16],[10], {'path_arc': 0.85*PI}),
- ([10],[10]),
- (GrowFromCenter,[11]),
- (GrowFromCenter,[21]),
- ([11,12,13,14,15,17,18,19,20], range(12,21)),
- ))
- self.wait(WAIT_TIME)
- eq_a8 = MathTex(r'\frac{x_P y_B - y_P x_B}{x_A y_B - y_A x_B} = a').scale(SCALE)
- eq_a8.next_to(eq_b, UP, SPACING)
- eq_a8[0][20].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a7, eq_a8,
- ([11], ShrinkToCenter),
- ([21], ShrinkToCenter),
- ([],[9], {'shift': UP}),
- (range(12,21),range(10,19), {'path_arc': -0.52*PI}),
- ))
- self.wait(WAIT_TIME)
- eq_a = MathTex(r'a = \frac{x_P y_B - y_P x_B}{x_A y_B - y_A x_B}').scale(SCALE)
- eq_a.next_to(eq_b, UP, SPACING)
- eq_a[0][0].set_color(A_COLOR)
- self.play(TransformByGlyphMap(eq_a8, eq_a,
- ([20],[0], {'path_arc': 0.7*PI}),
- ([19],[1], {'path_arc': 0.66*PI}),
- ))
- self.wait(WAIT_TIME)
- self.play(eq_a.animate.set_color(A_COLOR))
- self.wait(WAIT_TIME)
- self.wait(2)
Add Comment
Please, Sign In to add comment