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
127
128
129
130
131
132
|
# Plotting Graphs
from manimlib.imports import *
class PlotGraphs(GraphScene):
CONFIG = {
"x_min": -5,
"x_max": 5,
"y_min": 0,
"y_max": 4,
"graph_origin": ORIGIN + 2.5* DOWN,
"x_labeled_nums": list(range(-5, 6)),
"y_labeled_nums": list(range(0, 5)),
}
def construct(self):
topic = TextMobject("Domain and Range")
topic.scale(2)
topic.set_color(YELLOW)
self.play(Write(topic))
self.play(FadeOut(topic))
self.wait(1)
XTD = self.x_axis_width/(self.x_max- self.x_min)
YTD = self.y_axis_height/(self.y_max- self.y_min)
self.setup_axes(animate = True)
graphobj = self.get_graph(lambda x : np.sqrt(x + 4), x_min = -4, x_max = 5)
graph_lab = self.get_graph_label(graphobj, label = r"\sqrt{x + 4}")
rangeline1 = Arrow(self.graph_origin+2.2*YTD*UP+5*XTD*LEFT, self.graph_origin+4.1*YTD*UP+5*XTD*LEFT)
rangeline2 = Arrow(self.graph_origin+1.7*YTD*UP+5*XTD*LEFT, self.graph_origin+5*XTD*LEFT)
rangeline1.set_color(RED)
rangeline2.set_color(RED)
rangeMsg = TextMobject(r"Range: $y \geq 0$")
rangeMsg.move_to(self.graph_origin+2*YTD*UP+5*XTD*LEFT)
rangeMsg.scale(0.5)
rangeMsg.set_color(YELLOW)
domainline1 = Line(self.graph_origin+0.6*YTD*DOWN+1.2*XTD*LEFT, self.graph_origin+0.6*YTD*DOWN + 4*XTD*LEFT)
domainline2 = Arrow(self.graph_origin+0.6*YTD*DOWN+1.1*XTD*RIGHT, self.graph_origin+0.6*YTD*DOWN + 5.3*XTD*RIGHT)
domainline1.set_color(PINK)
domainline2.set_color(PINK)
domainMsg = TextMobject(r"Domain: $x \geq -4$")
domainMsg.move_to(self.graph_origin+0.6*YTD*DOWN)
domainMsg.scale(0.5)
domainMsg.set_color(GREEN)
self.play(ShowCreation(graphobj))
self.play(ShowCreation(graph_lab))
self.wait(1)
self.play(GrowArrow(rangeline1))
self.play(GrowArrow(rangeline2))
self.play(Write(rangeMsg))
self.wait(1)
self.play(GrowArrow(domainline1))
self.play(GrowArrow(domainline2))
self.play(Write(domainMsg))
self.wait(3)
self.wait(2)
class PlotSineGraphs(GraphScene):
CONFIG = {
"x_min": -8,
"x_max": 8,
"y_min": -1,
"y_max": 1,
"graph_origin": ORIGIN,
"x_labeled_nums": list(range(-8, 9)),
"y_labeled_nums": list(range(-1, 2)),
}
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)
self.setup_axes(animate = True)
sineobj = self.get_graph(lambda x : np.sin(x), x_min = -7, x_max = 8)
sine_lab = self.get_graph_label(sineobj, label = "\\sin(x)")
rangeline1 = Line(8*XTD*LEFT,1*YTD*UP+8*XTD*LEFT)
rangeline2 = Line(8*XTD*LEFT,1*YTD*DOWN+8*XTD*LEFT)
rangeline1.set_color(RED)
rangeline2.set_color(RED)
rangeMsg = TextMobject(r"Range: $-1 \leq y \leq 1$")
rangeMsg.move_to(1.1*YTD*UP+8.5*XTD*LEFT)
rangeMsg.scale(0.5)
rangeMsg.set_color(YELLOW)
domainline1 = Arrow(1.1*YTD*DOWN+2*XTD*LEFT, 1.1*YTD*DOWN + 8.5*XTD*LEFT)
domainline2 = Arrow(1.1*YTD*DOWN+2*XTD*RIGHT, 1.1*YTD*DOWN + 8.5*XTD*RIGHT)
domainline1.set_color(PINK)
domainline2.set_color(PINK)
domainMsg = TextMobject(r"Domain: $[-\infty, \infty]$")
domainMsg.move_to(1.1*YTD*DOWN)
domainMsg.scale(0.5)
domainMsg.set_color(GREEN)
self.play(ShowCreation(sineobj))
self.play(ShowCreation(sine_lab))
self.wait(1)
self.play(GrowArrow(rangeline1))
self.play(GrowArrow(rangeline2))
self.play(Write(rangeMsg))
self.wait(1)
self.play(GrowArrow(domainline1))
self.play(GrowArrow(domainline2))
self.play(Write(domainMsg))
self.wait(3)
|