"
233 | ]
234 | },
235 | "metadata": {},
236 | "output_type": "display_data"
237 | }
238 | ],
239 | "source": [
240 | "%%manim -v WARNING --disable_caching -qm End\n",
241 | "\n",
242 | "class End(Scene):\n",
243 | " def construct(self):\n",
244 | " self.add(Title(\"Manim Version 0.6.0\"))\n",
245 | " f5t= Text(\"...and lots of other enhancements!\").scale(1.3).shift(UP)\n",
246 | " f5tb= Text(\"Visit us at docs.manim.community\",t2c={'[9:]':\"#e07a5f\"}).scale(1.3).shift(DOWN)\n",
247 | " self.play(FadeInFrom(f5t,DOWN))\n",
248 | " self.play(FadeInFrom(f5tb,DOWN))\n",
249 | " banner = ManimBanner(dark_theme=True).scale(0.3).to_corner(DR).shift(LEFT)\n",
250 | " self.play(FadeIn(banner))\n",
251 | " self.play(banner.expand())\n",
252 | " #self.play(FadeOut(banner))\n",
253 | " self.wait(2)"
254 | ]
255 | },
256 | {
257 | "cell_type": "code",
258 | "execution_count": null,
259 | "metadata": {},
260 | "outputs": [],
261 | "source": []
262 | },
263 | {
264 | "cell_type": "code",
265 | "execution_count": null,
266 | "metadata": {},
267 | "outputs": [],
268 | "source": [
269 | "\n",
270 | " class Indications(Scene):\n",
271 | " def construct(self):\n",
272 | " indications = [ApplyWave,Circumscribe,Flash,FocusOn,Indicate,ShowPassingFlash,Wiggle]\n",
273 | " names = [Tex(i.__name__).scale(3) for i in indications]\n",
274 | "\n",
275 | " self.add(names[0])\n",
276 | " for i in range(len(names)):\n",
277 | " if indications[i] is Flash:\n",
278 | " self.play(Flash(UP))\n",
279 | " elif indications[i] is ShowPassingFlash:\n",
280 | " self.play(ShowPassingFlash(Underline(names[i])))\n",
281 | " else:\n",
282 | " self.play(indications[i](names[i]))\n",
283 | " self.play(AnimationGroup(\n",
284 | " FadeOutAndShift(names[i], UP*1.5),\n",
285 | " FadeInFrom(names[(i+1)%len(names)], DOWN*1.5),\n",
286 | " ))\n"
287 | ]
288 | }
289 | ],
290 | "metadata": {
291 | "kernelspec": {
292 | "display_name": "Python 3",
293 | "language": "python",
294 | "name": "python3"
295 | },
296 | "language_info": {
297 | "codemirror_mode": {
298 | "name": "ipython",
299 | "version": 3
300 | },
301 | "file_extension": ".py",
302 | "mimetype": "text/x-python",
303 | "name": "python",
304 | "nbconvert_exporter": "python",
305 | "pygments_lexer": "ipython3",
306 | "version": "3.9.2"
307 | }
308 | },
309 | "nbformat": 4,
310 | "nbformat_minor": 4
311 | }
312 |
--------------------------------------------------------------------------------
/2021_06_03_v0.7.0_release_tour.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "id": "1059ad74",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "data": {
11 | "text/html": [
12 | "Manim Community v0.7.0\n",
13 | "\n",
14 | "
\n"
15 | ],
16 | "text/plain": [
17 | ""
18 | ]
19 | },
20 | "metadata": {},
21 | "output_type": "display_data"
22 | }
23 | ],
24 | "source": [
25 | "import manim\n",
26 | "from manim import *"
27 | ]
28 | },
29 | {
30 | "cell_type": "code",
31 | "execution_count": null,
32 | "id": "769fffc1",
33 | "metadata": {},
34 | "outputs": [],
35 | "source": []
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": 4,
40 | "id": "973b9b8c",
41 | "metadata": {},
42 | "outputs": [
43 | {
44 | "name": "stderr",
45 | "output_type": "stream",
46 | "text": [
47 | " \r"
48 | ]
49 | },
50 | {
51 | "data": {
52 | "text/html": [
53 | ""
56 | ],
57 | "text/plain": [
58 | ""
59 | ]
60 | },
61 | "metadata": {},
62 | "output_type": "display_data"
63 | }
64 | ],
65 | "source": [
66 | "%%manim -v WARNING --disable_caching -qh Intro\n",
67 | "\n",
68 | "class Intro(Scene):\n",
69 | " def construct(self):\n",
70 | " text=Text(\"Release Tour v0.7.0\").to_edge(UP).shift(DOWN).scale(2)\n",
71 | " self.add(text)\n",
72 | " banner = ManimBanner().scale(0.5).shift(DOWN)\n",
73 | " self.play(banner.create())\n",
74 | " self.wait()\n",
75 | " self.play(\n",
76 | " FadeOut(text),\n",
77 | " Transform(banner, ManimBanner().scale(0.3).to_corner(DR))\n",
78 | " )\n"
79 | ]
80 | },
81 | {
82 | "cell_type": "code",
83 | "execution_count": 6,
84 | "id": "f9c3c635",
85 | "metadata": {},
86 | "outputs": [
87 | {
88 | "name": "stderr",
89 | "output_type": "stream",
90 | "text": [
91 | " \r"
92 | ]
93 | },
94 | {
95 | "data": {
96 | "text/html": [
97 | ""
100 | ],
101 | "text/plain": [
102 | ""
103 | ]
104 | },
105 | "metadata": {},
106 | "output_type": "display_data"
107 | }
108 | ],
109 | "source": [
110 | "%%manim -v WARNING --disable_caching -qh Polar\n",
111 | "\n",
112 | "class Polar(Scene):\n",
113 | " def construct(self):\n",
114 | " self.add(ManimBanner().scale(0.3).to_corner(DR))\n",
115 | "\n",
116 | " polarplane_pi = PolarPlane(\n",
117 | " azimuth_units=\"PI radians\",\n",
118 | " size=6,\n",
119 | " azimuth_label_scale=0.7,\n",
120 | " radius_config={\"number_scale_value\": 0.7},\n",
121 | " ).add_coordinates()\n",
122 | " l1= Line(color=YELLOW)\n",
123 | " t1= Text(\"New Mobjects:\").scale(0.7)\n",
124 | " t2= Text(\"PolarPlane\").scale(0.7)\n",
125 | " t3= Text(\"ArcBrace\").scale(0.7)\n",
126 | "\n",
127 | " t1.to_corner(UR)\n",
128 | " t2.next_to(t1,DOWN)\n",
129 | " t2.set_color(BLUE)\n",
130 | " t3.set_color(YELLOW)\n",
131 | " t3.next_to(t2,DOWN)\n",
132 | "\n",
133 | "\n",
134 | " arc_2 = Arc(radius=2,start_angle=0,angle=PI/2).set_color(ORANGE)\n",
135 | " brace_2 = ArcBrace(arc_2).set_color(YELLOW)\n",
136 | " group_2 = VGroup(arc_2,brace_2)\n",
137 | " self.play(FadeIn(polarplane_pi,t1,t2))\n",
138 | " self.wait()\n",
139 | " self.play(FadeIn(group_2, t3))\n",
140 | " self.wait(2)\n",
141 | " self.play(FadeOut(polarplane_pi), FadeOut(t1), FadeOut(t2), FadeOut(t3), FadeOut(group_2))"
142 | ]
143 | },
144 | {
145 | "cell_type": "code",
146 | "execution_count": 7,
147 | "id": "fb886ca0",
148 | "metadata": {},
149 | "outputs": [
150 | {
151 | "name": "stderr",
152 | "output_type": "stream",
153 | "text": [
154 | " \r"
155 | ]
156 | },
157 | {
158 | "data": {
159 | "text/html": [
160 | ""
163 | ],
164 | "text/plain": [
165 | ""
166 | ]
167 | },
168 | "metadata": {},
169 | "output_type": "display_data"
170 | }
171 | ],
172 | "source": [
173 | "%%manim -v WARNING --disable_caching -qh StarPolygram\n",
174 | "\n",
175 | "class StarPolygram(Scene):\n",
176 | " def construct(self):\n",
177 | " self.add(ManimBanner().scale(0.3).to_corner(DR))\n",
178 | "\n",
179 | " e1=Dot()\n",
180 | " e1t=Text(\"Star\").to_edge(DOWN).shift(UP)\n",
181 | " e1 = Star(7, outer_radius=2, density=2, color=RED)\n",
182 | " e2 = Star(7, outer_radius=2, density=3, color=PURPLE)\n",
183 | " hexagram = Polygram(\n",
184 | " [[0, 2, 0], [-np.sqrt(3), -1, 0], [np.sqrt(3), -1, 0]],\n",
185 | " [[-np.sqrt(3), 1, 0], [0, -2, 0], [np.sqrt(3), 1, 0]],\n",
186 | " )\n",
187 | " self.play(FadeIn(e1t,e1))\n",
188 | " self.play(Transform(e1, e2))\n",
189 | " hexa_text=Text(\"Polygram\").to_edge(DOWN).shift(UP)\n",
190 | " self.play(FadeOut(e1, scale=2),FadeIn(hexagram, scale=0.1),FadeOut(e1t, scale=1.4), FadeIn(hexa_text,scale=0.4))\n",
191 | " self.wait()\n",
192 | " self.play(FadeOut(hexagram), FadeOut(hexa_text))"
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": 8,
198 | "id": "49af9fab",
199 | "metadata": {},
200 | "outputs": [
201 | {
202 | "name": "stderr",
203 | "output_type": "stream",
204 | "text": [
205 | " \r"
206 | ]
207 | },
208 | {
209 | "data": {
210 | "text/html": [
211 | ""
214 | ],
215 | "text/plain": [
216 | ""
217 | ]
218 | },
219 | "metadata": {},
220 | "output_type": "display_data"
221 | }
222 | ],
223 | "source": [
224 | "%%manim -v WARNING --disable_caching -qh Diagrams\n",
225 | "\n",
226 | "class Diagrams(Scene):\n",
227 | " def construct(self):\n",
228 | " # self.camera.background_color = WHITE\n",
229 | " text=Text(\"Class diagrams in the docs\").to_edge(UP).scale(1.2)\n",
230 | " self.add(BackgroundRectangle(text, buff=0.15))\n",
231 | " self.play(Write(text))\n",
232 | " self.wait()\n",
233 | "\n",
234 | " "
235 | ]
236 | },
237 | {
238 | "cell_type": "code",
239 | "execution_count": 10,
240 | "id": "22e5d38d",
241 | "metadata": {},
242 | "outputs": [
243 | {
244 | "name": "stderr",
245 | "output_type": "stream",
246 | "text": [
247 | " \r"
248 | ]
249 | },
250 | {
251 | "data": {
252 | "text/html": [
253 | ""
256 | ],
257 | "text/plain": [
258 | ""
259 | ]
260 | },
261 | "metadata": {},
262 | "output_type": "display_data"
263 | }
264 | ],
265 | "source": [
266 | "%%manim -v WARNING --disable_caching -qh ColorsOverview\n",
267 | "\n",
268 | "\n",
269 | "from manim.utils.color import Colors\n",
270 | "\n",
271 | "\n",
272 | "\n",
273 | "class ColorsOverview(Scene):\n",
274 | " def construct(self):\n",
275 | " banner = ManimBanner().scale(0.3).to_corner(DR)\n",
276 | " self.add(banner)\n",
277 | "\n",
278 | " def color_group(color):\n",
279 | " group = VGroup(\n",
280 | " *[\n",
281 | " Line(ORIGIN, RIGHT * 1.5, stroke_width=35, color=Colors[name].value)\n",
282 | " for name in subnames(color)\n",
283 | " ]\n",
284 | " ).arrange_submobjects(buff=0.4, direction=DOWN)\n",
285 | "\n",
286 | " name = Text(color).scale(0.6).next_to(group, UP, buff=0.3)\n",
287 | " if any(decender in color for decender in \"gjpqy\"):\n",
288 | " name.shift(DOWN * 0.08)\n",
289 | " group.add(name)\n",
290 | " return group\n",
291 | "\n",
292 | " def subnames(name):\n",
293 | " return [name + \"_\" + char for char in \"abcde\"]\n",
294 | "\n",
295 | " color_groups = VGroup(\n",
296 | " *[\n",
297 | " color_group(color)\n",
298 | " for color in [\n",
299 | " \"blue\",\n",
300 | " \"teal\",\n",
301 | " \"green\",\n",
302 | " \"yellow\",\n",
303 | " \"gold\",\n",
304 | " \"red\",\n",
305 | " \"maroon\",\n",
306 | " \"purple\",\n",
307 | " ]\n",
308 | " ]\n",
309 | " ).arrange_submobjects(buff=0.2, aligned_edge=DOWN)\n",
310 | "\n",
311 | " for line, char in zip(color_groups[0], \"abcde\"):\n",
312 | " color_groups.add(Text(char).scale(0.6).next_to(line, LEFT, buff=0.2))\n",
313 | "\n",
314 | " def named_lines_group(length, colors, names, text_colors, align_to_block):\n",
315 | " lines = VGroup(\n",
316 | " *[\n",
317 | " Line(\n",
318 | " ORIGIN,\n",
319 | " RIGHT * length,\n",
320 | " stroke_width=55,\n",
321 | " color=Colors[color].value,\n",
322 | " )\n",
323 | " for color in colors\n",
324 | " ]\n",
325 | " ).arrange_submobjects(buff=0.6, direction=DOWN)\n",
326 | "\n",
327 | " for line, name, color in zip(lines, names, text_colors):\n",
328 | " line.add(Text(name, color=color).scale(0.6).move_to(line))\n",
329 | " lines.next_to(color_groups, DOWN, buff=0.5).align_to(\n",
330 | " color_groups[align_to_block], LEFT\n",
331 | " )\n",
332 | " return lines\n",
333 | "\n",
334 | " other_colors = (\n",
335 | " \"pink\",\n",
336 | " \"light_pink\",\n",
337 | " \"orange\",\n",
338 | " \"light_brown\",\n",
339 | " \"dark_brown\",\n",
340 | " \"gray_brown\",\n",
341 | " )\n",
342 | "\n",
343 | " other_lines = named_lines_group(\n",
344 | " 3.2,\n",
345 | " other_colors,\n",
346 | " other_colors,\n",
347 | " [BLACK] * 4 + [WHITE] * 2,\n",
348 | " 0,\n",
349 | " )\n",
350 | "\n",
351 | " gray_lines = named_lines_group(\n",
352 | " 6.6,\n",
353 | " [\"white\"] + subnames(\"gray\") + [\"black\"],\n",
354 | " [\n",
355 | " \"white\",\n",
356 | " \"lighter_gray / gray_a\",\n",
357 | " \"light_gray / gray_b\",\n",
358 | " \"gray / gray_c\",\n",
359 | " \"dark_gray / gray_d\",\n",
360 | " \"darker_gray / gray_e\",\n",
361 | " \"black\",\n",
362 | " ],\n",
363 | " [BLACK] * 3 + [WHITE] * 4,\n",
364 | " 2,\n",
365 | " )\n",
366 | "\n",
367 | " pure_colors = (\n",
368 | " \"pure_red\",\n",
369 | " \"pure_green\",\n",
370 | " \"pure_blue\",\n",
371 | " )\n",
372 | "\n",
373 | " pure_lines = named_lines_group(\n",
374 | " 3.2,\n",
375 | " pure_colors,\n",
376 | " pure_colors,\n",
377 | " [BLACK, BLACK, WHITE],\n",
378 | " 6,\n",
379 | " )\n",
380 | "\n",
381 | " self.add(color_groups, other_lines, gray_lines, pure_lines)\n",
382 | "\n",
383 | " VGroup(*self.mobjects).remove(banner).move_to(ORIGIN)\n",
384 | " self.remove(color_groups, other_lines, gray_lines, pure_lines)\n",
385 | " tt=Text(\"New color cheatsheet in the docs\")\n",
386 | " self.play(FadeIn(tt), run_time=0.2)\n",
387 | " self.play(FadeIn(color_groups,shift=0.1*UP, lag_ratio=0.05), run_time=3)\n",
388 | " self.play(FadeOut(tt),run_time=0.2)\n",
389 | "\n",
390 | " self.play(FadeIn(other_lines,gray_lines,pure_lines,shift=0.1*UP))\n",
391 | " self.wait()\n",
392 | " self.play(FadeOut(*self.mobjects))\n",
393 | "\n"
394 | ]
395 | },
396 | {
397 | "cell_type": "code",
398 | "execution_count": 16,
399 | "id": "a2b4c2d8",
400 | "metadata": {},
401 | "outputs": [
402 | {
403 | "name": "stderr",
404 | "output_type": "stream",
405 | "text": [
406 | " \r"
407 | ]
408 | },
409 | {
410 | "data": {
411 | "text/html": [
412 | ""
415 | ],
416 | "text/plain": [
417 | ""
418 | ]
419 | },
420 | "metadata": {},
421 | "output_type": "display_data"
422 | }
423 | ],
424 | "source": [
425 | "%%manim -v WARNING --disable_caching -qh End\n",
426 | "\n",
427 | "class End(Scene):\n",
428 | " def construct(self):\n",
429 | " banner = ManimBanner().scale(0.3).to_corner(DR)\n",
430 | " self.add(banner)\n",
431 | "\n",
432 | " f5t= Text(\"...and lots of other enhancements!\").scale(1.3).shift(UP)\n",
433 | " f5tb= Text(\"Visit us at docs.manim.community\",t2c={'[9:]':\"#e07a5f\"}).scale(1.3).shift(DOWN)\n",
434 | " self.play(FadeIn(f5t,shift=UP))\n",
435 | " self.play(FadeIn(f5tb,shift=UP))\n",
436 | " self.play(banner.animate.shift(LEFT))\n",
437 | " self.play(banner.expand())\n",
438 | " self.wait(2)\n"
439 | ]
440 | },
441 | {
442 | "cell_type": "code",
443 | "execution_count": null,
444 | "id": "becba3fe",
445 | "metadata": {},
446 | "outputs": [],
447 | "source": []
448 | }
449 | ],
450 | "metadata": {
451 | "kernelspec": {
452 | "display_name": "Python 3",
453 | "language": "python",
454 | "name": "python3"
455 | },
456 | "language_info": {
457 | "codemirror_mode": {
458 | "name": "ipython",
459 | "version": 3
460 | },
461 | "file_extension": ".py",
462 | "mimetype": "text/x-python",
463 | "name": "python",
464 | "nbconvert_exporter": "python",
465 | "pygments_lexer": "ipython3",
466 | "version": "3.9.2"
467 | }
468 | },
469 | "nbformat": 4,
470 | "nbformat_minor": 5
471 | }
472 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 |
4 | If you haven't read our code of conduct, please do so at the
5 | [manim repository](https://github.com/ManimCommunity/manim/blob/master/CODE_OF_CONDUCT.md#code-of-conduct).
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM manimcommunity/manim:v0.3.0
2 |
3 | COPY --chown=manimuser:manimuser . /manim
4 |
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Manim Community
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # manim-tweets
2 |
3 | Code for tweets by @manim_community on twitter. Both the code and video output are licensed under the MIT license.
4 |
5 | ## Try online without installation:
6 |
7 | [](https://mybinder.org/v2/gh/ManimCommunity/manim-tweets/HEAD?filepath=jupyter_notebooks%2Fpendulum%2Fpendulum_example.ipynb) : An animated pendulum
8 |
9 | **NOTE**
10 |
11 | The filenames are in the format `year_date_day_scenename.py` (e.g.`2020_12_08_lissajous_curve.py`).
12 | Be aware that the day might be off +-1 of the day of the tweet because of different time zones.
13 |
14 | ## Code of Conduct
15 |
16 | Our full code of conduct, and how we enforce it, can be read on [our website](https://docs.manim.community/en/latest/conduct.html).
17 |
--------------------------------------------------------------------------------
/assets/2021_01_03/config_new.py:
--------------------------------------------------------------------------------
1 | obj = MyAwesomeMobject(coolness=9001)
2 |
--------------------------------------------------------------------------------
/assets/2021_01_03/config_old.py:
--------------------------------------------------------------------------------
1 | class MyAwesomeMobject:
2 | CONFIG = {
3 | "coolness": 9001,
4 | }
5 |
6 |
7 | obj = MyAwesomeMobject()
8 |
--------------------------------------------------------------------------------
/assets/2021_01_03/markup_example.py:
--------------------------------------------------------------------------------
1 | group = VGroup(
2 | MarkupText("foo bar foobar"),
3 | MarkupText("foo bar" "big small"),
4 | MarkupText('colors'),
5 | ).arrange(DOWN)
6 | self.add(group)
7 |
--------------------------------------------------------------------------------
/assets/2021_01_03/methodanim_new.py:
--------------------------------------------------------------------------------
1 | sq = Square()
2 | self.play(sq.animate.scale(0.65).rotate(-PI / 4))
3 |
--------------------------------------------------------------------------------
/assets/2021_01_03/methodanim_old.py:
--------------------------------------------------------------------------------
1 | sq = Square()
2 | self.play(sq.scale, 0.65, sq.rotate, -PI / 4)
3 |
--------------------------------------------------------------------------------
/assets/2021_01_03/rubikscube.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ManimCommunity/manim-tweets/fd6b76f51227426ff21677d55a56c9a3031bf1ac/assets/2021_01_03/rubikscube.png
--------------------------------------------------------------------------------
/assets/2021_03_04/Blivet2.svg:
--------------------------------------------------------------------------------
1 |
2 |
18 |
--------------------------------------------------------------------------------
/assets/2021_03_04/present.svg:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/assets/2021_03_04/rocket-2.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
70 |
--------------------------------------------------------------------------------
/assets/2021_03_04/tree.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/jupyter_notebooks/pendulum/pendulum.py:
--------------------------------------------------------------------------------
1 | from manim import *
2 |
3 |
4 | class Pendulum(VGroup):
5 | def phi_function(self, amplitude, acceleration, length, time):
6 | return amplitude * np.sin(np.sqrt(acceleration / length) * time - np.pi / 2)
7 |
8 | def __init__(self, weight, amplitude, acceleration, length, time):
9 | VGroup.__init__(self)
10 | self.sound_stamps_there = []
11 | self.sound_stamps_back = []
12 |
13 | self.amplitude = amplitude
14 | self.acceleration = acceleration
15 | self.length = length
16 | self.time = time
17 | self.phi = self.phi_function(amplitude, acceleration, length, time)
18 | self.anchor = Dot(ORIGIN)
19 | self.line = Line(ORIGIN, length * DOWN)
20 | self.line.rotate(self.phi * DEGREES, about_point=self.line.get_start())
21 | self.mass = LabeledDot(label=f"{weight}" + r"\, \text{kg}").scale(0.3)
22 | self.mass.move_to(self.line.get_end())
23 | self.mobj = VGroup(self.line, self.anchor, self.mass)
24 | self.add(self.mobj)
25 |
26 | def start(self):
27 | self.mobj.current_time = 0.000001
28 |
29 | def updater(mob, dt):
30 | mob.current_time += dt
31 | new_phi = self.phi_function(
32 | self.amplitude, self.acceleration, self.length, mob.current_time
33 | )
34 | mob[0].rotate(
35 | (new_phi - self.phi) * DEGREES, about_point=self.line.get_start()
36 | )
37 | if np.sign(self.phi) < np.sign(new_phi):
38 | self.sound_stamps_there.append(mob.current_time)
39 | if np.sign(self.phi) > np.sign(new_phi):
40 | self.sound_stamps_back.append(mob.current_time)
41 |
42 | self.phi = new_phi
43 | self.mass.move_to(self.line.get_end())
44 |
45 | self.mobj.add_updater(updater)
46 |
--------------------------------------------------------------------------------
/jupyter_notebooks/pendulum/pendulum_example.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import manim\n",
10 | "from pendulum import Pendulum\n",
11 | "from manim import *"
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": null,
17 | "metadata": {},
18 | "outputs": [],
19 | "source": [
20 | "%%manim Pendulum1 -v WARNING --disable_caching -qm -s \n",
21 | "\n",
22 | "class Pendulum1(Scene):\n",
23 | " def construct(self):\n",
24 | " pendulum = Pendulum(weight=1, amplitude=12, acceleration=10, length=3, time=0)\n",
25 | " self.add(pendulum)"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": null,
31 | "metadata": {},
32 | "outputs": [],
33 | "source": [
34 | "%%manim Pendulum2 -v WARNING --disable_caching -qm -s\n",
35 | "# remove -s to see the video\n",
36 | "\n",
37 | "class Pendulum2(Scene):\n",
38 | " def construct(self):\n",
39 | " pendulum = Pendulum(weight=1, amplitude=12, acceleration=10, length=3, time=0)\n",
40 | " self.add(pendulum)\n",
41 | " pendulum.start()\n",
42 | " self.wait(2)"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "%%manim Pendulum3 -v WARNING --disable_caching -qm \n",
52 | "\n",
53 | "class Pendulum3(Scene):\n",
54 | " def construct(self):\n",
55 | " amplitudes = [5,10,15,20,25,30,35]\n",
56 | " total= len(amplitudes)\n",
57 | " for i,val in enumerate(amplitudes):\n",
58 | " pendulum = Pendulum(weight= 1.8,amplitude=val,acceleration= 10, length=4,time= 0)\n",
59 | " anchor_pos= pendulum.anchor.get_center()\n",
60 | " pendulum.anchor.set_color(YELLOW)\n",
61 | " pendulum.mass.scale(1.8)\n",
62 | " dest_pos = (-total/2+i)*1.2*RIGHT+2*UP\n",
63 | " pendulum.shift(anchor_pos+dest_pos)\n",
64 | " self.add(pendulum)\n",
65 | " pendulum.start()\n",
66 | " self.wait(6)"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": null,
72 | "metadata": {},
73 | "outputs": [],
74 | "source": [
75 | "%%manim Pendulum4 -v WARNING --disable_caching -qm \n",
76 | "\n",
77 | "class Pendulum4(Scene):\n",
78 | " def construct(self):\n",
79 | " lengths = [2,2.2,2.3,2.4,2.5,2.6]\n",
80 | " total= len(lengths)\n",
81 | " for i,val in enumerate(lengths):\n",
82 | " pendulum = Pendulum(weight= 4,amplitude=30,acceleration= 10, length=val,time= 0)\n",
83 | " pendulum.anchor.set_color(RED)\n",
84 | " pendulum.mass.scale(1.4)\n",
85 | " anchor_pos= pendulum.anchor.get_center()\n",
86 | " dest_pos = (-total/2+i)*1.1*RIGHT+2*UP\n",
87 | " pendulum.shift(anchor_pos+dest_pos)\n",
88 | " self.add(pendulum)\n",
89 | " pendulum.start()\n",
90 | " waiting_time=6\n",
91 | " self.wait(waiting_time)\n",
92 | "\n",
93 | " for mobj in self.mobjects:\n",
94 | " for sound_stamp in mobj.sound_stamps_there:\n",
95 | " self.add_sound(\"tick.mp3\", time_offset=-waiting_time + sound_stamp)\n",
96 | " for sound_stamp in mobj.sound_stamps_back:\n",
97 | " self.add_sound(\"tock.mp3\", time_offset=-waiting_time + sound_stamp)\n",
98 | " self.wait(1)"
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": null,
104 | "metadata": {},
105 | "outputs": [],
106 | "source": []
107 | }
108 | ],
109 | "metadata": {
110 | "kernelspec": {
111 | "display_name": "Python 3",
112 | "language": "python",
113 | "name": "python3"
114 | },
115 | "language_info": {
116 | "codemirror_mode": {
117 | "name": "ipython",
118 | "version": 3
119 | },
120 | "file_extension": ".py",
121 | "mimetype": "text/x-python",
122 | "name": "python",
123 | "nbconvert_exporter": "python",
124 | "pygments_lexer": "ipython3",
125 | "version": "3.9.1"
126 | }
127 | },
128 | "nbformat": 4,
129 | "nbformat_minor": 4
130 | }
131 |
--------------------------------------------------------------------------------
/jupyter_notebooks/pendulum/tick.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ManimCommunity/manim-tweets/fd6b76f51227426ff21677d55a56c9a3031bf1ac/jupyter_notebooks/pendulum/tick.mp3
--------------------------------------------------------------------------------
/jupyter_notebooks/pendulum/tock.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ManimCommunity/manim-tweets/fd6b76f51227426ff21677d55a56c9a3031bf1ac/jupyter_notebooks/pendulum/tock.mp3
--------------------------------------------------------------------------------