-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
142 lines (137 loc) · 4.17 KB
/
index.js
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
133
134
135
136
137
138
139
140
141
142
// stripIndents is imported from 'common-tags'
// for storing code in template strings and preserving indentation
const { stripIndents } = commonTags;
const app = new Vue({
el: "#app",
data: {
paused: false,
src: "videos/Mobjects.mp4",
mobjects: [
{
title: "TextMobject",
time: 0,
code: stripIndents`
# TextMobject
text_mobject = TextMobject("TextMobject")
self.play(Write(text_mobject))
self.wait()
self.play(FadeOut(text_mobject))`
},
{
title: "TexMobject",
time: 4,
code: stripIndents`
# TexMobject
tex_mobject = TextMobject("TexMobject")
tex_mobject.shift(UP)
formula = TexMobject("\sum_{k=0}^\\infty \\frac{c}{k^2} = \\frac{8\\pi^2}{996}")
formula.shift(UP)
formula.next_to(tex_mobject, DOWN)
self.play(Write(tex_mobject), Write(formula))
self.wait()
self.play(FadeOut(tex_mobject), FadeOut(formula))`
},
{
title: "NumberLine",
time: 8,
code: stripIndents`
# number line
number_line = NumberLine()
number_line.add_numbers()
self.play(ShowCreation(number_line, submobject_mode = "one_at_a_time"))
number_line_text = TextMobject("NumberLine")
number_line_text.shift(UP)
self.play(Write(number_line_text))
self.wait()
self.play(FadeOut(number_line_text))
self.play(FadeOut(number_line))`
},
{
title: "NumberPlane",
time: 13,
code: stripIndents`
# TexMobject
tex_mobject = TextMobject("TexMobject")
tex_mobject.shift(UP)
formula = TexMobject("\sum_{k=0}^\\infty \\frac{c}{k^2} = \\frac{8\\pi^2}{996}")
formula.shift(UP)
formula.next_to(tex_mobject, DOWN)
self.play(Write(tex_mobject), Write(formula))
self.wait()
self.play(FadeOut(tex_mobject), FadeOut(formula))`
},
{
title: "Vector",
time: 16,
code: stripIndents`
# vector
vector = Vector([-2, 3])
self.show_mobject("Vector", vector, GrowArrow, shift=UP+2*LEFT)`
},
{
title: "Dot",
time: 20,
code: stripIndents`
# dot
self.show_mobject("Dot", Dot(radius = 0.1).set_color(RED),
GrowFromCenter, shift=0.5*(UP+LEFT))`
},
{
title: "Line",
time: 24,
code: `self.show_mobject("Line", Line(ORIGIN, UP+2*RIGHT), ShowCreation, shift=1.5*(UP+0.5*RIGHT))`
},
{
title: "Brace",
time: 26,
code: "Brace"
},
{
title: "ParametricFunction",
time: 30,
code: stripIndents`
graph = ParametricFunction(lambda t : 4*t*RIGHT + 2*smooth(t)*UP)
graph_line = Line(graph.points[0], graph.points[-1], color = WHITE)
graph_text = TextMobject("ParametricFunction")
graph_text.next_to(graph, 0.5*UP+2*LEFT)
self.play(ShowCreation(graph), Write(graph_text))
self.play(Transform(graph, graph_line))
self.play(Uncreate(graph), FadeOut(graph_text))`
}
]
},
methods: {
jumpTo(time) {
manimVid.play();
manimVid.pause();
manimVid.currentTime = time;
manimVid.play();
paused = false;
},
playPause() {
if (manimVid.paused) {
manimVid.play();
} else {
manimVid.pause();
}
}
}
});
// update the code block with the corresponding mobject's code
const code = document.querySelector("#code");
const updateMobjectTimer = () => {
// access mobjects directly from Vue data
let mobjectOn = app.$data.mobjects[0];
for (let i = 0; i < app.$data.mobjects.length; i++) {
const mobject = app.$data.mobjects[i];
// see which mobject the video is currently on
time = manimVid.currentTime;
if (mobject.time < time) {
mobjectOn = mobject;
} else {
break;
}
}
code.innerText = mobjectOn.code;
};
setInterval(updateMobjectTimer, 500);