Skip to content

Instantly share code, notes, and snippets.

@behackl
Last active December 6, 2021 13:06
Show Gist options
  • Save behackl/99bd625701cfa86d08bde8c2d9c6def2 to your computer and use it in GitHub Desktop.
Save behackl/99bd625701cfa86d08bde8c2d9c6def2 to your computer and use it in GitHub Desktop.
FROM manimcommunity/manim:v0.13.1
COPY --chown=manimuser:manimuser . /manim
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "meaningful-korean",
"metadata": {},
"source": [
"## Mathematical Animations WITH EASE | Ep. 02: Positioning and Configuration\n",
"\n",
"This notebook contains the examples discussed in [this video](). 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": "vulnerable-hearts",
"metadata": {},
"outputs": [],
"source": [
"from manim import *"
]
},
{
"cell_type": "markdown",
"id": "forced-crime",
"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": "personal-mobile",
"metadata": {},
"outputs": [],
"source": [
"config.media_width = \"80%\"\n",
"config.verbosity = \"WARNING\""
]
},
{
"cell_type": "markdown",
"id": "closed-mixer",
"metadata": {},
"source": [
"### Part 1: Positioning and Alignment"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "industrial-dinner",
"metadata": {},
"outputs": [],
"source": [
"%%manim -qm Positioning\n",
"\n",
"class Positioning(Scene):\n",
" def construct(self):\n",
" plane = NumberPlane()\n",
" self.add(plane)\n",
"\n",
" # next_to from episode 1\n",
" red_dot = Dot(color=RED)\n",
" green_dot = Dot(color=GREEN)\n",
" green_dot.next_to(red_dot, RIGHT + UP) # RIGHT == [1, 0, 0]\n",
" self.add(red_dot, green_dot)\n",
"\n",
" # shift\n",
" s = Square(color=ORANGE)\n",
" s.shift(2*UP + 4*RIGHT)\n",
" self.add(s)\n",
"\n",
" # move_to\n",
" c = Circle(color=PURPLE)\n",
" c.move_to([-3, -2, 0])\n",
" self.add(c)\n",
"\n",
" # align_to\n",
" c2 = Circle(radius=0.5, color=RED, fill_opacity=0.5)\n",
" c3 = c2.copy().set_color(YELLOW)\n",
" c4 = c2.copy().set_color(ORANGE)\n",
" c2.align_to(s, UP)\n",
" c3.align_to(s, RIGHT)\n",
" c4.align_to(s, UP + RIGHT)\n",
" self.add(c2, c3, c4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "baking-edwards",
"metadata": {},
"outputs": [],
"source": [
"%%manim -qm CriticalPoints\n",
"\n",
"class CriticalPoints(Scene):\n",
" def construct(self):\n",
" c = Circle(color=GREEN, fill_opacity=0.5)\n",
" self.add(c)\n",
"\n",
" for d in [(0,0,0), UP, UR, RIGHT, DR, DOWN, DL, LEFT, UL]:\n",
" self.add(Cross(scale_factor=0.2).move_to(c.get_critical_point(d)))\n",
"\n",
" s = Square(color=RED, fill_opacity=0.5)\n",
" s.move_to([1,0,0], aligned_edge=LEFT)\n",
" self.add(s)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "directed-mongolia",
"metadata": {},
"outputs": [],
"source": [
"%%manim -qm UsefulUnits\n",
"\n",
"from manim.utils.unit import Percent, Pixels\n",
"\n",
"class UsefulUnits(Scene):\n",
" def construct(self):\n",
" for perc in range(5, 51, 5):\n",
" self.add(Circle(radius=perc * Percent(X_AXIS)))\n",
" self.add(Square(side_length=2*perc*Percent(Y_AXIS), color=YELLOW))\n",
"\n",
" d = Dot()\n",
" d.shift(100 * Pixels * RIGHT)\n",
" self.add(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "metallic-jamaica",
"metadata": {},
"outputs": [],
"source": [
"%%manim -qm Grouping\n",
"\n",
"class Grouping(Scene):\n",
" def construct(self):\n",
" red_dot = Dot(color=RED)\n",
" green_dot = Dot(color=GREEN).next_to(red_dot, RIGHT)\n",
" blue_dot = Dot(color=BLUE).next_to(red_dot, UP)\n",
" dot_group = VGroup(red_dot, green_dot, blue_dot)\n",
" dot_group.to_edge(RIGHT)\n",
" self.add(dot_group)\n",
"\n",
" circles = VGroup(*[Circle(radius=0.2) for _ in range(10)])\n",
" circles.arrange(UP, buff=0.5)\n",
" self.add(circles)\n",
"\n",
" stars = VGroup(*[Star(color=YELLOW, fill_opacity=1).scale(0.5) for _ in range(20)])\n",
" stars.arrange_in_grid(4, 5, buff=0.2)\n",
" self.add(stars)"
]
},
{
"cell_type": "markdown",
"id": "afraid-modem",
"metadata": {},
"source": [
"### Part 2: Configuration and Default Settings"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "downtown-tomorrow",
"metadata": {},
"outputs": [],
"source": [
"%%manim SimpleScene\n",
"\n",
"config.background_color = WHITE\n",
"config.frame_width = 9\n",
"config.frame_height = 16\n",
"\n",
"config.pixel_width = 1080\n",
"config.pixel_height = 1920\n",
"\n",
"class SimpleScene(Scene):\n",
" def construct(self):\n",
" plane = NumberPlane(x_range=(-4.5, 4.5), y_range=(-8, 8))\n",
" t = Triangle(color=PURPLE, fill_opacity=0.5)\n",
" self.add(plane, t)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "indie-council",
"metadata": {},
"outputs": [],
"source": [
"%%manim -qm ChangedDefaults\n",
"\n",
"config.background_color = BLACK\n",
"\n",
"class ChangedDefaults(Scene):\n",
" def construct(self):\n",
" Text.set_default(color=GREEN, font_size=100)\n",
" t = Text(\"Hello World!\")\n",
"\n",
" Text.set_default() # reset previously changed default values\n",
" t2 = Text(\"Goodbye!\").next_to(t, DOWN)\n",
" self.add(t, t2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "lovely-museum",
"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