Last active
December 6, 2021 13:06
-
-
Save behackl/99bd625701cfa86d08bde8c2d9c6def2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM manimcommunity/manim:v0.13.1 | |
COPY --chown=manimuser:manimuser . /manim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "discrete-battlefield", | |
"metadata": {}, | |
"source": [ | |
"## Mathematical Animations WITH EASE | Ep. 01: An Invitation\n", | |
"\n", | |
"This notebook contains the examples discussed in [this video](https://youtu.be/rUsUrbWb2D4). The cells below contain the final state of the corresponding scene from the video. Feel free to modify the code below and play around, your changes are only local and just visible to you. To add some more new cells, you can use the \"+\" icon above.\n", | |
"\n", | |
"To run cells, click on them so that they are in focus, then either the \"Run\" button above, or hit `<Shift + Enter>`." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "laden-series", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from manim import *" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "hydraulic-bracelet", | |
"metadata": {}, | |
"source": [ | |
"These are some useful basic settings for Jupyter notebooks. You can use them by executing the cell, or just skip them." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "informal-combine", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"config.media_width = \"80%\"\n", | |
"config.verbosity = \"WARNING\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "collective-flexibility", | |
"metadata": {}, | |
"source": [ | |
"## Part 2: Basic Anatomy of Manimations" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "adopted-fluid", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%%manim -qm FirstExample\n", | |
"\n", | |
"class FirstExample(Scene):\n", | |
" def construct(self):\n", | |
" blue_circle = Circle(color=BLUE, fill_opacity=0.5)\n", | |
" green_square = Square(color=GREEN, fill_opacity=0.8)\n", | |
" green_square.next_to(blue_circle, RIGHT)\n", | |
" self.add(blue_circle, green_square)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "electric-judge", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%%manim -qm SecondExample\n", | |
"\n", | |
"class SecondExample(Scene):\n", | |
" def construct(self):\n", | |
" ax = Axes(x_range=(-3, 3), y_range=(-3, 3))\n", | |
" curve = ax.plot(lambda x: (x+2)*x*(x-2)/2, color=RED)\n", | |
" area = ax.get_area(curve, (-2, 0))\n", | |
" self.add(ax, curve, area)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "unauthorized-absolute", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "boring-banking", | |
"metadata": {}, | |
"source": [ | |
"## Part 3: Where are the Animations?!" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "liquid-conflict", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%%manim -qm SecondExample\n", | |
"\n", | |
"class SecondExample(Scene):\n", | |
" def construct(self):\n", | |
" ax = Axes(x_range=(-3, 3), y_range=(-3, 3))\n", | |
" curve = ax.plot(lambda x: (x+2)*x*(x-2)/2, color=RED)\n", | |
" area = ax.get_area(curve, x_range=(-2, 0))\n", | |
" self.play(Create(ax, run_time=2), Create(curve, run_time=5))\n", | |
" self.play(FadeIn(area))\n", | |
" self.wait(2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "vocal-forth", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%%manim -qm SquareToCircle\n", | |
"\n", | |
"class SquareToCircle(Scene):\n", | |
" def construct(self):\n", | |
" green_square = Square(color=GREEN, fill_opacity=0.5)\n", | |
" self.play(DrawBorderThenFill(green_square))\n", | |
" blue_circle = Circle(color=BLUE, fill_opacity=0.5)\n", | |
" self.play(ReplacementTransform(green_square, blue_circle))\n", | |
" self.play(Indicate(blue_circle))\n", | |
" self.play(FadeOut(blue_circle))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "dirty-insider", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "italic-maintenance", | |
"metadata": {}, | |
"source": [ | |
"## Bonus: Complex Exponential Spiral" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "studied-present", | |
"metadata": {}, | |
"source": [ | |
"This has not been discussed in the first episode, but might nonetheless give you a good impression of how a more complex (pun intended) scene looks like." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "european-cattle", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%%manim -qm ComplexExp\n", | |
"\n", | |
"class ComplexExp(ThreeDScene):\n", | |
" def construct(self):\n", | |
" axes = ThreeDAxes(x_range=(-0.1, 4.25), y_range=(-1.5, 1.5), z_range=(-1.5, 1.5), y_length=5, z_length=5)\n", | |
" curve = ParametricFunction(\n", | |
" lambda p: axes.coords_to_point(p, np.exp(complex(0, PI*p)).real, np.exp(complex(0, PI*p)).imag),\n", | |
" t_range=(0, 2, 0.1)\n", | |
" )\n", | |
" curve_extension = ParametricFunction(\n", | |
" lambda p: axes.coords_to_point(p, np.exp(complex(0, PI*p)).real, np.exp(complex(0, PI*p)).imag),\n", | |
" t_range=(2, 4, 0.1)\n", | |
" )\n", | |
" t = MathTex(\"z = e^{t \\pi i}, \\quad t\\in [0, 2]\")\n", | |
" t.rotate(axis=OUT, angle=90*DEGREES).rotate(axis=UP, angle=90*DEGREES)\n", | |
" t.next_to(curve, UP + OUT)\n", | |
" self.set_camera_orientation(phi=90*DEGREES, theta=0, focal_distance=10000)\n", | |
" self.add(axes)\n", | |
" self.play(Create(curve, run_time=2), Write(t))\n", | |
" self.wait()\n", | |
" self.move_camera(phi=75*DEGREES, theta=-30*DEGREES)\n", | |
" self.wait()\n", | |
" four = MathTex(\"4\").rotate(axis=OUT, angle=90*DEGREES).rotate(axis=UP, angle=90*DEGREES)\n", | |
" four.move_to(t[0][12])\n", | |
" self.play(Create(curve_extension, run_time=2), t[0][12].animate.become(four))\n", | |
" self.wait()\n", | |
" self.move_camera(phi=90*DEGREES, theta=-90*DEGREES, focal_distance=10000)\n", | |
" self.wait()\n", | |
" self.move_camera(phi=75*DEGREES, theta=-30*DEGREES)\n", | |
" self.wait()\n", | |
" self.move_camera(phi=0, theta=-90*DEGREES, focal_distance=10000)\n", | |
" self.wait()\n", | |
" self.move_camera(phi=75*DEGREES, theta=-30*DEGREES)\n", | |
" self.wait()\n", | |
" self.play(FadeOut(axes, curve, curve_extension, t, shift=IN))\n", | |
" self.wait()\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "worldwide-utilization", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3.9.7 64-bit ('manim-U7iPD1cl-py3.9': poetry)", | |
"language": "python", | |
"name": "python397jvsc74a57bd0077578ffb0885fac61d66748d17d69ece81a9c3c2de51f585b3d06d19f35a5ea" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment