summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus/intro-to-calculus/intro-to-derivative/derivative1.py
blob: 79a6fc63596838d8de8a755c1a7cd8875c9e23b2 (plain)
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
from manimlib.imports import *
class derivative1(GraphScene, Scene):
	def setup(self):
		GraphScene.setup(self)
	CONFIG = {
        "y_max" : 4,
        "y_min" : -2,
        "x_max" : 4,
        "x_min" : -2,
        "y_tick_frequency" : 1, 
        "x_tick_frequency" : 1, 
        "axes_color" : WHITE, 
        "num_graph_anchor_points": 3000, #this is the number of points that graph manim
        "graph_origin" : ORIGIN+2*DOWN+4*LEFT,
        "x_labeled_nums": list(range(-2,5)),
        "y_labeled_nums": list(range(-2,5)),
        "x_axis_label":"$x$",
        "y_axis_label":r"$f(x)=y= 3-\frac { 3 }{ 2 } x$",
        "x_axis_width": 5,
        "y_axis_height": 5,
    }
	def construct(self):
		#XTD = self.x_axis_width/(self.x_max - self.x_min)
		#YTD = self.y_axis_height/(self.y_max - self.y_min)

		text1 = TextMobject("")
		text2 = TexMobject("{y}_{2}-{y}_{1}")
		text2 = TexMobject("{x}_{2}-{x}_{1}")
		text3 = TexMobject(r"m\quad =\frac { { y }_{ 2 }-{ y }_{ 1 } }{ { x }_{ 2 }-{ x }_{ 1 } }").move_to(np.array([3,0,0]))
		text4 = TexMobject(r"m\quad =\frac { 3 }{ -2 }").move_to(np.array([3,0,0]))
		text5 = TexMobject(r"m\quad =\quad -1.5").move_to(np.array([3,0,0]))
		self.setup_axes()
		graph_1 = self.get_graph(lambda x : 3-1.5*x, color = GREEN_SCREEN, x_min = -1, x_max = 3)
		graph_2 = self.get_graph(lambda x : 3.1-1.5*x, color = ORANGE, x_min = 0, x_max = 2)
		dot1 = Dot()
		dot2 = SmallDot(self.graph_origin+1.7*RIGHT, color = PINK)
		dot3 = SmallDot(self.graph_origin+2.5*UP, color = RED_B)
		vec1 = Vector(2.5*DOWN, color = PINK).shift(self.graph_origin+2.5*UP)
		vec2 = Vector(1.7*RIGHT, color = RED_B).shift(self.graph_origin)
		brace1 = Brace(vec1, LEFT)
		brace2 = Brace(vec2, DOWN)
		br1text = brace1.get_text(r"${y}_{2}-{y}_{1}$").next_to(brace1, LEFT)
		br2text = brace2.get_text(r"${x}_{2}-{x}_{1}$").next_to(brace2, DOWN) 
		self.play(ShowCreation(graph_1), ShowCreation(dot2), ShowCreation(dot3))
		self.play(MoveAlongPath(dot1, graph_2), ShowCreation(vec1), ShowCreation(vec2), run_time = 3)
		self.wait(1)
		self.play(ShowCreation(brace1), ShowCreation(brace2))
		self.play(ShowCreation(br1text), ShowCreation(br2text))
		self.wait(2)
		self.play(GrowFromCenter(text3))
		self.wait(2.5)
		self.play(ReplacementTransform(text3, text4))
		self.wait(2)
		self.play(ReplacementTransform(text4, text5))
		self.wait(2)