{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Manim Community v0.18.0\n",
       "\n",
       "
\n" ], "text/plain": [ "Manim Community \u001b[32mv0.\u001b[0m\u001b[32m18.0\u001b[0m\n", "\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from manim import *\n", "from manim_geometry import *\n", "\n", "config.media_embed = True\n", "config.media_width = \"100%\"\n", "_RV = \"-v WARNING -qm --progress_bar None --disable_caching\"\n", "_RI = \"-v WARNING -s --progress_bar None --disable_caching\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Auto-animations\n", "\n", "While you can access all objects as an attribute of \"Geos\", each construction has a default animation, for this you can use the `auto_animation` method. This method receives the following parameters:\n", "\n", "1. `all_styles` [dict]: Here the styles of the auxiliary objects are defined.\n", "2. `anim_kwargs` [dict]: Here the typical kwargs of the animations are defined, `run_time`, etc., I do not recommend modifying any other option besides `run_time`.\n", "3. `show_dot/show_dots` [Bool]: Shows the auxiliary point or points.\n", "4. `remove_arc/remove_arcs` [Bool]: Removes the auxiliary arcs.\n", "5. `**kwargs`: Here you can define the styles of the object being animated.\n", "\n", "## Dots" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Example(Scene):\n", " def construct(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"d1,d2\": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),\n", " })\n", " geos.auto_animation(\"d1\")\n", " geos.auto_animation(\"d2\", anim_kwargs={\"run_time\":5})\n", " self.wait()\n", "\n", "%manim $_RV Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Lines" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Example(Scene):\n", " def construct(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"l1\": Line(LEFT, RIGHT).shift(UP),\n", " \"l2\": Line(LEFT*2, RIGHT*2),\n", " \"l3\": Line(LEFT*3, RIGHT*3).shift(DOWN),\n", " \"l4\": Line(LEFT*4, RIGHT*4).shift(DOWN*2),\n", " })\n", " geos.auto_animation(\"l1\")\n", " geos.auto_animation(\"l2\", dot_kwargs={\"radius\": 0.2, \"color\": RED})\n", " geos.auto_animation(\"l3\", show_dots=False, color=BLUE)\n", " geos.auto_animation(\"l4\", anim_kwargs={\"run_time\":3})\n", "%manim $_RV Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Circles" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Example(Scene):\n", " def construct(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"c1\": geos.circle(ORIGIN, 1),\n", " \"c2\": geos.circle(ORIGIN, 2),\n", " })\n", "\n", " geos.auto_animation(\"c1\")\n", " geos.auto_animation(\"c2\",\n", " all_styles={\"color\": YELLOW},\n", " color=BLUE,\n", " anim_kwargs={\"run_time\": 3})\n", " self.wait()\n", "\n", "%manim $_RV Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. warning::\n", " In case you need to animate step by step you can use the following method. I don't recommend it but it's there, you can read the source code of `manim_geometry/geos.py` which is where this is defined, I've tried hard to make it easy to understand but the library is not designed for you to modify this." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Example(Scene):\n", " def construct(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"c1\": geos.circle(ORIGIN, 1),\n", " })\n", "\n", " geos.prepare_animation(\"c1\")\n", " self.play(geos.c1._prepared_anim.get_step(0)) # Show dot\n", " self.play(geos.c1._prepared_anim.get_step(1), run_time=4) # Draw line\n", " self.play(geos.c1._prepared_anim.get_step(2)) # Rotate line drawing circle\n", " self.play(geos.c1._prepared_anim.get_step(3)) # Remove line and dot\n", " # Check geos.py to see all the steps\n", "\n", " self.wait()\n", "\n", "%manim $_RV Example" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Example(Scene):\n", " def construct(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"c1\": geos.circle(ORIGIN, 1, start_angle=-PI/2),\n", " \"c2\": geos.circle(ORIGIN, 2, start_angle=-PI),\n", " })\n", "\n", " geos.auto_animation(\"c1\")\n", " geos.auto_animation(\"c2\", reverse=True)\n", "\n", " self.wait()\n", "\n", "%manim $_RV Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Multiple FadeIn" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Example(Scene):\n", " def construct(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"l1\": Line(LEFT, RIGHT).shift(UP),\n", " \"l2\": Line(LEFT*2, RIGHT*2),\n", " \"l3\": Line(LEFT*3, RIGHT*3).shift(DOWN),\n", " \"d1,d2\": geos.dots_at_start_end_line(\"l1\")\n", " })\n", " geos.fade_in_multiple(\"d1,d2\")\n", " geos.fade_in_multiple(\"l1,l2,l3\", scale=0.5)\n", " self.wait()\n", "\n", "%manim $_RV Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## FadeIn Dot and Label" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class FadeInDotAndLabel(Scene):\n", " def construct(self):\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"d1,d2,d3\": GeosVGroup(\n", " Dot(LEFT), Dot(ORIGIN), Dot(RIGHT)\n", " ).scale(3).rotate(30*DEGREES)\n", " },\n", " set_all_labels=True\n", " )\n", " geos.show_dot_and_label(\"d1\")\n", " geos.show_dot_and_label(\"d2,d3\")\n", "\n", " self.wait()\n", "\n", "%manim $_RV FadeInDotAndLabel" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Line bisector" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class LineBisector1(Scene):\n", " def setup(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"d1,d2\": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),\n", " \"b1\": geos.line_bisection_two_points(\"d1,d2\", color=GREEN),\n", " \"c1\": geos.circle(\"d1\", 2),\n", " \"c2\": geos.circle(\"d2\", 2),\n", " })\n", " self.geos = geos\n", "\n", " def construct(self):\n", " self.geos.auto_animation(\"b1\")\n", " self.wait()\n", "\n", "%manim $_RV LineBisector1" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class LineBisector2(LineBisector1):\n", " def construct(self):\n", " self.geos.auto_animation(\n", " \"b1\",\n", " arc_kwargs={\"color\": RED},\n", " line_kwargs={\"color\": YELLOW},\n", " dot_kwargs={\"color\": PURPLE},\n", " )\n", " self.wait()\n", "\n", "%manim $_RV LineBisector2" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class LineBisector3(LineBisector1):\n", " def construct(self):\n", " self.geos.auto_animation(\"b1\", all_styles={\"color\": YELLOW}, color=PINK)\n", " self.wait()\n", "\n", "%manim $_RV LineBisector3" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class LineBisector4(Scene):\n", " def setup(self):\n", " self.add(NumberPlane().fade(0.7))\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"d1,d2\": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),\n", " \"b1\": geos.line_bisection_two_points(\"d1,d2\", all_styles={\"color\": PINK}),\n", " \"c1\": geos.circle(\"d1\", 2),\n", " \"c2\": geos.circle(\"d2\", 2),\n", " })\n", " geos.auto_animation(\"b1\")\n", "\n", "%manim $_RV LineBisector4" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class LineBisector5(LineBisector1):\n", " def construct(self):\n", " self.geos.auto_animation(\"b1\", show_dots=False)\n", " self.wait()\n", "\n", "%manim $_RV LineBisector5" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class LineBisector5(LineBisector1):\n", " def construct(self):\n", " geos = self.geos\n", " geos.auto_animation(\"b1\", remove_arcs=False, dot_kwargs={\"radius\": 0.2, \"color\": RED})\n", " self.play(geos.b1.arcs.animate.set_color(RED))\n", " self.play(geos.b1.animate.set_color(YELLOW))\n", " self.play(FadeOut(geos.b1.arcs))\n", " self.wait()\n", "\n", "%manim $_RV LineBisector5" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class LineBisector5(LineBisector1):\n", " def construct(self):\n", " geos = self.geos\n", " geos.auto_animation(\"b1\", remove_arcs=False, show_line=False)\n", " self.play(geos.b1.arcs.animate.set_color(RED))\n", " self.play(Create(geos.b1))\n", " self.play(FadeOut(geos.b1.arcs))\n", " self.wait()\n", "\n", "%manim $_RV LineBisector5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Common chord" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class CommonChord1(Scene):\n", " def setup(self):\n", " self.add(NumberPlane().fade(0.7))\n", "\n", " geos = Geos(self)\n", " init_geos = {\n", " \"d1,d2\": GeosVGroup(Dot(LEFT), Dot(RIGHT*4)).rotate(30*DEGREES),\n", " \"c1\": geos.circle(\"d1\", 2),\n", " \"b12\": geos.common_chord_partial(\"d2,c1\", color=YELLOW),\n", " }\n", " geos.create_geos(init_geos)\n", " self.geos = geos\n", " \n", " def construct(self):\n", " self.add(self.geos.d1, self.geos.c1)\n", " self.geos.auto_animation(\"b12\")\n", "\n", "%manim $_RV CommonChord1" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class CommonChord2(CommonChord1):\n", " def construct(self):\n", " self.add(self.geos.d1, self.geos.c1)\n", " geos = self.geos\n", " geos.auto_animation(\n", " \"b12\",\n", " all_styles={\"color\": PINK},\n", " dot_kwargs={\"radius\": 0.2},\n", " remove_arc=False,\n", " show_line=False,\n", " color=BLUE\n", " )\n", " self.play(geos.b12.arc.animate.set_color(YELLOW))\n", " self.play(Create(geos.b12))\n", " self.play(FadeOut(geos.b12.arc))\n", " self.wait()\n", "\n", "%manim $_RV CommonChord2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Nearest/Farthest angle bisector" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Example(Scene):\n", " def construct(self):\n", " self.add(NumberPlane().fade(0.7))\n", "\n", " geos = Geos(self)\n", " geos.create_geos({\n", " \"d1,d2\": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),\n", " \"dU\": Dot(UP),\n", " \"iI_1\": geos.nearest_angle_bisector(\"d1\", \"d2\", \"dU\", color=ORANGE),\n", " \"iI_2\": geos.farthest_angle_bisector(\"d1,d2,dU\", color=GREEN),\n", " \"iI_3\": geos.farthest_angle_bisector(\"d1,dU,d2\", color=BLUE),\n", " \"c1\": geos.circle(\"d1\", 2, z_index=-1),\n", " \"c2\": geos.circle(\"d2\", 2, z_index=-1),\n", " },\n", " set_all_labels=True\n", " )\n", "\n", " self.add(geos.get_all_dots(), geos.get_all_circles(), geos.get_all_labels())\n", "\n", " geos.auto_animation(\"iI_1\")\n", " geos.auto_animation(\"iI_2\",\n", " remove_arcs=False,\n", " add_dot=True,\n", " all_styles={\"color\": PINK},\n", " dot_kwargs={\"radius\": 0.1}\n", " )\n", " self.play(geos.iI_2.arcs.animate.shift(DOWN))\n", " self.play(FadeOut(geos.iI_2.arcs))\n", " geos.auto_animation(\"iI_3\", show_dots=False, add_dot=True)\n", "\n", " self.wait()\n", "\n", "%manim $_RV Example" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "venv", "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.12.1" } }, "nbformat": 4, "nbformat_minor": 2 }