Create Math Animations Like 3Blue1Brown using Manim | Kyle B. | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Create Math Animations Like 3Blue1Brown using Manim

teacher avatar Kyle B., Ph.D. student in pure mathematics

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

10 Lessons (31m)
    • 1. Introduction to Manim

      1:07
    • 2. Project

      0:28
    • 3. Installing Manim

      0:33
    • 4. Basics with Text

      4:11
    • 5. Transforming Text

      3:45
    • 6. Inserting Graphs

      4:00
    • 7. Inserting Vertical Lines

      4:11
    • 8. Labeling

      3:11
    • 9. Shading Regions

      3:19
    • 10. Polishing off the animations

      5:52
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

190

Students

--

Projects

About This Class

We will make a 30 second math animation tutorial on logarithms using manim, the program created by Grant Sanderson from 3Blue1Brown. We will cover working with text, equations, positioning, position transforming, and graphing.

Some knowledge of python programming would be nice to have, but is not necessary. LaTeX is essential, but LaTeX is very easy to learn. 

This is an example-based introduction to manim, avoiding any complicated theory that goes into the computer science of manim. 

Manim works on windows, mac and Linux, I’ll be using the Mac version in this tutorial. 

Meet Your Teacher

Teacher Profile Image

Kyle B.

Ph.D. student in pure mathematics

Teacher

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction to Manim: Hi everyone, welcome to a very quick introduction to man im, the math animation program created by Grant Sanderson, the genius behind three blue one brown. My name is Kyle and I am a PhD student in complex differential geometry at Beijing University and the Australian National University. I have my own math channel covers mathematical topics using madam. And the purpose of this quick introduction is to not worry about any of the computer science behind the programming, just to get your where as quickly as possible and getting you producing these animations without worrying about object oriented programming or any of that. So in this series, we will learn how to animate colored text and equations in Madam will show transformations in Madam. So fading in and fading out, moving things around, converting one thing into another. And we'll graph and shade regions in magnum. So the way we're going to learn this is by working on a single video on a certain way of realizing Euler's number as the integral under the curve of our hyperbola. That video is available in the next installment. 2. Project: No. 3. Installing Manim: So the first thing we want to do if we're going to use man m, is to install man M&M is going to require a few packages. All of this is laid out very coherently on the man im community page, which can be found by typing in docs dot.com and then clicking the first result. And this is the page we'll end up with. 4. Basics with Text: The first thing we're gonna do to get started with madame is just the set out some text. Open up your text editor. I use Sublime. I'm going to start every document with from math import star. And now I want to save this text file as a Python file. So I'll save it, make a sub folder of my anim folder. I'll call it Skill Share, and then I'll call this file example 1.01y. In Sublime, the color changes indicating that it knows that we're running a Python file. I'll also import numpy as np, just saving throughout, we're going to be inserting a graph later on. But for the moment we only are going to worry about texts. So the class that I'm gonna work with is just going to be a normal scene. Example one then seen in brackets. So this just tells me that I'm in a, in a normal scene. I will have def, construct self. And this is going to be the starting format. These first four lines of text pretty much going to be the same every time. The only thing we made changes, obviously the name of the same. So the name of the scene here is example one. And where there is a scene or a graph seen, since we're only worrying about text for the moment, I'll just leave it as a scene. And now we want to insert some text. So I'm going to use a variable name I like T1. I'm only going to worry about normal text, so I'm going to write t e x, and then I'm going to use quotation marks. Insert some text. This is just going to insert some text. It's actually not gonna do anything yet. What I need to do is to self.age play and then write t1. So I need to actually animate the text, and that's going to be done by this command here. Now open up the terminal, go to the directory. So type in C, d, and then minds in documents, then magnesium, then Skill Share. Now to actually animate the program itself, what I need to do is type in the name of the file, which is example 1.01y. I wanna do dash p and then dash q l, which will give me a low quality animation. If I wanted a high-quality animation, I could do. We do QL until we're happy with the product and then we'll do Q H because the higher-quality animation takes a longer time. So just press enter after that, and we see that we get an animation saying, insert some text in the project that we're working on. The introduction says, Here is another way of discovering Euler's number. So let's write that over here is a way of realizing Euler's number. And so what I'll do is open up the terminal again and then I can just hit up and enter. If this did not work, it didn't change. You didn't save the edit. Make sure you save. This is white text. It looks a bit boring, so I'm gonna change the color after the quotation marks. I'm going to have a comma and then color equals, and I like gold underscore V. And so if I save this now it up on the terminal and then hit Enter, The text is now in gold, but I don't want it in the middle. What I wanted to do is actually go to the top. So what I'm gonna do is outside of the brackets that the text is contained in. And we're going to have to corner. And then I'm just gonna type in up and then save by hit Run. Now, then we see that it's moved to the top of the screen just to show you what it's like with a high-quality animation, let's do the same, but we'll do Q. And there we go. It looks, looks very nice. Just to finish off this first lesson, we could move this around. We could move it into the bottom of the screen and that puts it down here. We could move it to other corners. For example, if I wanted it in the upper left, I could do UL. And similarly, if I wanted it in the upper right, I could do u, r. If I wanted to do it in the bottom left, I could do DL. And if I wanted to in the bottom right, I could do D. But we just want it to be up to the top for the moment. And that'll be the end of this first installment. 5. Transforming Text: So what we now want to do is insert some more text into our madam file and position it appropriately so nothing's overlapping and introduce some more colors that we can work with. So the next line in the video said, consider the graph of the function which was the hyperbola. Let's insert another line. I'll have tech, consider the graph of the function, and let's use blue this time. I don't want to put it in the upper corner because that will now overlap with the original texts that we have here that T1, though, what I wanna do is just shifted up and I'm going to shift it up by about 2.5. That seems to be a good number to get at just under the line. Now let's do self dot play, right? T2, again, making sure you're saving at every step it up in a terminal. And let's just run a low-quality animation. Okay, so that looks pretty good since we want to have more text to the right, what I'll actually do is shift this blue text to the left a little more. So I'll do plus left. And that will just transformative in the way that we want, hopefully. Okay, so that did shifted to the left, but maybe I wanted to shift a little more. So what I'll do is I'll to be two times left. And there we go. That's in a good spot. And now I want to actually do some math, so insert some math equations. And so what I'm gonna do is introduce a new variable, T3. And instead of just tick, I'm going to have mass tech and then I'm going to have f from to. And because I'm actually going to define a hyperbola, I want R plus. So let's just do that for the moment. I'll do color red. And I want to actually have T3 be right next to T2, but on the right. So I'm gonna do next, underscore two, T2, right? And then self.age playwright T3, saving here. Now, these back slashes are highlighted because what I want to have before these quotation marks is an r which just makes LA tech work more efficiently here, run in the terminal. And that works. Now it's still a bit cramped on this right hand side. So what I'll do is I'll actually move this blue texts entirely to the corner. And the way I'm gonna do that is to just delete this left altogether. And then just underneath and I hit Enter, then do t2, T2 corner, left and that's just going to shift it right to the left corner. And that's because I want to have more equations here. I'll put a backslash just to give me a bit of space and our ride back of one over x. And then if I hit run, and there we go. So we have all the equations and functions written out. We've made the texts different colors, and we've also arranged them in a way that's not overlapping and also visually appealing. In the next video, we'll actually insert a graph of the hyperbola, and then in subsequent videos will shade the region under the curve and animate things accordingly. So I hope to see you guys there. Ok. 6. Inserting Graphs: So what we now wanna do is actually insert a graph of the hyperbola. And the way we're gonna do that is instead of working in a scene, we'll change our scene, two graphs scenes. So there's a capital G here. I'm going to insert an axes, actually wanna animate the axes. I think that'll look nice. So I'm going to do self.name setup axes and then animate equals true. Let's hit run on that. Okay, so that sets up the axes that are gray by default with a bunch of optics, the X and Y axes are already labeled o. We can see some clear issues. We can see that the axis origin is anywhere that we may want it. We want to be able to maybe shift that around and it's clearly overlapping with the text, so we need to deal with that. And the way to do that is actually using something called a config dictionary. I'm not going to bother explaining what that is, but that's just where you input all the commands telling the graph what to do, where we're going to insert the config dictionary is between class and DEF. So we're going to write config and then some curly brackets. Now I am going to have the x min value of the axes at minus1. Since I only care about the hyperbola, I'm going to have the x max to be six. I'm going to have the Y mean to also be minus1 and the y max to be three. Now if we do that, lets it run. And we see that the axes has been shortened. So we have three ticks up and six ticks along. So it's still in the wrong position. And of course there's no graph there yet. That's what we can edit using the config dictionary. So I also don't like the color of the axes. I'm going to change that to gold. So I'm gonna do axes color and then gold v. And let's see what that does. So we see that the axis is now a gold color. What I also want to do is move the graph origin to a better position. After doing some fiddling. I've found that probably the best place to move it is four to the left, 3.1 times down. And this is one of the disadvantages of Man him at least to my knowledge of it, is that it is a little fiddly with positioning. So if we hit run again, then there's no overlap this time with the text and the, the graph. So let's actually insert a graph of the hyperbola now. And the way we're gonna do that is to ride self.age get graphs. So we'll actually call this maybe hyperbola. And we're gonna use a lambda function. So I'm just gonna write a lambda x and then a colon. And we'll write that as one over x. The x min value that I'm going to take is going to be zero-point 3.3.3. And the Zmax value I'll take is going to be six. If I want to color the graph, I can just do as we usually do and write color, orange color. And then I'll do self dot play and instead of write, I'll write show creation, hyperbola. And so after saving all that, let's do a low-quality animation here. And now we have a nice hyperbola graph with no overlaps. So that's it for this installment. In the next one, we're gonna look at inserting some labels on the axes and actually animating some areas under the curve. I hope to see you guys there. 7. Inserting Vertical Lines: Okay, so now that we have a graph of the hyperbola, but we wanna do is introduce that definition of the logarithm as the integral from one to x of one over t d t. So we need T4 is math tech again because it's a mathematical formula. And I'm going to have text define a function. So this is just even though we're in a math environment, we're going to insert some text just for convenience and then define f of x or maybe apply best to call it f of t is the integral from one to t of one over x dx. And I'll make this green. Now again, I'm getting these backslash warnings from Sublime. And that's because I did not insert the R before the quotation marks. And I want to have this to the right corner. So I'm gonna go to corner and then right, so from here I'm going to write self dot, write T4, save, and that's hit run. So just scrolling through to speed up the animation. And then we have this definition here. So it's all now in the original animation, what I did, I actually got rid of the original text. The here is a way of realizing Euler's number and transformed that into T4. And the way to do that is actually very simple. Instead of write T4, I'm going to have transform T1 to t4. And so if I now hit run. And so the heading transforms into this text here, which makes it less cumbersome to look at and simplifies the overall picture. Okay, so let's now insert some vertical lines to indicate the area under the curve that we want to bound between. So to insert some vertical lines from the x-axis to the graph, I'm gonna type in V1 is self.age get vertical line to graph. The inputs of this are going to be the x value. So I want to have a vertical line from one up to the hyperbola graph. And maybe I want that to be a red color. I'll do self dot play, show creation V1 and hit Run. Again, just scrolling through for convenience. And then we have the vertical line inserted, so I'll just scroll back. And so the vertical line appears at the same time. So let's also insert a second vertical line. So let's say v2 is self.age, get vertical line. Two graphs already Sublime has learned and will do to hyperbola color red. And let's say I wanted to actually have them show up at the same time. Then I could also do show creation v2 here. So I'll do them in the same self dot play section. But I need to do it after the variables have been defined. I need to put it after the v2. If I now hit Run. That's it for this installment. In the next one, we'll look at how to actually get this area between the curve to be shaded and varying certain values of the T parameter. I hope to see you there. 8. Labeling : So the next thing we wanna do is insert labels under the second vertical line under the V2 and vary the V2 for different values of this first input parameter, just indicating the fact that the upper bound on this integral, this t here, is the variable that we're looking at and also shaded this region. So the way we're going to do that is by defining a v2 label. And that's just going to be a tech or Michelle make it a math tech. T equals to two because that's really the parameter name. I'll put an R there since we are using math. We'll color it like I usually do with gold B. And to make sure that it actually appears under v2, I'm gonna put next to V2 and down because I want to have it under the vertical line. And just so that it comes along, whenever V2 is along, I'm going to do v2 dot add and then v2 underscore label. And that's now going to pair it as one single object, save it and hit run. Notice I haven't shown creation of V2 label. It's already contained in V2. And if we scroll through here to the end of our animation, and it appears automatically. Now I'd like to shade the region bounded between these two vertical lines. And the way I'm gonna do that is as follows. So I'll define a new variable a1 as self.age area. And I want the area bounded between the hyperbola and the x axis between 12. The opacity of this shading is determined by the number of rectangles that you use in the Riemann integration. So the dx scaling I want to be so to color the area bound between the two vertical lines, we're going to define a new variable, a2 as self.age get area. Now we want the area under the hyperbola bounded between 12. I want the area colour to be orange. And the opacity, which is the width of the rectangles in the Riemann integral, which is denoted by dx scaling. I want that to be 0.05. I'm going to attach that to the V2 variables. I'm going to have add v to label comma a2 and now hit run. And so what we're gonna do in the next installment is vary this value of t together with the vertical line to indicate that t being this upper bound on the integral is the variable for this function here. Hope to see you guys there. 9. Shading Regions: Okay, so in this installment, what we're gonna do is move the vertical line together with the V2 label or different values. For example, here we had two, we're gonna move it to 1.5. We're going to move it to 2.5. We'll move it to three and so on. Changing these together as well as the area. So what we're going to do is basically repeat these lines here, but for varying values. So I'm actually even going to copy and paste and then just change v3 to, let's do 2.5. I'll keep the color the same. I'll change this to 2.5 V3 label. I'll write A3, B3, B3 labeled a3. This needs to be changed to a three. All this can remain the same. This now has to be next to V3. And all that seems fine. Just make sure that all 2's have been changed to 3s. I don't want to show this on top of everything else. I want to transform V2 into the three sign going to transform V2 into v3. And let's hit run. It's just view the animation now in its entirety. So here we see an issue. The area seems to have gone further than what the vertical line has. So let's have a look at that and see vertical line went to three and we wanted it to go to 2.5. So let's just fix that now. Scrolling through. And then we have does exactly what we wanted them to do. So let's do that for a few more values of t. So again, copy and paste. So I'll change this to V4. Now. We've labeled A4, will do 4.5 this time. So this has to be changed to 4.5. This has to be 4.5. This has to be the boar and self.age transform. Now, even though we want to change V3 into V4, if we write V3 V4, that's not going to work. As you can see if you try it out yourself or you need to do is always transform the original ancestor of this thing that was transformed into, even though we're transforming v3 and v2 is gone. Now, we're going to transform V3 to V4. We have to transform V2 to V4. So just always remember, what did you start with, and that's what you need to transform. So if we now hit run, and there we go, we varied the area under the curve together with its label using some transformations. In the next video, we'll just as some finishing touches. 10. Polishing off the animations: So for this last part, we just want to add some finishing details. So if I want to add some x labeled nums has just these are the X values. X takes on the axis I want labeled, so maybe I want one to six labeled. Similarly, the y labeled nums. Maybe I just want 123. Say let's save and hit Run. The tics labeled appropriately. The final part of the video just had a question regarding Euler's number. So let's just type some of that in. So for what value of T Now this is going to be mapped. So let's change it to math tech. I'm going to insert this with a text. So for what value of t? F of t equal one. And I'll put a space in here. Maybe I'll make that red. Now this is going to appear in the middle of the screen. If I shift times two, Now, I want everything else to fade away and transform into this Q1 variable. So what I'm gonna do is I'm going to define a new variable, prev or previous. And I'm going to collect all the old variables together. So I'm going to define a V group, V, G, capitalize and collect all the variables that were there previously. So for example, V2 was there. We don't have to write v4 because v4 came from the two. Similarly for v3, we had a V1 appearing, so I need to collect that. We added a T4 coming from a T1. So I need to collect T1. I need to also get rid of T2 and T3, as well as the axes and the hyperbola. So I'm going to do self.name axes that's going to transform the axes as well. And T2, T3. And now to transform them, self.position transform prev Q1. Let's hit Run. All that remains to do to finish off our product is. And so the question, for what value of t does f of t equal one? And this is Euler's number. And will, since this was red, I'll use blue. This is next to Q1 down. And I'll write self dot play, right? Q2. And the other thing that's occurred throughout here as the animations are very, very fast. And when you actually sit down to record your voice over these animations, you want to have plenty of time to talk and it's easier to cut out space, nothing. Then it is to insert space where you have time to talk. And so what I would do is between every animation here is insert a self.age weight one. And in fact, when I'm about to edit it, I will insert a self.view 86. But for the moment, let's just do self.view weight one. So let us now see what our final product looks like. Okay.