#!/usr/bin/env python # coding: utf-8 # **Note:** This is a temporary test environment in which you can play around with Manim without the need of installing it locally. Keep in mind that this is a *temporary* environment, though: your changes will not be saved and cannot be shared with others. To save your work, you will need to download the notebook file ("File > Download as > Notebook (.ipynb)"). Enjoy! # # *Useful resources:* [Documentation](https://docs.manim.community), [Discord](https://discord.gg/mMRrZQW), [Reddit](https://www.reddit.com/r/manim/) # In[ ]: from manim import * # In[ ]: get_ipython().run_line_magic('manim', '--help') # In[ ]: get_ipython().run_cell_magic('manim', '-qm -v WARNING SquareToCircle', '\nclass 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(Create(square))\n self.play(Transform(square, circle))\n self.play(FadeOut(square))\n') # In[ ]: get_ipython().run_cell_magic('manim', '-qm -v WARNING WarpSquare', '\nclass WarpSquare(Scene):\n def construct(self):\n square = Square()\n self.play(\n ApplyPointwiseFunction(\n lambda point: complex_to_R3(np.exp(R3_to_complex(point))), square\n )\n )\n self.wait()\n') # In[ ]: get_ipython().run_cell_magic('manim', '-qm -v WARNING WriteStuff', '\nclass WriteStuff(Scene):\n def construct(self):\n example_text = Tex("This is some text", tex_to_color_map={"text": YELLOW})\n example_tex = MathTex(\n "\\\\sum_{k=1}^\\\\infty {1 \\\\over k^2} = {\\\\pi^2 \\\\over 6}",\n )\n group = VGroup(example_text, example_tex)\n group.arrange(DOWN)\n group.set(width=config["frame_width"] - 2 * LARGE_BUFF)\n\n self.play(Write(example_text))\n self.play(Write(example_tex))\n self.wait()\n') # In[ ]: get_ipython().run_cell_magic('manim', '-qm -v WARNING UpdatersExample', '\nclass UpdatersExample(Scene):\n def construct(self):\n decimal = DecimalNumber(\n 0,\n show_ellipsis=True,\n num_decimal_places=3,\n include_sign=True,\n )\n square = Square().to_edge(UP)\n\n decimal.add_updater(lambda d: d.next_to(square, RIGHT))\n decimal.add_updater(lambda d: d.set_value(square.get_center()[1]))\n self.add(square, decimal)\n self.play(\n square.animate.to_edge(DOWN),\n rate_func=there_and_back,\n run_time=5,\n )\n self.wait()\n') # In[ ]: get_ipython().run_cell_magic('manim', '-qm -v WARNING OpeningManim', '\nclass OpeningManim(Scene):\n def construct(self):\n title = Tex(r"This is some \\LaTeX")\n basel = MathTex(r"\\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{\\pi^2}{6}")\n VGroup(title, basel).arrange(DOWN)\n self.play(\n Write(title),\n FadeIn(basel, shift = UP),\n )\n self.wait()\n\n transform_title = Tex("That was a transform")\n transform_title.to_corner(UP + LEFT)\n self.play(\n Transform(title, transform_title),\n LaggedStart(*[FadeOut(obj, shift=DOWN) for obj in basel]),\n )\n self.wait()\n\n grid = NumberPlane(x_range=(- 10, 10, 1), y_range=(- 6.0, 6.0, 1))\n grid_title = Tex("This is a grid")\n grid_title.scale(1.5)\n grid_title.move_to(transform_title)\n\n self.add(grid, grid_title) # Make sure title is on top of grid\n self.play(\n FadeOut(title),\n FadeIn(grid_title, shift=DOWN),\n Create(grid, run_time=3, lag_ratio=0.1),\n )\n self.wait()\n\n grid_transform_title = Tex(\n r"That was a non-linear function \\\\ applied to the grid"\n )\n grid_transform_title.move_to(grid_title, UL)\n grid.prepare_for_nonlinear_transform()\n self.play(\n grid.animate.apply_function(\n lambda p: p\n + np.array(\n [\n np.sin(p[1]),\n np.sin(p[0]),\n 0,\n ]\n )\n ),\n run_time=3,\n )\n self.wait()\n self.play(Transform(grid_title, grid_transform_title))\n self.wait()\n') # See many more examples at https://docs.manim.community/en/latest/examples.html!