Skip to content

Instantly share code, notes, and snippets.

@behackl
Created February 2, 2021 13:24
Show Gist options
  • Save behackl/ea8a0fe78f9fa1d02ea115648f8faf82 to your computer and use it in GitHub Desktop.
Save behackl/ea8a0fe78f9fa1d02ea115648f8faf82 to your computer and use it in GitHub Desktop.
Manim Community v0.3.0 interactive release tour (mybinder.org)
FROM manimcommunity/manim:v0.3.0
COPY --chown=manimuser:manimuser . /manim
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "unlikely-gates",
"metadata": {},
"source": [
"<p align=\"center\">\n",
" <img src=\"https://raw.githubusercontent.com/ManimCommunity/manim/master/logo/cropped.png\">\n",
"</p>\n",
"\n",
"# Manim v0.3.0\n",
"\n",
"The full changelog can be found at https://docs.manim.community/en/v0.3.0/changelog.html#v0-3-0.\n",
"\n",
"This is a Jupyter notebook where you can try all the _features_ released in this version interactively. Your changes are only visible for you and will not be visible for others. To keep the changes, you will have to download the Notebook.\n",
"\n",
"[**Code Of Conduct**](https://docs.manim.community/en/v0.3.0/conduct.html)"
]
},
{
"cell_type": "markdown",
"id": "established-administration",
"metadata": {},
"source": [
"As a first step, `manim` has to be imported."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "gentle-arrival",
"metadata": {},
"outputs": [],
"source": [
"from manim import *"
]
},
{
"cell_type": "markdown",
"id": "organizational-practice",
"metadata": {},
"source": [
"## [#943](https://github.com/ManimCommunity/manim/pull/943): IPython %%manim magic\n",
"\n",
"Now, Manim can run directly in notebooks using the `%%manim` magic:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "precious-jacob",
"metadata": {},
"outputs": [],
"source": [
"%%manim SquareToCircle -qm -v WARNING\n",
"\n",
"class SquareToCircle(Scene):\n",
" def construct(self):\n",
" circle = Circle()\n",
" square = Square()\n",
" square.flip(RIGHT)\n",
" square.rotate(-3 * TAU / 8)\n",
" circle.set_fill(PINK, opacity=0.5)\n",
"\n",
" self.play(ShowCreation(square))\n",
" self.play(Transform(square, circle))\n",
" self.play(FadeOut(square))"
]
},
{
"cell_type": "markdown",
"id": "known-specialist",
"metadata": {},
"source": [
"## [#970](https://github.com/ManimCommunity/manim/pull/970): New command to get Manim's version\n",
"\n",
"Locally, running\n",
"```sh\n",
"manim --version\n",
"```\n",
"will now print the installed version of manim."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "numeric-packing",
"metadata": {},
"outputs": [],
"source": [
"!manim --version"
]
},
{
"cell_type": "markdown",
"id": "supported-chosen",
"metadata": {},
"source": [
"## [#948](https://github.com/ManimCommunity/manim/pull/948): Code strings can now be passed to [`Code`](https://docs.manim.community/en/v0.3.0/reference/manim.mobject.svg.code_mobject.Code.html#manim.mobject.svg.code_mobject.Code)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "figured-michael",
"metadata": {},
"outputs": [],
"source": [
"%%manim CodeString -qm -s -v WARNING\n",
"\n",
"codestring = \\\n",
"\"\"\"\n",
"from manim import *\n",
"print(\"Welcome To Manim\")\n",
"\"\"\"\n",
"\n",
"class CodeString(Scene):\n",
" def construct(self):\n",
" code = Code(\n",
" code=codestring,\n",
" tab_width=4,\n",
" background=\"window\",\n",
" language=\"Python\",\n",
" font=\"Monospace\"\n",
" )\n",
" self.add(code)"
]
},
{
"cell_type": "markdown",
"id": "future-sapphire",
"metadata": {},
"source": [
"## [#917](https://github.com/ManimCommunity/manim/pull/917): Allow overriding new-style method animations\n",
"\n",
"See https://docs.manim.community/en/v0.3.0/reference/manim.mobject.mobject.html#manim.mobject.mobject.override_animate for some more detailed documentation."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "unsigned-powell",
"metadata": {},
"outputs": [],
"source": [
"%%manim AnimationOverrideExample -qm -v WARNING\n",
"\n",
"class CircleWithContent(VGroup):\n",
" def __init__(self, content):\n",
" super().__init__()\n",
" self.circle = Circle()\n",
" self.content = content\n",
" self.add(self.circle, content)\n",
" content.move_to(self.circle.get_center())\n",
"\n",
" def clear_content(self):\n",
" self.remove(self.content)\n",
" self.content = None\n",
"\n",
" @override_animate(clear_content)\n",
" def _clear_content_animation(self):\n",
" anim = Uncreate(self.content)\n",
" self.clear_content()\n",
" return anim\n",
"\n",
"class AnimationOverrideExample(Scene):\n",
" def construct(self):\n",
" t = Text(\"hello!\")\n",
" my_mobject = CircleWithContent(t)\n",
" self.play(ShowCreation(my_mobject))\n",
" self.play(my_mobject.animate.clear_content())\n",
" self.wait()"
]
},
{
"cell_type": "markdown",
"id": "brazilian-pavilion",
"metadata": {},
"source": [
"## [#939](https://github.com/ManimCommunity/manim/pull/939): Support for custom font files"
]
},
{
"cell_type": "markdown",
"id": "latin-found",
"metadata": {},
"source": [
"First, we download a suitable font:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fifteen-homework",
"metadata": {},
"outputs": [],
"source": [
"!wget https://github.com/google/fonts/raw/89ade4fa7b7663aec69d3202d2eefd928e78c467/ofl/orbitron/Orbitron%5Bwght%5D.ttf -O orbitron.ttf"
]
},
{
"cell_type": "markdown",
"id": "olive-moderator",
"metadata": {},
"source": [
"And now, the file can be used in manim:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "obvious-alexandria",
"metadata": {},
"outputs": [],
"source": [
"%%manim CustomFont -qm -p -v WARNING --disable_caching\n",
"\n",
"class CustomFont(Scene):\n",
" def construct(self):\n",
" with register_font(\"orbitron.ttf\"):\n",
" a = Text(\"Hello, this is Orbitron!\",font=\"Orbitron\")\n",
" self.play(Write(a))"
]
},
{
"cell_type": "markdown",
"id": "renewable-usage",
"metadata": {},
"source": [
"## [#892](https://github.com/ManimCommunity/manim/pull/892): Allow importing ManimCommunity Logo colors\n",
"\n",
"Now, you can import the colours used in our logo using the following import\n",
"```py\n",
"from manim.communitycolors import *\n",
"```\n"
]
},
{
"cell_type": "markdown",
"id": "incoming-trouble",
"metadata": {},
"source": [
"## [#742](https://github.com/ManimCommunity/manim/pull/742): Introduction of new and easier handling of Units: Pixels, Munits, Percent in `unit`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "compressed-baseball",
"metadata": {},
"outputs": [],
"source": [
"%%manim UnitDot -qm -v WARNING --disable_caching\n",
"\n",
"from manim import unit\n",
"\n",
"def make_dot(c):\n",
" return Dot(radius=0.2, color=c)\n",
"\n",
"class UnitDot(Scene):\n",
" def construct(self):\n",
" dot1 = make_dot(RED).shift(UP)\n",
" dot2 = make_dot(BLUE)\n",
" dot3 = make_dot(GREEN).shift(DOWN)\n",
" self.add(dot1, dot2, dot3)\n",
"\n",
" self.play(\n",
" dot1.animate.shift(3.55 * unit.Munits * RIGHT),\n",
" dot2.animate.shift(320 * unit.Pixels * RIGHT),\n",
" dot3.animate.shift(25 * unit.Percent(X_AXIS) * RIGHT)\n",
" )\n",
"\n",
" self.wait()"
]
},
{
"cell_type": "markdown",
"id": "vanilla-latin",
"metadata": {},
"source": [
"## [#916](https://github.com/ManimCommunity/manim/pull/916): Multi-column layout for partite graphs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "limiting-march",
"metadata": {},
"outputs": [],
"source": [
"%%manim MultiColumn -qm -v WARNING\n",
"\n",
"class MultiColumn(Scene):\n",
" def construct(self):\n",
" graph = Graph(vertices=[0, 1, 2, 3, 4, 5, 6, 7],\n",
" edges=[(0, 4), (0, 6), (1, 6), (2, 5), (3, 7)],\n",
" layout=\"partite\",\n",
" partitions=[[0, 1, 2, 3]])\n",
" self.play(ShowCreation(graph))\n",
" self.play(FadeOut(graph))\n",
"\n",
" # nodes not specified in any of the partitions will form their own partition\n",
" graph = Graph(vertices=[0, 1, 2, 3, 4, 5, 6, 7],\n",
" edges=[(0, 2), (0, 3), (3, 6), (1, 2), (5, 7)],\n",
" layout=\"partite\",\n",
" partitions=[[0, 1], [2, 3], [4, 5]])\n",
" self.play(ShowCreation(graph))\n",
" self.play(FadeOut(graph))\n",
"\n",
" layers = [[0], [1, 2, 3], [4, 5, 6, 7], [8, 9], [10]]\n",
" edges = []\n",
" for j in range(len(layers) - 1):\n",
" edges.extend([(a, b) for a in layers[j] for b in layers[j+1]])\n",
" graph = Graph(vertices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n",
" edges=edges,\n",
" layout=\"partite\",\n",
" layout_scale=4,\n",
" partitions=layers)\n",
" self.play(ShowCreation(graph))\n",
" self.play(FadeOut(graph))"
]
},
{
"cell_type": "markdown",
"id": "julian-loading",
"metadata": {},
"source": [
"## [#945](https://github.com/ManimCommunity/manim/pull/945): The [`Graph Mobject`](https://docs.manim.community/en/v0.3.0/reference/manim.mobject.graph.Graph.html#manim.mobject.graph.Graph) has a [`change_layout()`](https://docs.manim.community/en/v0.3.0/reference/manim.mobject.graph.Graph.html#manim.mobject.graph.Graph.change_layout) method now, and\n",
"## [#922](https://github.com/ManimCommunity/manim/pull/922): Tree layout for Graph mobject\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "liable-photography",
"metadata": {},
"outputs": [],
"source": [
"%%manim ChangeGraphLayout -qm -v WARNING\n",
"\n",
"class ChangeGraphLayout(Scene):\n",
" def construct(self):\n",
" G = Graph(\n",
" [1, 2, 3, 4, 5, 6, 7, 8],\n",
" [(1, 2), (2, 3), (3, 4), (4, 5), (1, 6), (6, 7), (6, 8)],\n",
" layout=\"tree\",\n",
" layout_scale=5,\n",
" root_vertex=1,\n",
" labels=True,\n",
" )\n",
" self.play(ShowCreation(G))\n",
" self.wait()\n",
" for root in range(2, 9):\n",
" self.play(G.animate.change_layout(\"tree\", layout_scale=5, root_vertex=root))\n",
" self.wait(0.5)\n",
"\n",
" for lt in [\"circular\", \"spring\", \"planar\", \"shell\", \"spiral\"]:\n",
" self.play(G.animate.change_layout(lt))\n",
" self.wait(0.5)\n",
"\n",
" self.play(G.animate.change_layout(\"tree\", layout_scale=5, root_vertex=1))\n",
" self.play(FadeOut(G))"
]
},
{
"cell_type": "markdown",
"id": "acute-error",
"metadata": {},
"source": [
"## [#893](https://github.com/ManimCommunity/manim/pull/893): Convenience method `from_networkx()` for creating a graph from a networkx graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "noted-jamaica",
"metadata": {},
"outputs": [],
"source": [
"%%manim ImportNetworkxGraph -qm -p -v WARNING --disable_caching\n",
"\n",
"import networkx as nx\n",
"\n",
"\n",
"nxgraph = nx.erdos_renyi_graph(14, 0.5)\n",
"\n",
"class ImportNetworkxGraph(Scene):\n",
" def construct(self):\n",
" G = Graph.from_networkx(nxgraph, layout=\"spring\", layout_scale=3.5)\n",
" self.play(ShowCreation(G))\n",
" self.play(*[G[v].animate.move_to(5*RIGHT*np.cos(ind/7 * PI) +\n",
" 3*UP*np.sin(ind/7 * PI))\n",
" for ind, v in enumerate(G.vertices)])\n",
" self.play(Uncreate(G))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "departmental-wallet",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment