{ "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": [ "# 17-sided polygon\n", "\n", "I used this video as a reference:\n", "\n", "" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "FRAME_HEIGHT = config.frame_height\n", "FRAME_WIDTH = config.frame_width\n", "\n", "class Polygon17Sides(Scene):\n", " def fade_out(self, *mobs, **kwargs):\n", " self.play(\n", " *map(FadeOut, mobs),\n", " **kwargs\n", " )\n", "\n", " def construct(self):\n", " geos = Geos(self)\n", " frame_y_radius = FRAME_HEIGHT/2\n", " frame_x_radius = FRAME_WIDTH/2\n", " \n", " ac = lambda color: {\n", " \"all_styles\": {\"color\": color},\n", " }\n", " geos.create_geos({\n", " \"lY\": geos.line(DOWN*frame_y_radius, UP*frame_y_radius),\n", " \"lX\": geos.line(LEFT*frame_x_radius, RIGHT*frame_x_radius),\n", " \"cO\": geos.circle(ORIGIN, 3.5, line_kwargs={\"color\": RED}),\n", " \"dO1\": geos.dot_from_method(lambda n: n(\"cO\").get_top()),\n", " \"lO1\": geos.common_chord_partial(\"dO1\", \"cO\", **ac(GREEN)),\n", " \"dO2\": geos.intersection_lines(\"lO1\", \"lY\"),\n", " \"lO2\": geos.line_bisection_two_points(\"dO2\", ORIGIN, **ac(GREEN)),\n", " \"dA\": geos.intersection_lines(\"lO2\", \"lY\"),\n", " \"dB\": geos.dot_from_method(lambda n: n(\"cO\").get_right()),\n", " \"lAB\": geos.segment(\"dA,dB\"),\n", " \"aO\": geos.arc_three_points(\"dB,dA,dO1\", 2.3, other_angle=True),\n", " \"dC\": geos.nearest_intersection_circle_line(\"aO\", \"lAB\", \"dB\"),\n", " \"dD\": geos.nearest_intersection_circle_line(\"aO\", \"lY\", ORIGIN),\n", " \"dE\": geos.farthest_angle_bisector(\"dC\", \"dD\", ORIGIN),\n", " \"lAE\": geos.line(\"dA\", \"dE\"),\n", " \"dF\": geos.nearest_intersection_circle_line(\"aO\", \"lAE\", ORIGIN),\n", " \"dG\": geos.farthest_angle_bisector(\"dF\", \"dD\", ORIGIN),\n", " \"lGA\": geos.line(\"dG\", \"dA\", overshot=2.5),\n", " # ----\n", " \"dH,dI\": geos.intersection_circle_line(\"aO\", \"lGA\"),\n", " \"dJ\": geos.farthest_angle_bisector(\"dH\", \"dI\", \"dO1\", **ac(BLUE)),\n", " \"lAJ\": geos.line(\"dA\", \"dJ\"),\n", " \"dK\": geos.nearest_intersection_circle_line(\"aO\", \"lAJ\", \"dJ\"),\n", " \"dL\": geos.farthest_angle_bisector(\"dK\", \"dI\", ORIGIN, **ac(BLUE)),\n", " \"lAL\": geos.line(\"dA\", \"dL\"),\n", " \"dM\": geos.intersection_lines(\"lX\", \"lGA\"),\n", " \"dN\": geos.intersection_lines(\"lX\", \"lAL\"),\n", " \"lBN\": geos.line_bisection_two_points(\"dB\", \"dN\", **ac(GREEN)),\n", " \"dP\": geos.intersection_lines(\"lX\", \"lBN\"),\n", " \"nPN\": geos.distance(\"dN\", \"dP\"),\n", " \"aP\": geos.arc(\"dP\", \"nPN\", PI, -60*DEGREES, **ac(BLUE)),\n", " \"dQ\": geos.nearest_intersection_circle_line(\"aP\", \"lY\", \"dA\"),\n", " \"nMQ\": geos.distance(\"dM\", \"dQ\"),\n", " \"aM\": geos.arc_three_points(\n", " \"dP,dM,dQ\", radius=\"nMQ\", overshot_ang=0, reverse_points=True,\n", " **ac(GREEN),\n", " ),\n", " \"dR\": geos.nearest_intersection_circle_line(\"aM\", \"lX\", \"dP\"),\n", " \"cR\": geos.circle(\"dR\", 0.8, **ac(GREEN)),\n", " \"dS,dT\": geos.intersection_circle_line(\"cR\", \"lX\"),\n", " \"dU\": geos.nearest_angle_bisector(\"dS\", \"dT\", \"dA\", **ac(BLUE)),\n", " \"lRU\": geos.line(\"dR\",\"dU\", overshot=2.3),\n", " \"dW\": geos.nearest_intersection_circle_line(\"cO\", \"lRU\", \"dU\"),\n", " \"lEND\": geos.line(\"dB\", \"dW\", color=RED),\n", " },\n", " )\n", "\n", " self.add(geos.lX, geos.lY)\n", " geos.auto_animation(\"cO\")\n", " geos.auto_animation(\"lO1\", remove_arc=False)\n", " geos.auto_animation(\"lO2\", remove_arcs=False)\n", " geos.auto_animation(\"lAB\")\n", " self.play(\n", " *map(FadeOut, [geos.lO1, geos.lO1.arc, geos.lO2, geos.lO2.arcs])\n", " )\n", " geos.auto_animation(\"aO\")\n", " geos.auto_animation(\"dE\", remove_arcs=False)\n", " geos.auto_animation(\"lAE\")\n", " geos.auto_animation(\"dG\", remove_arcs=False)\n", " geos.auto_animation(\"lGA\", show_dots=False)\n", " geos.auto_animation(\"dJ\", remove_arcs=False)\n", " self.fade_out(\n", " geos.dE.arcs, geos.dG.arcs, geos.lAE\n", " )\n", " geos.auto_animation(\"lAJ\")\n", " geos.auto_animation(\"dL\", remove_arcs=False)\n", " geos.auto_animation(\"lAL\")\n", " self.fade_out(\n", " geos.dL.arcs, geos.lAJ,\n", " geos.dJ.arcs, geos.aO, geos.lAB\n", " )\n", " geos.auto_animation(\"lBN\", remove_arcs=False)\n", " geos.auto_animation(\"aP\")\n", " self.fade_out(\n", " geos.lBN.arcs, geos.lBN\n", " )\n", " geos.auto_animation(\"aM\")\n", " geos.auto_animation(\"cR\")\n", " geos.auto_animation(\"dU\", remove_arcs=False)\n", " geos.auto_animation(\"lRU\", show_dots=False)\n", " geos.auto_animation(\"lEND\")\n", "\n", " self.fade_out(\n", " geos.lGA, geos.lAL, geos.aP, geos.aM,\n", " geos.lRU, geos.dU.arcs, geos.cR\n", " )\n", "\n", " rotate_line = geos.lEND\n", " main_circle = geos.cO\n", " pol17 = RegularPolygon(\n", " 17,\n", " radius=geos.cO.radius,\n", " start_angle=0,\n", " color=YELLOW,\n", " stroke_width=2\n", " ).move_to(geos.cO)\n", "\n", " arcs = VGroup()\n", "\n", " for _ in range(17):\n", " tmp_circle = ICircle(rotate_line.get_length()).move_to(rotate_line.get_end())\n", " arc = tmp_circle.common_chord_group_partial(main_circle, only_arc=True)\n", " arc.reverse_points()\n", " arc.set_stroke(width=3)\n", "\n", " arcs.add(arc)\n", "\n", " self.play(\n", " Rotate(rotate_line, -arc.angle, about_point=rotate_line.get_end()),\n", " Create(arc),\n", " )\n", " rotate_line.reverse_points()\n", "\n", " self.play(FadeOut(rotate_line))\n", "\n", " self.play(Create(pol17))\n", " self.wait()\n", " self.fade_out(main_circle, arcs, geos.lX, geos.lY)\n", "\n", " pol17_labels = RegularPolygon(\n", " 17, radius=geos.cO.radius*0.9,\n", " start_angle=0\n", " )\n", " pol17_labels_anchors = pol17_labels.get_anchors()\n", " labels = VGroup(*[\n", " MathTex(str(i+1)).scale(0.5).move_to(pol17_labels_anchors[i*2])\n", " for i in range(17)\n", " ])\n", "\n", " self.play(LaggedStartMap(FadeIn, labels))\n", " self.wait(4)\n", "\n", "%manim $_RV Polygon17Sides" ] }, { "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 }