-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathgradient.py
100 lines (81 loc) · 2.3 KB
/
gradient.py
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
from manimlib import *
from manimlib.once_useful_constructs.graph_scene import GraphScene
YELLOW_Z = "#e2e1a4"
A_AQUA = "#8dd3c7"
A_YELLOW = "#ffffb3"
A_LAVENDER = "#bebada"
A_RED = "#fb8072"
A_BLUE = "#80b1d3"
A_ORANGE = "#fdb462"
A_GREEN = "#b3de69"
A_PINK = "#fccde5"
A_GREY = "#d9d9d9"
A_VIOLET = "#bc80bd"
A_UNKA = "#ccebc5"
A_UNKB = "#ffed6f"
class Intro(Scene):
def construct(self):
self.interact()
l = Line(10 * UP, 10 * DOWN)
title1 = TexText("Single Variable")
title1.scale(1.5)
title1.move_to(FRAME_WIDTH/4 * LEFT + 3.5 * UP, UP)
title2 = TexText("Multivariable")
title2.scale(1.5)
title2.move_to(FRAME_WIDTH/4 * RIGHT + 3.5 * UP, UP)
self.play(FadeIn(title1, DOWN), FadeIn(title2, DOWN), Write(l))
self.embed()
class IntroGraphLeft(GraphScene):
CONFIG = {
"x_max": 4,
"x_labeled_nums": list(range(-1, 5)),
"y_min": 0,
"y_max": 2,
"y_tick_frequency": 2.5,
"y_labeled_nums": list(range(5, 20, 5)),
"n_rect_iterations": 1,
"default_right_x": 3,
"func": lambda x: 0.1*math.pow(x-2, 2) + 1,
"y_axis_label": "",
}
def construct(self):
self.setup_axes()
graph = self.get_graph(self.func)
self.play(ShowCreation(graph))
self.graph = graph
rects = VGroup()
for dx in np.arange(0.2, 0.05, -0.05):
rect = self.get_riemann_rectangles(
self.graph,
x_min=0,
x_max=self.default_right_x,
dx=dx,
stroke_width=4*dx,
)
rects.add(rect)
self.play(
DrawBorderThenFill(
rects[0],
run_time=2,
rate_func=smooth,
lag_ratio=0.5,
),
)
self.wait()
for rect in rects[1:]:
self.play(
Transform(
rects[0], rect,
run_time=2,
rate_func=smooth,
lag_ratio=0.5,
),
)
self.wait()
self.embed()
class IntroGraphRight(Scene):
def construct(self):
self.embed()
class PartialExample(Scene):
def construct(self):
self.embed()