Transcripts
1. Introduction: Hey there. Thank you so much for joining me in this course. Before we get started, I
want to take a quick second to introduce manim
and what it even is. So most likely you've seen animations like
these on Youtube. There's one math
focused channel in particular called
Three Blue, One Brown. That first got me wondering
about how they're made. And after digging
a little deeper, it turns out that the
creator of this channel, Grant Sanderson, was the one who originally wrote the open
source project called Manim. What is Num? It's
a Python library that lets you create
animations by using code. And the library is
a collection of prewritten code that programmers
can use to code faster. It's essentially like a
mode in a video game. It adds extra features, making it easier to
complete certain tasks, in this case, to
create animations. What I hope to give
you in this course is a complete starter pack of
skills that would allow you to start writing
code and experiment with it yourself to create
stunning animations. The reason I started learning
num was because I thought that the animations you can create with it look very cool. And I was curious if I
could learn it enough so that I can make some cool
ones for my Youtube videos. It was a very natural process. And once I felt like I knew
enough, I just stopped. Now I know the basics to
the point so that when I want to create a more
complex animation, I can just Google how to
do it and go from there. And when I have a gap
in my editing timeline, instead of searching for generic
stock footage or a gift, I can quickly whip
together a sick animation. Which I think makes
the video a lot more entertaining and
enjoyable to watch, just like you. I'm also a beginner to man him
and believe it or not, I know barely nothing
about Python, which is the programming
language that you write the code with to create
manim animations. The cool thing about this
is that you can learn basic Python and
how to write code. As you're learning manim, you don't have to have
any programming knowledge beforehand to create
these animations. There's a saying that
it's a lot better to learn from someone who's just
a few steps ahead of you, but not 1,000 steps ahead. Because two beginners can speak a similar language and understand each other's
problems and knowledge gaps a lot more compared
to a beginner and a Harvard professor who often assumes you already know a
lot of things to begin with. My goal with this course was to make it super easy for you to understand all the concepts from a beginner's point of view. That's why I've designed
this course to be friendly to people with varying
levels of experience. I'm going to assume you
know very little or nothing about coding or
creating animations. Just as I did a
couple of months ago before I started learning mana. So you can feel free to skip around if something
feels redundant. For example, if you already
know how to set up VS code or you're already familiar
with basic Python syntax, you don't have to
feel the need to watch the whole lesson
all the way through. The only thing you need to take this course is a computer
and an Internet connection. After it, you'll be
able to create and tweak animations like these
or like these by using code. Also, before we get started, I just want to thank you for
joining me in this course. I know there's 1 million things you could be doing right now, so I really hope to make
it worth your time. Thanks again and let me know if you have any questions
along the way.
2. Class project - before we get started: Welcome to the
course. There's going to be quite a bit
of information, so I want to make sure that you get and retain as much
of it as possible. What I recommend for most
students is to first go through the full course in
order to help paint a full picture of
how manim works. And then to come back to individual sections
later based on the things that you
feel you may be missed or don't
completely understand. Also, another great
thing would be to have a place where
you can take notes, whether it's Apple
notes on your phone, a notepad, or a Google Doc. During the course,
I'll be going through different commands that
are easy to forget. If you don't use them often or if you don't
write them down, I encourage you to do
that. Most importantly, I recommend following along
with me downloading Nim, setting everything up, and
then copying what I'm doing. I'm going to be
showing you animations that you can replicate yourself. And the best way to learn
is by doing it yourself. For this class project, I
want you to create a quick, maybe five or ten second
animation that you think is cool by applying the things you
learned during the course. As I said, we're going
to be creating a bunch of animations that you
can follow along with. So you'll have a lot of
material to experiment with, but I'd encourage you
to create something of your own browse through
different parameters. Shapes, text, it doesn't even
have to make sense, just make something that
you think looks cool. And once you do
that, upload it to the project gallery so others can take
inspiration from it too. So without further ado, let's learn how to install.
3. How to setup and install Manim on Windows: This lesson, I'll
show you how to install manim. If
you're using Windows. It might look a little scary because we're going to
use the power shell, which is this mysterious
thing that hackers use. But don't worry,
you will do it step by step and you'll be able to start creating animations
with manim in no time. First thing here, I'm googling how to install manim on Windows. And I'm going to use
this guide here by the manim community so that
you can follow along with me. Now it says here
that the easiest way to install manim and its dependencies is by using
a package manager like chocolate ly or scoop. So let's install chocolate
ly first I'll click on it, which will take me to its page. And here it says that I need
to do it with power shell. So I'm going to search
for power shell inside of my windows and then run
it as administrator, because it says that I have
to run it as administrator. Next up it says I need to
run, get execution policy. So I'm going to copy that and
put it into my power shell. And click Enter. And if
it returns restricted, then run this command or that command for me. It returned bypass,
which means that I don't have to type
this in or this in. Next, let's run the
following command. I'm going to click
here to copy and then paste it into
my powershell. And click Enter.
After a bit of time, it says here that
chocolate is ready. Next I'm going back to the
manim installation guide and I'm going to see
what the next steps are. And this is good news. Manim can be installed via chocolate by simply
running Choco install. Man, I'm going to copy
that and put it in my powershell and click Enter
once again, right here. When it stopped, I pressed
the letter Y on my keyboard, which just basically means yes, and that it can proceed further. Here it says, do you
want to run the script Y Yes or all? I'm going to put in
the capital letter A because I want to
install all the scripts. And then after I click Enter, it continues again
and it's done. Now it says please reboot at your earliest convenience.
So I'll do that. Now that my PC restarted,
everything is installed. We'll now want to
install VS code, which is basically
a program that will let us write and edit code. I'll type in VS
code into Google, then click on the first link and then press download
four Windows. Once I save it, I'm going to
open what I just download it and it's going to open
the installer for VS code. I'm going to accept
the license agreement after thoroughly
reading through it, then I'm going to click Next. Next. Again, here
I don't have to change anything and
just click Next. And finally install. It will do its magic and VS code will be installed
on your computer. We can leave the launch
visual studio code checked and click
Finish. And we're in. Now in order to start
writing manum code, we're going to need to install a few extensions within VS code. You can basically install
extensions into it, just like inside your browser
to add some bonus features. And there are three
that we want to get to. Extensions. Click on
this four square icon on the left and then
type in Python. That's the first
extension that we want. If it shows up here
already under popular, you can just click Install
here without searching. The second one we'll
need is called pylons under popular
extensions, but if you don't see it, you can
just search for it. And the final one we need
is called Nim Side View. This one is going
to allow you to see the animations that
you create with manim within visual studio
code without actually having to find the animation
file every single time. Search for that and install. And that's it. Well, just
kidding. It's not it. There's one bonus thing that we can install alongside manim that will make it easier to work with animations that have text. I'm back here inside of the installation guide and
I want to install latex. And it recommends that
we use this command. Since we already installed the Chocolate Ly
package Manager. I'm going to copy this, Go
back into the Windows shell administrator and
paste it in again. When it says, do you
want to run the script? I'm going to put
in capital A and press Enter to let it install everything that
it wants to install, and everything is done to
make sure everything works. I went into VS code and wrote some code for
a basic animation. We'll walk through how
to do everything later. And I noticed that
Manim works great news. But then I tested
out this bonus thing that we just installed
called Latex. And it seemed not to
load the animation. And gave me an error
saying latex failed but did not produce a log file
check your latex installation. So I used the other
command provided in the installation instructions
to install it again. This time it seemed to
have been installed. But give me yet another
error saying latex error converting to DVI log output
above or the log file. I spent around 40 minutes
searching and found someone on Red It who managed to painstakingly solve
this error themselves. And luckily, they provided
a command that solves it. So I opened the power
shell and pasted it in. I leave the code in
the description. Afterwards, the error was
resolved and now I have a good installation of manim that I can start creating
animations with. If you're getting the
same error as me, you can paste in
this code inside of your power shell and it will get rid of it thanks to this editor. Once again, this was how to
install manim on Windows.
4. How to setup and install Manim on Mac: Lesson, I'll show you how to install manim if
you're using a Mac. First thing here, I'm googling how to install manim on Mac. And I'm going to
use this guide from the manim community so that
you can follow along with me. It says here, for the sake of simplicity, the
following instructions. Assume that you have the popular Package Manager home
brew installed. I do not have it installed. So Google for Homebrew, here we go. It's the first link. And it says here
that to install it, I can copy this and paste
it into my Mac terminal. I'll hit this, copy,
open the terminal, and paste it in by clicking
command V on my keyboard. Once I hit Enter, it'll
install homebrew, which will basically let us
install manim a lot easier some time. It says here,
installation successful. I'll close it and I'm back here in the manim installation guide. Then I can copy this first line, open the terminal again, paste it in with command
V and hit Enter. Once it installs everything. I'll go back to the guide, and here it says
that Macs that have M one series chips or later also require this
installation as well. You can check which chip
you have if you go to the Apple menu on the top
left and click about this. If it says here,
Apple M something, then you have the M series chip. If it says Intel, then
you have an Intel chip. Which means that you don't need to install this bonus thing. Since I have the M one chip, I'll copy this and paste it
in the terminal as well, do its thing. And finally back
to the installation guide. Again to paste in
the final command and our num installation
is now finished. Next I'm going to
install VS code, which is basically
a program that will let us write and
edit our num code. I'll search for VS
code on Google, click on the first link and then choose Download Mac Universal. Once it's downloaded, I
can double click on it, which will extract it
from the zipped file. Then I'll go to go and
choose Applications. Then I'm going to drag
visual studio code into the Applications folder, how you install apps on, cuz I can open it now. Before I start writing any
code inside of VS code, we'll want to install
a few extensions. You can install
extensions into it, just like inside
of your browser. To add some bonus features, I'll press on this
four square icon, which means extensions. And I'm going to look
for three extensions. The first one is called Python, the second one is called pylons, and the last one is
called Manim side View. Once I click install on all of those, I'm
essentially done. And there's one bonus thing
that we can install alongside Manim that will
make it easier to work with animations
that have text back here inside of the
installation guide. And here in the
optional dependencies I want to install latex. It also uses home brew,
which we already have. So I'll copy this and paste
it in the terminal again. And it's installed to make
sure everything works. I'll open up Vis code
and write some code to test if manim code works and
if it creates an animation. I'll leave this code
in the resources so you can try it out yourself. And sure enough, if I run
the code here and then click on this icon to
open manimsideview, select hello, it opens up the
animation that I created. This is how you can
install manim on Mac.
5. Getting to know Visual Studio Code: Here we are inside of
visual studio code and this lesson is going to be all about getting to know it. We'll talk about keyboard
shortcuts to help you access different commands
and also write code faster. How to create new files
and how to save them. Essentially everything that you need to know in order to set up your environment to start
creating num animations. First things first, whenever you open visual studio code
for the first time, you're going to be presented
with a screen like this. From here, you can
create a new file, open an already existing file, and do many other things. But we can also do this without the help of
the welcome screen. We can go to File
and choose New File. Here we can select Python File. Since we're going to be
writing manum code in Python, I'll choose that and it
created a new Python file. Now it's not saved yet, so I'm going to click
command S to save it. And I'm going to expand
this so that I can create a new folder within my desktop where I'll save all things
related to this course. So I'll click New Folder
and name it Course Demo. And then I'll save this
file inside of here with the name of manim
demo. And there we go. If I go into the course demo
folder and right click on the new file that's been created open with and
visual studio code. It will open within
visual studio code and now I can start writing code
and creating animations. Every single animation that
I will create will appear inside of the course demo
folder right next to this file. Manim will create a bunch
of folders here where we'll be able to find the final
file of our animations. Another keyboard shortcut
that may be useful to you is command shift P on Mac or
control shift P on Windows. And this lets you access all available commands based
on your current context. In terms of manum, it was useful for me for just one case, and that's choosing the
Python interpreter. So I'm going to
search for Python and I can see
Select Interpreter. If I click on it, I'll
be able to select which Python version
this file uses. If your manum code doesn't
work, this may be an issue. Now, there are also a few
useful keyboard shortcuts for navigating your code
and writing it faster. I'm going to open one of my
Manum projects and then copy some code from here and paste it in in order to showcase
the keyboard shortcut. Also, I'm going to press
command plus on my keyboard, that's control plus On
Windows to zoom in, if you want to zoom out, it's
command or control minus. Here we have some code that you don't really have to
worry about right now, but we'll focus on
keyboard shortcuts. So it's not really super fast or efficient to move across your code with
your mouse cursor. It's a lot faster to do
it with the keyboard. For example, if I want to
select the text, right, I would have to move my hands
away from the keyboard, then pick up my mouse, move
it over here and select it. And sometimes I will select a little more than I wanted to, then I would have to click
away and then select it again. It's a lot faster to do
it with the keyboard, go up like this and then
select the text like so. And then change it
to whatever I want. Let's see how to do that on Mac. If you hold option on your
keyboard or control on Windows and click either
the left or right arrow, it will move your cursor
across the whole word. Right now I'm holding
option and clicking the right arrow and it
jumps from here to here. Instead of me having to
do it letter by letter. Now if I add shift to
the shortcut option, shift right arrow, as it
jumps over this word, it will also select it. I can immediately start typing here and
replace that word. Now in order to
delete the full word, instead of deleting
letter by letter, you can hold option or control on Windows
and click backspace, and it will delete
word immediately. Instead of you having to delete letter by letter,
which is a lot faster. Holding control on
Windows and clicking either the left or right arrow
will jump between words, which is the same as holding option on a Mac. And
doing the same thing. If you add shift, it selects the words
that you jump over. Now if you have multiple
lines like this, you can navigate up or down
with just your arrow keys. Let's say I wanted to select
this word brown instead of searching for it
with my mouse cursor and then selecting over it. I'm going to hold Option, then click left a few
times than up a few times. Hold option, shift, select left, which will select this
whole word and the space. If I didn't want to
include the space, I would just moved one spot over here and select
the word again. Now I can change it to something else if
you're using a Mac. There's also a handy keyboard
shortcut that jumps across the whole line instead of
only one word at a time. And that's command
and your arrow keys instead of option
and your arrow keys. Unfortunately, Windows
doesn't have this. Of course, you can select
the whole line with command shift and left
arrow key as well. If you learn these
keyboard shortcuts, it will make it a lot
easier for you to navigate VS code and
write code a lot faster. Let's move on to
actually writing some code and learning
the basics of mani.
6. Setting up a Manim scene: In this lesson,
we're going to write the first lines of code
and learn how to import manim into Python and also how to create a
scene for our animation. Once you're inside of Manum, the first thing you're
going to want to write is from man import snowflake. This will import the manim
library inside of Python. And the library is essentially
a collection of code that makes it easier to write code
without the manim library. Vs code will not understand
the code that we're writing and will not be able
to output any animations. Next we'll want to
create a scene, and we can create multiple of these scenes within
one manim file. Let's class then the name
of our scene that we want. I'll say demo, then parentheses, and the word scene with
the capital letter. And then at the end, let's add a colon. It should
look like this. In Python, capitalization
is important. If I write the word scene
with a lower case letters VS, Code immediately notices that something's wrong and
underlines this word. I know that I have
to come here and change it to the
capital letters. Now, another important thing
within Python is indenting. Right now my text cursor is
right here in the front. But under class demo scene, I want to click Tab once it
increases by one indent. What this basically means is that if I write anything here, it will live under this. If I wrote it
without the indent, the code will not live
under the class demo. Also, you can click this
little arrow here and it will hide everything
that's under this scene. If you work on
multiple scenes or animations within
one manum project, you can just collapse some of the scenes that you're not
working on in order to make your workspace cleaner
and for you to be able to understand what you're doing and where
everything is better. I'm going to delete
this. Expand this again under the scene. I want to write
def construct self and also add a colon at the end. And all of this is the
preparation that you need to do in order to start creating
a scene or an animation. This line of code imports the
manim library into Python, And this right here
creates a scene inside of which we'll be able
to create our animation. You'll notice if I
click return or Enter, it immediately gives
me two indents. Which basically
means that VS code automatically pressed tab twice. So that I write all of my code under the deaf construct self. And I want all the
code that I write for my man animation to be inside
of this def construct self. Which means that
sometimes you will not understand why your
code is not working. And that's simply because you didn't have the
right indentation. If it's like this,
it understands that this line of
code right here is under the class demo scene and not under deaf
construct self. We want everything to be
under deaf construct self. I'll just move my
cursor here and click Tab once on my keyboard to
put it back into place. Also, if you write
some code and see this white dot inside
of your VS code, that means that this code
hasn't yet been saved. If you want to save it, go
up to file and click Save. Or a simpler way is
to hit the keyboard, Shortcut control S on Windows or Command on Mac and
it will save the project. Now that we have
our Num workspace prepared and we've
created a scene, let's write the code for
our first animation.
7. Creating the first animation: This lesson, we're going to
learn the basics of Manim. We're going to write
the first lines of Nim code and create a
simple text animation. Now that we have our scene, let's move the cursor inside of the deaf construct
self and let's create an animation
where there's going to be text writing
itself on the screen. I'll create a new variable
and then say that it's equal to text inside of parentheses
and also quotation marks. I'll put my text,
I'll say hello. So I've assigned this
text to the letter. Also notice the
capitalization here. The text command starts
with the capital letter. Now I've created this text, but it will not appear inside
of our animation because we want to tell Python that we want it to appear
on the screen. To do that, we'll use the
self dot play command. If you want to put
something on the screen, you'll always be using the
self dot play command. It means that you want
to show something. I'll open the parentheses
again and say right. And inside of its parentheses I'll say this right
here basically determines what kind
of method do I want to use to showcase
the animation case. It will write out the text. If I hover my mouse
cursor over this text, it will say here that it
will simulate handwriting. Now let's run this code
by coming over here, clicking this downward arrow, and choosing Run Python file. It will now run this file, but nothing really happened. Next, let's come
to this icon here, which is the manum side view extension that
we installed before. Click on it and choose
the name of our scene. This name right
here. I only have one scene which is
the demo scene. I only see one option here, but later we'll have multiple
scenes that you'll be able to choose and play inside
of the manim side view. If I click here, it
will run the animation. You'll see that it
writes the word hello. Now to find this file
inside of your computer, you're going to want to go where you saved this python file. If I hover over the name, it will tell me its
location for me. It's under desktop
and course demo. I'll go to my desktop and inside of course demo I'll
be able to see a few folders like media and piiche I care about
the media folder. I'm going to expand that,
then go into videos, manim demo and ten ADP. And here I can see the file
that has the name which is the same as my C. And
if I preview this file, it's the same animation. So I can just take
this file from here and use it wherever I want. Now that we made our
first simple animation, let's explore some
different commands and different things
that we can animate.
8. Creating a simple text animation: Okay, so this is the text animation that we
have right now. It just says hello in plain text in the
middle of the screen. So let's play around
a little bit with this text and try to make
it a little different. Inside of here I'm going
to put a comma and the space and VS code will automatically tell me what
else I can put next to it. So we can see that
the text object has a bunch of different attributes
that I can assign to it. For example,
filopacity, which means how see through text is color, or font size, or line spacing, font weight, and so
many more attributes. By the way, if you want to find out different attributes
of an object, you can simply right click on it and press go to Definition. It will open up a new tab with a document describing what
you can do with that object. Here if I scroll down, we can see some examples that are the same examples
we were able to see when we just hovered our mouse cursor
over the word text. You can see you can
change the height, the width, and many
different parameters. But let's just say
we want to change the color to be blue. Vs code automatically
suggests some more colors. Maybe I want to pick dark blue. So I can just click on it and
it immediately fills it in. Then let's say I want the weight of this text equals bold. The word bold also has
to be capitalized. Let's say size or
actually font size VS. Code automatically corrected
me here is equal to 48. Now I'll click command on my keyboard to
save this and re, run this code once more. And it automatically opened
it in num side view. We can see now that the text has this dark blue color
and it's bold. If I want to make it bigger, I can increase the font
size to something like 100. Hit command, once again
it became bigger. Now one more useful command
that you're probably going to use a lot is self dot weight. This essentially pauses the
animation for some time. In seconds I'll say
self weight three, and then I'll hit
command on my keyboard. And when this
animation restarts, you'll see that the
word hello stays on the screen for a
longer amount of time. That time is precisely
equal to 3 seconds. It played the animation where it wrote on the screen
and is the text. And then it waits for 3 seconds. After that, I'll
say self dot play. And right, which is the exact opposite
of the right command, it will unwrite this text. I'll hit Command on my keyboard once again
to run this text. And it writes, it stays here for 3 seconds and
then unwrites it. I'll add another
self weight command for 1 second so that you'll
be able to see it better. It writes the text, then waits
3 seconds and unwrites it, and there was a gap at the
very end of exactly 1 second. So that's what you
can do with text.
9. Importance of variables: Now, of course you
don't have to create a variable and then
assign text to it. You can put all of this text
here inside of self play. So it would say self dot play. Right? And then the text
inside of the parentheses. Essentially, I didn't assign
a variable to this text, I just wrote it inside of
the self dot play command. The same thing happens, but the reason we want
to assign it to a variable or just a
random letter is that if for some reason we want to change this text
in the future, we will have to change it only in one place,
which is here. Instead of having to go to every single self dot
play command where we wrote that text and then
change it individually. It's just better to assign
things to variables, which means that
you'll be able to more easily change that thing
that's inside the variable without having to
change those parameters across multiple different
places inside of your code.
10. Good resource to learn Manim: So this is a very good
resource to learn num. It's the Manimcmunity website. You can go into
doctmanimtcmunity and you'll find a very good
resource to learn Num. Here's the installation
instructions and there's a tutorial
for beginners. If I go to tutorials, I'll be able to enter
the Quickstart guide, which will essentially walk
me through the basics of Nim. Also, if I've forgotten
a few commands, I can say text maanim. Then the first
Google result will usually be the manim
community where I'll be able to go in and read about that command
or that object. Scroll down, I'll even see some examples of this
element being used. Also, I can click here
to make this code interactive and then add
something of my own. Instead of self dot ad, I'm going to say self
dot play right text. If I click Run, it will run
this code within the website. It just takes a while
until it gets going. As you can see, I've created this animation within
the code on the website. It's a really good
resource to learn mani, and experiment with it yourself to see what
different things do.
11. Creating a rectangle: That we have this text here. Let's add some more things on the screen and animate
them together. First, I will add a square. I will assign the
letter to the square. When I added the parentheses
VS code immediately tells me that there's an attribute that the square uses
called sight length. An example here is
the number two. I'm going to say side
length equals to, let's say three. And that's it. Now I have the square, but it's not going
to be added into my animation because I need to add it with the
self play command. I'm going to click Enter
and say self play again. I can use the same way of animating it with
the right command. Say, inside of parentheses, right now I have this blue text over here which is
assigned to the letter A. And then I'm animating
this text on the screen with the
self dot play command. Then I'm telling Manim
to wait 3 seconds, which in this case is
a little too long. So I'm going to decrease
it to 1 second. Once it writes this
text on the screen, it's going to wait 1 second. And then I added a square. And it will also animate the square. Let's
see what happens. For some reason, it doesn't
run because it says object got an unexpected keyword
argument side length. And that's because I spelled
it wrong. I forgot the. Now if I click command, it should run normally. Yes, there's the text. It waited 1 second and then
it drew the rectangle. But now the text and
the rectangle are both in the center of the
screen. How do we separate?
12. Shifting objects on the screen: Let's say that. I want
the rectangle to be on the left and I want the
text to be on the right. I'm going to come
here to the text, then say period, shift, and inside of parentheses
I will say right. Then I will copy this and add the same thing
to the rectangle, but I will say shift it left. Let's see what happens now. The text is shifted a
little bit to the right, and the rectangle is shifted
a little bit to the left, but they're still
overlapping with each other. Now the reason for
that is because it's shifted by just one place. And that's because by default, the scene in manim is made
up by an eight by 14 grid. If you want to see this grid, you can say self dot. A self dot ad is basically
the same as self dot play. But it doesn't play anything. It just plops an element on the screen without an
animation inside of it. I'm going to say number plane
with empty parentheses. Now if I play this, you'll
be able to see the grid. It shifted the word hello
by just one square. And it shifted this square also by one square,
but to the left. If I come back to the text, I can say shift it right, but times three, which will
shift it by three squares. And I can come to
the square and say shift it left, but
also by three. Now if I play this, the text is here and the square
is here on the left. And also I'm going to add another self dot weight command
at the end so that I can quickly posit when
the animation ends and still be able to see
it before it restarts. But what if I want to
shift this text Hello a little bit up and the
rectangle a little bit down. I can come here and add a
comma say up times two. It will shift my text right by three squares and then
up by two squares, it should end up somewhere here, inside of the rectangle. I can add a comma and
say down times one. It will shift it down by one squared and this
is what we get. The text is up there and
the square is down here.
13. Changing parameters of an object: Let's explore the square
attribute a little more. We only provided one parameter, side length three, which
made it this size, But there are some more
parameters that we can choose. I'm going to delete
everything to do with this text and only
work on the square. I don't have to have it here and I can leave
it in the center. I'll also delete
the shift command. Now I can assign a fill
opacity to the square, and I'm going to say
that it's equal to 0.7 which is 70% opacity. Phil. Opacity
basically means how visible is the fill
color of this square. Right now, there is no fill
color since the middle of the square is black,
just like the background. And I'm going to say
color equals red. Now the whole square
will have a red color, The outline will be fully red, and the center will be 70% red. If I play this with command
S or control on Windows, you can see that the
outline of the square is a little more visible than
the actual fill color. Now I can lower this to 0.2 and this is how it
will look like. It just fills in with
less of that color. Now in order to find out
some more parameters, I can right click on the square
and go to its definition, which will open up the
documentation for the square. I can see that there's an object for a rounded rectangle as well. It has a corner radius attribute that I can set to
whatever I want. I'll come back here
and instead of I will say rounded rectangle
also as soon as I started typing the word
rounded VS code automatically tried to guess what I wanted to type and it suggested
it over here. I don't have to type
out the full thing. If I hit Tab, I began typing round and it immediately
suggested rounded rectangle. And then I hit Tab
to fill it in. Let's add the corner
radius attribute, and let's say it's equal to
two and see what we get. Now I've run this code
and it says that it got an unexpected keyword
argument, side length. Side length doesn't apply
to the rounded rectangle, which means I will delete it. I'll run this once again
and it should work. Okay, We got this shape, and that's probably because
corner radius goes up to one. And then if it's more than one, it becomes this weird shape. Let's say 0.1 There we go, we get a nice rectangle
with rounded corners. If you put corner radius
to something above one, like ten, it's going
to make a weird shape. If I put one, I'm assuming it's just going to
be an oval shape. Yes, that's how
you can create and experiment with different
shapes inside of man.
14. Different ways to animate something on the screen: This whole time I've been using the right animation and it basically writes
things on the screen. It can also write
this rectangle, but there are
different ways that we can add things on the screen. The next one that
I wanted to show you is called draw border, then fill inside of parentheses. I'll say it will first draw the border of the shape and then fill it in with
the fill color. Let's see how it looks
like, it looks like this. The next way of
animating that you could use is called fade in. Which will basically just
subtly fade in the shape. You can also fade anything out. If I say fade out, instead of it will
look like this. It fades in and
then it fades out. Next, we can transition from
one shape into another. I'll create another
shape, a triangle. I'll set its fill opacity to 0.2 the same as the
rounded rectangle. I'll set its color to
blue and size to two. Now instead of self dot play, I'm going to say self dot add. And I'm going to
add the rectangle, then it's going to
wait for 1 second. After that second ends, I'm going to say self
dot play transform. And we're going
to transform from the rectangle which we've
assigned to the letter. And it's going to transform from S. And we've assigned our
rectangle to the letter t. It's going to add the
rectangle, wait for 1 second, and then transform from the
rectangle to the triangle. It tells me that it's got an unexpected keyword
argument size, which means the triangle
doesn't have an attribute size. I think it has an
attribute called scale, and you have to write it with a period after the parentheses. I'm going to say the
scale is equal to two. I'm going to also add
self weight at the end and make it 2 seconds so the animation weights
a little bit. This is how the
transform command works.
15. Exploring the self.play() command: You can also do is
set the duration of an animation
inside of self play. I'll add a and say run underscore
time is equal to three. Which now means that
this transform animation will run for 3 seconds. If I run the code, you'll
see that it's a lot slower. You can add the run time
attribute for any animation. If I say right, it will apply to the right
animation as well. You saw that the triangle faded in very slowly over 3 seconds. I can also make it
super fast by saying 0.1 Now it basically
appeared instantaneously. Another thing that
I can do within the self dot play command
is add two animations. I'm going to shift the
rounded rectangle left by three and I'm going to shift
the triangle right by three. Now they're going
to be separated inside of self dot play. I can say right,
which will write out the rectangle and
then draw border, then fill, which will animate the triangle. This
is how it looks like. You can see that both of these shapes now appear
at the same time, each with their own
specific animation. One more way of
animating something is create instead of draw
border, then fill. I'm going to say Create, which will use the
create animation to draw the triangle
on the screen. Let's see how that looks like. As it draws the outline, it also fills in the triangle. This is how you can use
the self play command to add things on the screen.
16. Animation 1 - Circle: Let's try to create an
animation that looks like this. Which will teach us about grouping different
shapes together, rotating stuff,
moving it around, resizing and adding updators. As I'm going to be walking
you through this animation, I highly recommend you open VS code and copy
exactly what I do. I'm going to be walking
through it very slowly showing everything
that I do step by step. You're going to learn so
much faster by doing it yourself and fixing errors yourself rather
than looking at me. Do it. I encourage you to
change different parameters, maybe name things differently. Just do it yourself
and then scroll back if something didn't work
and copy what I did. You're going to learn so
much better this way. You can see first we have the text Nim appear
on the screen. As well as this shape over here which is actually
just a circle and a square that's drawn around that circle.
Let's first do that. I'll come to my VS code and
delete everything apart from the class scene and deaf construct self which we need to create the animation. The first thing that we need
is a circle in the middle of the screen and a
rectangle that surrounds it. I'm going to assign the
circle to the letter, so it's easier to
remember say equals and circle with a capital letter
C because that's the syntax. Then I'll open the parentheses, and inside of it I'll
give it a radius of 0.5 which will make
the circle this big. I have opened the
animation within VLC so that I can pause
and show it to you easier. The circle is going
to have a radius of 0.5 Then when I pose it, we can see that the circle has a thicker outline and then a subtle red color
that's filling it in. I'm going to add another
attribute which is stroke width and say
that it's equal to ten. This will give the circle
this thicker outline. Also, we went to
color the circle red. So I'm going to say color equals red are some predefined
colors like red, red, ABCDE, which are just
different shades of red. And there's also pure red. If you want to add
a custom color, you're going to need a
hex code of that color. And every single
color has a hex code. Instead of saying color
equals something, we're going to come to the
end of the parenthese, say, period set
underscore color. And then inside of
its parentheses, we're going to put
the hex code of our color inside of
quotation marks. The color white has the
Hex code consists of red, green, and blue color. Let's change the
green color to be 00 and it should
give us a magenta. Yes, the circle is now magenta. If you want to find a hex code of a color, you can go online, type in color,
picker into Google, then pick any color
that you want. And here you will
have the hex code. If I copy the hex code
of this green color, and then paste it over here
with the hashtag and re, run the scene, the circle
will be that color. But inside of our animation, we want the circle to be
red color equals red. Another thing that I want is for the circle to be
colored red as well. Right now, only the outline
has the color soils fill opacity and I will set
it to something like 0.3 Let's see how
that looks here. It says that it got an unexpected keyword,
argument color. I made the mistake and
capitalized the word color. I'm going to write it
with the lower case letter C. Let's see if
that gives us the result. It does. Now the circle is
red and we have the circle.
17. Animation 1 - Surrounding Rectangle: Now we want this rectangle on the outside and it has
these rounded corners. I'm going to assign the rectangle
to the letter R. Again, it's easy to remember. This rectangle is called
a surrounding rectangle. It will surround whatever I put inside of these parentheses. It can be text or
it can be a shape. In this case, it's the
circle I'm going to put inside of myself
play command. As well as drawing the circle, I also want to draw the
surrounding rectangle. I'm going to say right, which will create the
circle, add a coma. And also right R, which will create the
surrounding rectangle. And if I run it,
this is what we get. But this rectangle is yellow and it doesn't
have rounded corners. If I click inside
of the parentheses, add a comma and hit a space. It also suggests other
things that I can input inside of the
surrounding rectangle. I can see here that
I can set a color, I'm going to say color
and set it to blue. Also, I can see here that it has corner radius and
that's what I want. I'll set the corner
radius to be equal to something like 0.1 There we go. Since the animation
stops immediately, I'm going to add a
self weight command at the very end with
empty parentheses. Empty parentheses
basically mean that it's going to wait for a
default amount of time. The default amount
of time is 1 second. I don't have to say one here
for it to wait 1 second. I can leave this
parentheses empty. Now if I play this animation, it's going to wait for 1
second at the very end. Now we have the circle and
a rectangle surrounding it. But we also want this text that says manim at the
top of this shape.
18. Animation 1 - Positioning objects next to each other: I'm going to come here and
assign my text to the letter. It's easy to remember. I'm going to say
text and inside of parentheses and quotation marks, I'm going to say mani. Now let's see what happens
if I play everything. The text, the rectangle
and the circle, Everything is in the center. The text overlaps
with the shape. And I want to put this text above the shape like
in this animation. To do that, I can put a period and say next underscore two, it will put this text
next to something. Now inside of parentheses, I have to say next to
what I want to put it. I'm going to say next
to the rectangle, I have to add a and say which
direction I wanted to go. I'm going to say up. Let's
see what it gives us now. Now the text is above the shape, but in the animation, the space between the shape and the text is a little bigger. Let's add another here and look through the list of
things that we can add. One of the things
is called buff. What buff means is a buffer, or just a space
between two things. I'm going to say buff equals
to something like 0.5 Now, the text should be a
little higher than before. Yes, we have the
initial shape animated.
19. Animation 1 - Moving objects to specific coordinates: Let's look at the animation again and see what
else we want to do. The first thing that catches my eye is that the
circle animates in a different way compared
to manim and the rectangle. That's because instead of
using the right animation, I use the draw border,
then fill animation. Now if I run this,
it's exactly the same. The next thing that we'll
want to do is to make both of these objects go into
opposite directions. Like so. I'm going to
add a few lines here. Since I want something else
to happen on the screen. I'm also going to use
the self play command. Now I want the text manim
to end up over here, and I want this to
end up over here. Let's start with the text. In order to animate something that's
already on the screen, I'm going to use the
animate command. I'm going to say t,
which is the text, because I want to
animate the text. Then I'm going to add a
period and say animate. Now I'm going to add
another period and choose the type of my
animation right now. I want to move it to
a specific place. I'm going to use the move
underscore two command. This command lets
me move something to a specific position
on the screen. Now inside of its parentheses, I'm going to add brackets, brackets like these.
They're not smooth. Here, I want to define the coordinates of where
I want my text to move. The first coordinate is x, the second coordinate is y, and the third coordinate is
z. I wrote these letters here as placeholders because there should actually
be numbers here. But how do we figure out what kind of numbers
to put in here? Well, remember that our man in video is made up of a grid. To be exact, it's eight by 14. The x value goes from
minus seven to seven, and the y value goes
from minus four to four. I'm going to temporarily
say self play, right? And number plane, this is just to show
the number plane. Also. I'm going to comment this out so that VS code ignores
this command. If you put a hashtag symbol
in front of some code, it turns a comment
which means that VS code just ignores it.
I'm going to play this. Here is the coordinate system. As you can see, it's made
up of eight by 14 squares. In the animation that
I want to create, I want to move my
text over here. I'm going to uncomment this. And let's say that it moves
to x equals to minus four. Because here in the center, all of the coordinates
are equal to zero, which means y is equal to
zero and X is equal to zero. And also z is equal to zero. But we don't need to
worry about z at all. We're always going
to leave it at zero. We're going to focus only
on the x and y values. We want the text to
end up somewhere here, which is 1234 squares in
place of the first zero. I'm going to say minus four. Now let's check the
y value over here. The value of y is equal to zero because it's
on this center line. I'm going to leave it as zero. Let's run this animation
and see how it plays out. Here's the coordinate system and the text moves into this spot. Exactly. I'm going to delete the coordinate system so that it doesn't
obstruct the view, but inside of our animation, we also want this shape
to move over there. The problem is that
at the moment, both of these shapes
are separate things. We would have to move
each of them separately, but there is a way to
combine to a group. Before the self play command, I'm going to come
here and say that r is equal to V group. And then what things I
want to put in the group, I want to put the circle and the surrounding
rectangle into a group. I'm going to say you can put all sorts of
objects inside of a group. Text graphs, different
shapes or anything else. Now, whenever I
animate this group, all of the objects that are inside the group
will move together. Here I'm going to put
a and say R animate. Because I want to
animate the whole group. And I said that the
group is equal to r. I want to animate R to
put another period. Move underscore two, don't
forget the brackets. By default, its
coordinates are 000, but I want to move it over here. Y value doesn't change because we only move
it horizontally. But the x value is the exact opposite that
we used for this text. Instead of minus four, I'm going to say four. And let's see how this
looks like. Perfect. Now we have the start
of this animation.
20. RECAP - Animation 1: Let's pause for a moment and run through everything that
we've done so far. First, we created a circle. We gave it a radius of 0.5 We gave it a
stroke width of ten, which made its outline a little thicker than
it is by default. Then we gave it a color red, which colored both the outline and the inside of
the circle red. And then we gave it a
fill opacity of 0.3 which made the filling of
the circle only 30% visible. If I was to say one here, the circle would be fully red, the outline and
also the inside of the circle would be fully
red. Let's undo that. Next, we drew a
surrounding rectangle, which is a command that draws a rectangle around
a chosen object. The object I chose
was the circle. This is why I put
the letter here, because I said that the letter
is equal to the circle. Then I gave this
surrounding rectangle the color blue.
That's why it's blue. And I gave it the
corner radius of 0.1 That's why the corners of this rectangle are
a little rounded. And these two
created this shape. Then I created another variable called and I said that
is equal to this text, this text over
here, inside of the text parentheses, I said manim. The text says manim. I said that I want
to put this text next to R, which is our
surrounding rectangle, and I want to put it up next
to the rectangle and up. And they also increased the
distance between the text and the rectangle by adding
the attribute called buff, or a buffer of 0.5 That's
why the text is up here, and that's why
there's a space in between the rectangle
and the text. But if I were to only do
this and nothing else, then nothing else would have
shown up on the screen. As you can see, the
animation is just black because I
only created all of these objects and
I haven't actually told Manim that I want to
put something on the screen. Next I use the
self play command. Um, that I want to put
something on the screen. I use the right animation to put the letter on the screen, which is our circle. Then I used the draw border, Then fill animation to
put the R on the screen. And R is our
surrounding rectangle that surrounds the circle. Again, I use the right animation to put the text on the screen. Initially it looked like this. Next, I wanted to move this text from this position
to this position. And move this shape from this position into
this position. But first, I needed to
group the circle and the rectangle together so
that they move together. And I don't have to animate
them separately for that, I use the V group command. Inside of its parentheses, I put the circle
and the rectangle. I called this group SR. I could have called it
anything that I want. I could have put Shrek here, which would mean
that I need to put shrek over here as well. Then I wanted to animate them going to their positions
at the same time. That's why I didn't use separate
self dot plate commands. But instead, I put both of the animations inside of
one self dot plate command. Which means that both of them
happened at the same time. Now let's just focus on
the first animation. I said animate, which means
that I want to animate. Remember, I've assigned
the letter to my text. I want to animate the text. And I said that I want to
move it to these coordinates. Again, our screen is split up
into invisible coordinates, which are eight by 14. The center coordinate is 000. If I want to move it left, I have to decrease this number. If I want to move it down, I have to decrease
the y coordinate. If I want to move it right, I have to increase
the x coordinate. And if I want to move it up, I have to increase
the y coordinate. In this case, I wanted to move this text to this position. Since this position
is on the x axis, that means that y
is equal to zero. If the x coordinate
was also zero, it would stay in the center. I want it to be over here.
I'm going to say minus four. What this will do is move
the text from wherever it is on the screen to this
position to minus 400. Here's how it looks
like. But I also wanted to move both of
these shapes as well. I put and then inserted another
animation. I said Shrek. Do animate for me. Shrek is equal to this group. The group of both the
circle and the rectangle. Which means that now it's going to animate both
of them together. I said that I want to move
it to this coordinate. This coordinate is
opposite of this one. I knew that y doesn't change because I
don't want it to be either higher or lower from
the x axis. I knew that is going to change because I wanted it to move horizontally. And that way has
positive x values. And here there are
negative X values. I said plus four,
which is just four. And all of that gave
us this animation.
21. Animation 1 - Creating an arrow: Let's look at what happens next. There's an arrow
going from manim to this shape and both ends of
the arrow have the arrow. Let's now add the arrow. I'm going to call
my arrow arrow. And I'm going to
say that it's equal to an arrow is
essentially a line. I'm going to say line. And then inside of
its parentheses, I can see that it has
these parameters. The start of the arrow
and the end of the arrow. And there's also the
buff to add some space, this space right here between
the end of the arrow and the shape that the arrow
points to inside of the arrow. We want to specify the start. I'm going to say that
the start is equal to, let's say this as the
start of this arrow. Because we can
either choose this as the start or
this as the start. It doesn't really matter here, the start of the
arrow is pointing at the left side of this shape. I have to tell manim that I
want the arrow to start on the left side of this shape
with some a buff value. To add this space
here in between. I've called this whole shape, it's a group of the circle and the rectangle,
and it's Shrek. For me, I'm going to say
start equals to shrek. Then I want to say Shrek. What? I'm going to
use the Get command. As I've mentioned,
we want the arrow to go to the left
side of this object. Now it's just going
to go to the center. If I play this self play right arrow, let's
see what will happen. Both of these objects move. And then this is our arrow. It starts somewhere here and it points to a random
place on our object. And it's not even an
arrow, it's just a line. We want to say where
it should point to. I'm going to say period, get underscore and
there are a bunch of places that I can
get from this shape. I want to get the left side. I'm going to say left. Then I'll add empty parentheses. What this means is that
the start of the arrow, we'll go to the left
side of this shape. But we also want
the other end of our arrow to go
to this word nim. I'm going to say d
is equal to that. I'm going to find the
variable to which I've assigned my text,
which is the letter. I'm going to say period, Get this time I want you to
point to the right side. I'm going to say
right and also add empty parentheses.
This is what we get. Now, it gave me an error saying that it got an
unexpected keyword, argument star, which
means that I've accidentally misspelled
the word start. I'm going to spell it correctly
and rerun this again, and this is how it
looks like now. Right now, this is just
a line and not an arrow. Because I've said that my
arrow is equal to line. How do I convert
it into an arrow? I can come to the end here at a period and say
add underscore tip, which will add the
tip of the arrow. Let's see how it looks like now. Now the tip of the arrow is pointing to only the word manim, which means that it added the
tip to the end of my line. Because the end of
my line is next to which is text next to text. And on the right side of the
text, which is right here. Now, I also want to add
the tip to the other side. So I'm going to add
another period, say add underscore tip. And inside of its
parentheses we can see that there are some
attributes that we can give it. There's one attribute called at underscore start that we
can say true or false. I'm going to say at underscore
start equals to true. Again, the capitalization
of this word matters. So true needs to have
a capital letter. If I run this, the arrow should now point
to both objects. Yes, but inside of our
animation, there's a space. And inside of our animation, there is no space in between
the arrow and these objects. To add the space inside
of the line here, inside of its parentheses, I can say buff
equals to something. In this case, I'm
going to choose 0.4 Let's see how
that looks like now. Perfect. Now, there's
a tiny space between the letters and the arrow and between the shape and the arrow, But you'll notice that
inside of this animation, the arrowheads are
slightly different. They're not the same
triangles as they're here. How do we figure this out? I'm assuming it has to do something with this
tip attribute. Again, I'm going to click
inside of the tip parentheses. Right now it didn't
suggest anything. I'm going to delete these
parentheses and add new ones so that VS code suggests something
inside of them. And here I see that I
can pick the tip shape. When I was creating
this animation, I didn't really know what
kind of tip shapes exist. I used my good friend Google. And I Googled four arrow tips here inside of the
maim community. I can click inside
of the arrow tip and I'll see a list of arrow
shapes that exist. It seems like I used
this shape here, which is this shape
at the bottom. It's called the stealth tip
here. Inside of my project. I'm going to come into
these parentheses again. It doesn't suggest anything. Again, I'm going to retype
them and I'm going to say tip underscore shape equals. And I want stealth tip, Stealth, It already
suggests stealth tip. And let's see what that
gives us right now. This end of the arrow
has this shape, but this end doesn't
have that shape. Which means that we need to add this tip shape attribute to
the other end of the arrow. So this was the first tip
and then remember we added the second tip which also made the arrow have
the tip at the start. I'm going to click inside
of the parentheses, Add a comma and paste in
the tip shape attribute. Now both the ends should have the same type of tip, perfect.
22. Animation 1 - Indicate and rotate commands: Let's see what's the
next thing that we want to copy the text. Manim, jumped up, became orange, and then jumped
down. Let's do that. For this, there is
a function called indicate and it basically
indicated this text. You can also indicate
shapes or anything else. I'm going to say self play indicate with a capital letter. I then open the parentheses and put the thing that
I want to indicate. In this case it's text. Again, I have the letter
assigned to my text. Then I'm going to put the
size of the indication how much I want it to indicate how big I
want the text to get. The default value is one. I just wanted to be
a little larger, and I'm going to say 1.5
Let's see what that gives us. The beginning is the
same and manim jumps up, but right now it's yellow. And in the animation that we want to recreate, it's orange. Which means that the
indicate command has some more parameters
that I can add to it. I'm going to add a comma and
the space for it to start suggesting stuff
to me and we can add the color with color. I'm going to say
color equals orange. The color has all
capital letters. Let's see how it looks
like. Now text is orange. Let's see what's next. This shape did some
weird shenanigans. Let's go frame by frame
and see what is going on. By the way, I'm pressing on my keyboard to move
one frame on VLC. We can see that the arrow
is shrinking that way, which we'll get to later. But right now, let's replicate
what the shape is doing. Let's first focus on
the rectangle here. It's rotating left, The
size of it is not changing. The only thing
that's happening is it's rotating to
rotate something. We can use the rotate
function again inside of self play because I want to show that thing
happening on the screen. I'm going to say rotate. And then inside of its
parentheses I'm going to object that I want to rotate. I want to rotate the
surrounding rectangle. This blue rectangle,
which for me is R. I'm going to say R.
Then after a comma, I want to put an angle to
which I want to rotate it. I'm going to say
angle in Python. Angles don't work with degrees, but they work with radiance, which in simple terms means that degrees go from minus pi to pi. And pi is 3.14 something
with a lot more digits. Essentially, pi
means 180 degrees. Minus pi means -180 degrees. Now let's look only
at the square and let's see how many degrees
we want to rotate. It pi, it seems like it
rotated just 90 degrees. If I say angle equals
pi, that's 180 degrees. To get 90 degrees, I can divide pi by two, which will mean it's 90 degrees. Let's play it and
see what happens. The shape moves here. The
square rotates by 90 degrees. If you want to convert
degrees to radiance, you can just put degrees
to radiance into Google. And then say you
want 180 degrees, which is the number pi, because it's 3.1 4159, I want 90 degrees, that's pi divided by two, which is 1.57 something here. It also gives the formula
from which you can get either the degrees
or the radiance. Anyway, pi divided by two radiance is the
same as 90 degrees. Now the rectangle is rotated, but the circle here also became bigger as the rectangle
was rotating. Which means that we want
to make the circle bigger as the animation for the
rectangle is happening. Which means that we're going to put the animation inside of the same self dot play
command separated by a comma instead of creating a new self dot play animation. Let's observe what
happens to the circle. It just gets bigger as
the rectangle rotates. In order to make it bigger, we're going to use
an animation called scale in place inside
of its parenthesis. I'm going to tell it
what I want to scale. In this case I want
to scale my circle, which is the letter for
me, I'm going to say. And then after a comma, I need to say, by how much
do I need to scale it? In this case, I'm going
to scale it by two times. It's going to become
twice as big. Of course, let's see
how it looks like. The rectangle rotates and
the circle gets bigger.
23. Animation 1 - Updater: Let's go back to the animation
and see what happens next. Actually, we don't need
to see what happens next because we didn't
fully complete this part. You can see as the
circle gets bigger, it also pushes the arrow
to the left very slightly. The arrow maintains
the same buffer, or the same distance between the circle and the end
point in our animation, the arrow just stays
in the same spot, it even overlaps
with the circle. In order to do that,
we somehow need to update the arrow as the
circle gets bigger. And for that we're
going to use an update. An updator is
essentially going to constantly update the position of some sort of an element. In this case, we want the
position of the arrow to constantly update as the
circle is getting larger. I'm going to find my arrow
which is right here. And then I'm going to
encase this whole thing, this whole line, this arrow
code inside of the updator. The code for the updator is
always underscore, redraw, and then I'm going
to add parentheses and say lambda and then a colon. Let's not forget to add another parenthesis
at the very end to make sure that the
always redraw function houses everything inside of it. What this will do is
always redraw the arrow. Every single frame that
plays on the screen, and any video is
made up of frames. One frame is essentially
just an image. And every single
video essentially has many different images
just playing fast. And that's why it
looks like a video. What this will do is for every
frame that gets generated, it will update the
position of the arrow. In this case, we
said that our arrow starts on the left
side of Shrek. And Shrek for us is this V group is the circle and
the surrounding rectangle. Shrek basically means
this whole shape. What this will do is for each frame of the video
that gets generated, it will look at
where the start of the shrek is and also where
the end of the text is. But the text doesn't move, so the arrow is going
to stay in place. But it will look at where
the edges of this shape are. According to that,
it will redraw the arrow for every single
frame of the video. Let's see how that
looks like there. As this shape got bigger, the arrow moved to the left. It's going to be easier to see when we do the next animation, which is just this
shape moving to the center and the arrow
getting smaller as well. I'm going to click Enter
once more, say self play. Now I want this shape, which for me is equal to
to move in the center. I'm going to say animate and then move to add parentheses. And inside of those
parentheses, add brackets. And I'm going to input the coordinate to which
I wanted to move, in this case the
center, which is 000. And I'm going to play this
and see what happens there. As it moves to the center, the arrow automatically updates itself and moves with the shape.
24. Animation 1 - Finishing up: Again, let's analyze each frame. What seems to happen now is the mani text and the
arrow slowly fade out. Once they fade out, the circle starts to get bigger and the
rectangle starts to get smaller until it
disappears, just like so. Now the circle is so big that we can't even
see it on the screen. And then the circle
also fades to black. Let's do that first. We need the nim text and
the arrow to disappear. So I'm going to say self
play inside of brackets. I'm going to use the
fade out animation, which fades something out
inside of its brackets. I'm going to say arrow because I want to
fade out the arrow. And also I want to
fade out the text. At the same time, I'm going to add another fade out animation. And inside of its brackets, I'm going to say which for me is equal to this text.
Let's see what happens. I notice that in the
animation that we want to copy the text and the arrow fade out a little faster, it's almost
instantaneous. By default, every single
self plate command runs for 1 second. The duration of the
animation is 1 second, but we can change that with the run underscore time command. And we're going to
say it's equal to 0.251 fourth of a second. Now if I run this, it will
fade out a lot faster, almost instantaneously
Next, once it's faded out, I want the circle to get bigger. And at the same time for the rectangle to
shrink to nothingness, I'm going to add another
self dot plate command. Because it happens after
every already faded out. That's why I'm using the next
one because I don't want everything to fade out and do everything
at the same time. I want it first to fade out
the text and the arrow. And only then for
the circle to get bigger and for the squared
to shrink inside of here, I'm going to use
another animation called shrink to center. And I want to shrink
the rectangle. And the rectangle for me is
the letter R. I'm going to say also I want the
circle to get bigger. And we already used the
scale in place command, which can basically scale
something up or down. I'm going to use that scale in place and inside of its
parentheses I'm going to put, because I only want
to scale the circle, which for me is the
letter S. And then I'm going to say by how much
I want to scale it. In this case, I want to
make the scale ridiculous. So I'm going to say 30 times, and this is what we get. The arrow fades out and perfect. Now the only thing that is left is to fade this red into black. Because in the original
animation, this fades to black. Which means the circle
basically disappears. So I'm going to add
another self play command. Because I want it
to fade to black only after it's been scaled up. And I'm going to say fade out and which is the circle.
And let's play it. Perfect. So now we've
copied that animation.
25. RECAP 2 - Animation 1 - Arrow: Let me briefly step
back a little bit and explain again what
happened from this point. From the point that
we created the arrow, we wanted to create this
arrow that points to the word manim and also
points to this shape. Let me delete this updator
to explain the arrow, we created a new variable
and named it arrow. And then to create the arrow, we use the line command, which essentially creates
a line that we can add these arrow end points
to to create the arrow. Also, if you want, there is a separate command that you
can just add an arrow with. And it already adds the arrow
without the line command. I just showed you how to do
it with the line command. If I just said R
equals to arrow, and I said the end of
this arrow is equal to Shrek get right. And instead of playing
this double arrow, I just played this arrow, this is what we would
have got. Instead, it's just the same arrow. I said that the
end of this arrow is on the right
side of this shape. That's why it's pointing all
the way to the right side. If I wanted it to
point over here, I would have said get left
instead of get right, and it would have
looked like this. If you use the arrow command
instead of the line command, you don't even need
to define the buff or the space that separates the
arrowhead and the object. It's set automatically. You can use arrow
instead of line. But in this case, I used the line command and then
created an arrow from the line. Also, there is another
command called double arrow, which could have created
the same double arrow. Instead of me having to
add a line and then add tips at the end of the line. But I wanted to show you
how to do it with a line. Anyway, I've set the
buff value to be 0.4 which told the arrow that I want there to be a
little bit of a space between an object that
the arrow is pointing to. The buff is essentially
this space right here, and this space right here, and I've set it to 0.4
I said that I want the start of the arrow to get
the left position of shrek, which means that it got the
left side of this shape. Because this shape
for me is Shrek, since it's a group that houses the circle and the
rectangle inside of it. I said that the start of
the arrow should point to x left side, and it points to the left
side of this shape. Next, I said that I want the end of the
arrow to point to, which for me is my text. And I wanted to point
to the right side of, and indeed the other side of this arrow is pointing to
the right side of this word. Of course, there's a little
space because I've said that buff is equal to
0.4 Now by itself, this would have just been
a line because I used a line command and I wanted
this to be a double arrow. What I did at the end of these parentheses is
added two arrow tips, one over here and then
the other one over here. First arrow tip, which I've
highlighted right now, essentially added
an arrow tip with the tip shape being
the stealth tip, which gave it this shape. But if I only added
one tip here, it would have only added the
tip to the end of my line, which is right here,
pointing to this text. Again, it's right here because I've defined it
to be right here. That's why I added another tip. And with the parameter at
the start equals true. I said that I also
want the tip of the arrow to be at
the start as well, Also for both ends of the arrow. I said that I want the tip
shape of the arrow to be the stealth tip which essentially just made
the end of the arrow. This shape Who?
That's the arrow.
26. 26 RECAP 2 Animation 1 The Rest: Next. I said that
I want to indicate the text which made
it jump up like this. I said that I wanted
to jump by 1.5 times. So it gets larger by 1.5 times. And I also said that the color when it jumps up
should be orange. And indeed it's orange. I'm going to open
it with VLC again, so that I'm able to pause
the animation better. Next, I said that
I want to rotate, which is my rectangle by 90 degrees pi divided by two
is 90 degrees in radiance. And also at the same time, I want to scale in place the letter which for me
the letter is the circle. I wanted to scale the
circle in place by two times after it
highlighted it, rotated the rectangle, and also scaled the circle
just like this. Next, I wanted to
move this shape in the center as well as
move the arrow with it. That's why I needed to add an updator to the arrow
so that as soon as something moves that
the arrow is attached to the arrow is going to
move with it as well. I said always redraw the
arrow inside of parentheses. I said lambda and a colon. Of course, don't forget to close the parentheses
at the very end. Now, since my line
or my arrow is always going to be at the
left side of the shrek, right here with the buff of 0.4 As soon as this shape moves
or changes its position, the arrow will always
try to adhere to this. The start of the arrow will always try to be on
the left side of this shape with the buff of 0.4 Which means that if
this shape moves over here, the arrow also has to move to
adhere to these parameters. Now in order to move the shape, I said shrek animate, because Shrek is the shape. And then I said move to 000, which is the center coordinate. The shape moved like this. Next I said that I
want to fade out the arrow and I want
to fade out the text. I want all of that to happen
in a quarter of a second, the text and the arrow
quickly faded out. Finally, I said that I want
to shrink my letter R, which is my rectangle, to the center, and
I also want to scale my circle to 30 times, which made it go like this. For the very end, I faded
out the circle as well, so that's why everything became this black color
at the very end. I hope I've explained
everything clearly and you were able to understand
how this animation works. Because we've gone over a lot of the principles of
how to rotate stuff, how to position stuff on
the screen, how to attach, and how to update different objects in
relation to other objects. And also how to do some
simple animations.
27. RECAP 2 - Animation 1 - The rest: Next, let's create an animation that looks something like this. It's not the most beautiful
thing I've ever made, but it's going to teach us a
few more important concepts when animating with Nim. Once again, I'm going to be
pausing this animation as I go along and we're going to
try to replicate everything. I'm going to collapse my old scene like this by
clicking this arrow over here. I'm going to add a few spaces here so that it doesn't
obstruct what we're doing Next, I'm going to create a new scene. I'm going to say
class, then demo two. And scene in parentheses,
then a semicolon. And of course, deaf
construct self and a colon. Once again, this is
our second scene. Again, we can have
multiple scenes or multiple animations
within one manim project, within one Python file, inside of VS code. Open up the animation once again and play it back from
the very beginning. We have three words,
Hello there, dog. And the letters of the word dog are all colored in
different colors. The first one is red, the
second one is orange, and the last one is yellow. In order to color individual
letters of a word, instead of assigning
text to a variable, we're going to instead assign
text to a variable text. But without the letter,
text is basically latex. It's one of the things
that we installed in the very beginning when we
were installing Manning. It's a different
beast on its own. And you can create different
mathematical formulas with it and basically
do a lot with text. But I'm only going to
go over the basics of latex because it's
very complicated. Text works pretty much the
same as the command text. For example, if I type
hello there, dog. And then I'll type self play write T to animate this
text on the screen. And then I'll run this code
and I'll choose demo two. Inside of my manumsideview. It's pretty much the
same as writing text. If I change it to text, what happens? Pretty
much nothing. The text is just a
little different. I'm also going to add a self weight command
at the very end and say that it should wait 3 seconds after the
animation finishes. But what we can do
with text is customize our text in various
different interesting ways. For example, instead of having just one
line of text here, I can put the text Hello, inside of quotation marks. Then I can add a comma, I will add the word there
inside of quotation marks. And the word dog as well. This will still write the
same hello there, dog text. But right now, there are no, because we didn't
really add any spaces. If I add a space after the word hello and after the word there, this text will now have spaces. As you can see, we've
separated our text into three separate elements
and all of them are inside one variable,
the one that I chose. What I can do now is
write them individually. In programming, this
is called an array. What's an array in programming and what an
array essentially is, it's a special variable. In this case it's cars, which can hold more than
one value at a time. And this text, cars holds
Ford, Volvo, and BMW. An array essentially
holds multiple values. And in this case we
also have three values, The word hello, the word
there, and the word dog. What's cool with race is
that we can call each of these individual things inside of it one by one, individually. The way to do that would
be to tell Python. Which one of these
elements do we want to work with or
do we want to call, for example, inside
of this animation? Which one of these three
do I want to write? If I put just it understands that I need
to write everything, but I can add brackets and
say zero inside of it, which means the first element. In programming, everything
starts from zero. This is the element number zero. This is the element number one, and this is the
element number two. It's not the first, second, and third, it's 012. If I say that I want to write
the element number zero, it will only write the text hello on the screen instead
of hello there, dog. And if I run this, it
only writes hello. Now, I can also write the first and the third element
and skip the second one. I'll add a comma, say, right? I'll say, add the brackets
and say the number two because remember this is the second element because
it starts from zero. If I play this, it will
only write hello dog, but the word there is missing. What I can also do
is inside of here, add a colon and then say, from which to which
element I want to write. For example, if I
only want to write these two elements and
exclude the third one, instead of writing
them out individually, I could come into
the first brackets, add a semicolon and say two. Now it will write
everything from zero to the element 2.2 is not included. It will write out the element 0.1 up until two isn't included. It will not write
our second element. If I run this, it should
give me hello there. Yes, if I only write one to two, it should only give me
the first element because the first one is included and the second one
isn't included. It's essentially the
same as writing one. Yes, it gave me the
second element, which would be exactly the
same as writing it like this. I'm now telling it to write
out the first element. This is zero, this is one. It's going to write there again. That's how you can tell Python
to write out a range of an
28. Animation 2 - Text and arrays: Let's go back to our animation and see what we've done here. There are three words.
Hello there, dog. And the word dog
also has a color. Now what's cool about this
is that we can assign different colors to each of these different elements
inside of our array. I'm going to say two, which is the word
dog because 012. Then I'm going to
say color equals. And I'll choose red. And I'll type out the whole, everything that's inside of
all three of these elements. Let's see what happens now. Only the letters
of dog became red. But in this example, I want every single letter to
have a different color. What we can do instead
is separate out the dog entirely into
different elements and assign a color to each
of those elements. Instead of saying hello there, dog, I'm going to
say hello there. D. Then add a and, which now separated
out the word dog. Now the second element became the letter
D. If I run this, only the letter D will
be colored red there. Now I want the letter to be orange and the
letter to be yellow. I'm going to come
here and say three. This is 012.3 The
letter is number three. I'm going to say color
equals orange and four, which is the letter
color equals yellow. Now if I play this,
we get the same text, but the letters of the word do each have a different color. We have replicated
what happened.
29. Animation 2 - Animating different words separately: Let's play this again and see if we did everything correctly. Here the text dog
writes itself first, and only then. Hello.
There appeared. Instead of writing out
everything at once, I'm going to say self play. Now I want to write
only the word dog. This is the element number zero. This is the element number one, and this is the
element number two. I'm going to say,
open the brackets. I wanted to write from
the number two up to the number 34.5 up
to the number five. Because remember five
is not included, It will only include
two to five. And we don't even have
the fifth element here. Another way to write this is
to write two and a semicolon that it will write
everything from the second element up to
the very end of the array. Right now, it will
write out the word dog. If I say two to five, the same thing should happen. And it should also
write the word dog. I'm just going to leave
it like this again, this is element number two
because it starts from zero. This is element 012, and that's the element that
I want to start writing out. Then I add a colon and define the final element that
will not be included. In this case, we have
element number two. Number three. Number four. I want the element number
four to still be included. Instead of saying four, I'm
going to say up to five. And we don't even
have the number five. It's just going to everything from here to
the end, the word dog. Next I want to write
out these two words. I'm going to click
Enter Self Play, right? Then again, add the brackets, and I wanted to
write the elements 0.1 everything up to
the second element, which is the letter D. I'm
going to say zero to two. Remember the element
two is not included. The letter D will
not be included. It will write everything
from zero up to the element number two and it will not include the
element number two. Let's see what we get. We get
dog and then hello there. Exactly as it was in our animation that we
want to replicate.
30. Animation 2 - Moving objects to the edges of the frame: Let's see what happens next. The word hello and
there split in half. And the word hello
travels to the top left. And the word there
travels to the top right. Again, I know that I need
to animate something, that's why I'm using the
self taught play command. Opening the brackets. First, let's work
on the word hello. The word hello is the
element number zero. I'm going to say,
open the brackets. And zero, because I only
want to work with this word. Then I'm going to add a
period and say animate, because I want to animate it. And then add a period. And choose which type of
animation method I want to use. In this case I'll use the
two underscore edge command tells manim that I
want to move something to either of the
edges of the screen. I'll open brackets
and now I have to say to which edge I
want to move it to. In our animation, the text Hello is on the upper left edge, so I want to move it upper left. If I wanted to
move it over here, I would say U R, which means up right. If I wanted to move it here, I would say D R, which is down right. It would look like this. If
I wanted to move it here, I would say D L, which means down left. It would look like this. If I wanted to move it left, I would just say left like this. Now, it should move right here. Yes, I want to move it here. I'm going to say U L, which is up and left. I'm also going to
add a buffer of one. Again, the buffer is
this space over here. How far away something
is from the edge? I wanted to be a little
bit farther from the edge, so I'm going to say one, this is how it's
going to look like. You can see that the
distance between the edges increased because I added
the buff value of one. Now inside of the animation
that we want to replicate, the word hello and there
move at the same time to different edges inside of the same self play animation. I'm going to add a and say one because the first element is
the word there, animate two, underscore edge inside
of parentheses, I'm going to say upper
right buff equals one, because I want to add the same buff value as I did to the text. Hello. Now if I play this, both of these words will
move to different corners.
31. Animation 2 - Arranging letters of text: Now we have this. Let's see
what we should do next. The letters of the
word dog all split up and form this vertical
line in the center. Again, there's something
happening on the screen, which means that I'll use
the self play command, open the parentheses, and I want to animate each
of the letters going to these positions
because the text dog right now is not centered, it's right here on the right. First, I'm going to
work on the letter D, which is the 012. The second element,
I'm going to say and add those brackets
and say two animate. In this case, instead of
the two edge command, I'm going to say period
and move score two. It's the one with
the coordinates. I'm going to add
the brackets again, and the default coordinates for every single object is 000, which is somewhere here in
the center of the screen. Now looking at the animation
we want to replicate. I can see that everything is in the center or rather
on the y axis. Which means that the x coordinate
will be equal to zero. Because the x coordinate
moves something sideways. We want to change only
the y coordinate, which means we want
to move vertically. In this case, I'm working
on the second element, which is the letter
D. And it's up here, which means that we need
to increase the y value. I'm going to say
something like two, and this is what
we're going to get. Yes, that's exactly
what we want. It, the letter D moves over here and it's aligned
in the center. But we also want to animate the letter and the
letter at the same time. In our animation, everything
is aligned to the center. But right now, the letter
is not in the center. I'll have to animate it as well. I'll say, open up the brackets. And the letter is the
next element after the letter D. And I know that the letter D was
the second element. I'm going to say three,
because this one comes after the letter
D. I'll say period, animate, period,
Move underscore two, open parentheses, and then
brackets inside of there. And I'm going to say 000 so that it moves to the
exact center of the frame. Let's see what we get now. Yes, now only the letter
G is remaining again. I want the letter to move at the same time as the letters. And that's why I'm
going to animate it within the same
self play command. I'm going to come
to the very end, add a comma and say four, because the letter G is the fourth element
inside of our array. And I'll say period, animate, move underscore two, open the parentheses
and then the brackets. And then inside of them, I want the letter to be in the center, which means that the
X value will be zero. But then I want it to go down, which means that the Y value
will have to decrease. I'll decrease it to the
same amount as I've increased for the
letter D. By two, I'm going to say minus two, and then zero for the Z value. Let's see what we get now. Perfect, all the letters align
in the way that we want.
32. Animation 2 - Creating and positioning shapes: Let's go back to the animation and see what we need to do next. We can see that there
are three shapes, each with a different color that appear outside of
each of the letters. Let's first create those shapes. First, the rectangle. I'll call the rectangle
something like the letter F equals
to rectangle. Then open brackets. And I want the rectangle
to be not that big. I'm going to say height equals one and width also equals one. Okay, we have the rectangle. Let's now create a circle, which I'll say is equal
to the letter C circle. Open the brackets. Right now, I don't really know how
big the circle will be, so I'll just leave
the brackets empty. Finally, I want to create
this polygon which in manim is called a
regular polygon. I'll assign this one
to the letter and say regular polygon,
open brackets. And inside of brackets, I can define n, which is how many corners the
polygon will have. In this case, we want
12345, say five. I've created all of
these shapes right now. If I play this animation, nothing will happen because I haven't played these shapes. The animation is the same. Because I've just created all of these shapes and I didn't
put them on the screen. I'm going to say
self play, right? And I will write out
every single shape, the rectangle, the circle, and the polygon. And
let's see what happens. Not only every shape
is different size, but it's also in the dead
center of our animation. We need to move every single
shape around and change its size so that it fits the animation that
we want to recreate. First, let's work on the square. I think the size is correct, but we want it to surround
the letter D. Now I know from before that the letter D is
the second element, 012. Here I've animated
the second element to be in these coordinates. What this means is that I
can move the rectangle to these coordinates
and it will be in the exact same spot
as the letter D. After the rectangle, I'm
going to say move two and I'm going to input these coordinates which are
the same for the letter D, 02.0 Notice that I don't have to use the move two command inside
of the self play command. I can also move something like the rectangle and only then
show it on the screen. I don't have to move
something only once, It's already on the screen. I can do it beforehand, and only then I can
reveal that object. Let's play this and see
if the rectangle moved. Yes, now the rectangle surrounds the letter D. Let's now
work on the circle. As we can see, our circle
is a little too big. And what I can do is
define the radius. I'll say radius equals to 0.5 I know it's 0.5 because I
made this animation before. But by default the
radius is equal to one. I want to make it smaller. I'll decrease the radius by
50% and say that it's equal to 0.5 Let's rent this
again and see what happens. Circle is now the correct size. Finally, I want to work
on this polygon and make it smaller as well as
make it surround the letter. First, I'll move the
polygon, I'll say period. Move two, open the brackets, and I want to move it to the
same position as the letter. The letter for us is 01234 is the fourth
element of this array. I'll find where I animated the fourth element,
and it's right here. And I animated it to
these coordinates. So I'm going to copy
the coordinates and simply paste them inside. Now you can see
that I accidentally pasted double brackets
on each side. I'm going to delete one brackets
and only leave one pair. Now the polygon
should be right here, but we also want to decrease
the size of the polygon, so I'm going to add another
period and say scale. And let's scale it down
by 50% I'll say 0.5 now. It should be twice as small and it should
be in this position. Let's run everything and see if that's really
what's happening. Yes, we've replicated this. Let's go back and see if there's anything
that we've missed. I noticed that I used a
different animation for the rectangle and the polygon as they were coming
onto the screen. They were appearing from
the center and then rotating into their
place like this. Both the rectangle
and the polygon, they're rotating into place. And in my animation they're
not really rotating, they're writing themselves out. I'm going to change
the right animation both for the rectangle
and for the polygon. I'm going to use spin
in from nothing. For the polygon as well Spin. And I can click Tab in order
for it to autocomplete. And now if I run this,
everything should spin nicely. Yes, so now we've completed
almost half of the animation.
33. Animation 2 - Rotating shapes: Let's play it again and see
what else we need to do. Now, all of these
objects rotated around. Let's see by how much this is, the first rotation,
the second rotation, and the third rotation. It seems like it rotated
360 plus 180 degrees. 360 plus 180, which
is 540 degrees. They all rotated
at the same time, which means that I need to group them together.
I'll come here. Remember, don't forget
the indentation. You don't want to be
writing the code over here. You want everything to live
under deaf construct self. If I put my cursor here, it automatically starts
writing right from the edge. And I don't want
everything to have two indentations so that everything lives under
deaf construct self. Here I want to group
the rectangle, the circle, and the
polygon together. I'll name this group CP because it's these
three together. I'll say that this
is equal to V group, remember this is how you
group objects together. And then inside of the
brackets of the V group, I'll say what I want to group F and which for me
is direct angle C, the circle, and the
regular polygon. Now we have the group, but we also want to animated spinning. I say self dot play. And then I'll use
the command rotate. Inside of its brackets, I can put what I want to rotate. It says here, define a object. And by the way,
object essentially means any kind of
object inside of mani, it's just called object
instead of object. I'm going to put in my group P because that's what I
want to rotate Next, I need to define the angle. I'll say angle equals. And remember inside of Python, not define the angle in degrees. I need to define it in radiance. In radiance, 180 degrees
is equal to the number pi, But I don't want to
rotate it by 180 degrees. I said that I want to
rotate it by 360 plus 180, which is 540 degrees. Now luckily, 540 degrees divided
by 180 degrees is three, and pi is 180 degrees. Essentially, I need to
rotate it by three pi. Here I will say pi times three, which essentially
translates to this rotating three
times 180 degrees, which is 540 degrees. Let's see how it looks like. Perfect. It's the same as with the animation
we want to recreate.
34. Animation 2 - Swapping positions of shapes: Now these two shapes, the polygon and the rectangle, grab each of the letters, and then they switch positions
like this. Let's do that. First things first, you
can switch positions of two objects with
the swap command, say self dot play swap. And then I want to
swap the rectangle with the polygon Inside of parentheses I will say
swap with with the, it will swap which for me is the rectangle with which
for me is this polygon. And let's see what happens
now, both of them swapped, but the letters still
stayed in place, which means that we need to group each of the letters
with their shape. Or alternatively, I could
just do this the easy way and say also swap two, which is the letter D for me, and then 34, which
is the letter, and it should achieve
the same thing. Yes, it now swaps both the rectangle and the polygon with the
letters inside of them. But I wanted to show
you another way, which is by grouping
them together. I'm going to delete this
self plate command. Make sure my cursor is right
here by clicking tab twice. And then I'm going to play the
animation so it refreshes. After it rotates,
I want the letter D to be grouped
with the polygon. I'll call P because my text is the letter and the
polygon is the letter. I'll say that's equal to the group because I
want to create a group. The first thing that I want
to group is the polygon. So I'll say the second thing
is the letter D. Now again, the letter D is 012. The second element of I'll say open the brackets and inside of brackets
I'll say two, which will now group
this polygon with the letter D. I also want
to create another group for the rectangle and the letter
G. I'll say because for me is the rectangle equals to
the group for the rectangle. And after the, I want to say
which letter is the letter. I'll come here to my text, 01234. It's the fourth element. I'll come down, say open
brackets and say four. Now I have this group
and this group. Now I want to swap these groups. I'll say self play swap
and P with it should swap both of these groups like this. Perfect. Let's see
what happens next.
35. Value Trackers: Next let's talk about a thing
called a value tracker. So I'm going to move all
of my scenes that I've created previously down and
I'll create a new scene. I'll call it class
value trackers and scene in parentheses, add a colon enter and def
construct self like this. And then I'll say
that is equal to my value tracker and inside of its parentheses I
can see that I can put a number, I'll
put a number ten. And what a value tracker
basically does is it tracks some sort
of a number value. You can't actually
put it on the screen, it works in the background. Instead what you can do is
attach it to another object and then animate it based on how the value
tracker changes. I'll show you what
all of that means. Let's create a number. I'll say that number is
equal to decimal number, which just basically means
it creates a number. And inside of its
parentheses I can say what kind of number
it is, say ten. And then I can also define how many decimal places it has, how many numbers
after the period. I'll say num, decimal
places equals zero. It will not have 10.00 it will
just have the number ten. Let's say self weight
for 3 seconds. And also let's play this
number on the screen. Self play right number. Let's see what we get. I will run the Python
file and then come to the manium side
view extension and select the value tracker scene. Once it plays, we just get a
plain number on the screen. Right now the number
is the same as my value tracker and they're
not connected in any way. I've just created
the value tracker and I just put the
number on the screen, but my goal here is to create a scene where this number counts 10-31 Way to do this would
be to create two numbers. I would say number two is equal to decimal number and I'll say 30 and nudecimal places
is equal to zero. Then I would come here and say self play transform
from my first number, which is named number, to my second number
which is number two. Now this is what we get. There's ten and then
it just changes to 30. But what if I want to show every single number that
it has to go through 10, 111-213-1415, the way up to 30. That's where I can use
the value tracker. I'll delete the
second number and also this self plate command. Instead of saying that
this decimal number is equal to just a
number, just ten, I will say that it's
equal to one dot get underscore value
which means that now this decimal number
is equal to this. Whatever the value is
inside the value tracker, which right now is just ten, it should give me
the same result, it should just write
number ten on the screen. It does. What I did here is I said that my
number is equal to a decimal number and
that decimal number is equal to whatever the
value of the value tracker. The cool thing now is
that I can animate the value tracker and the number will also
animate as well. Inside of my self
dot play command. I will say one animate, because I want to animate the value tracker
changing to 30. I'll say period set
underscore value, and I'll set it to 30. Now the value tracker
will animate 10-30 Also, right now, there's going to be nothing visible on the screen. Because as I've
mentioned before, you can see the value
tracker on the screen. I have to say self
dot play, right? And then our number. Let's see what
happens. There's still the number ten and it
doesn't really change 230. And that's because when we
animate the value tracker, we also need to
update our number. We need to add an updator. Remember, the easiest
way to do this is to say always underscore redraw, then put everything
in parentheses. Then come back and also
add a lambda function. I'll say lambda and a colon. Now, no matter what's
happening in our animation, it will always
redraw this number. I'll say command S, and
let's see what happens. The number ten comes
up on the screen and it animates
all the way to 30. Now I can increase the length
of this animation by saying run underscore time is equal
to something like five, which will make it, so
the whole animation lasts 5 seconds. So you can see that it
counts a lot slower. That's what you can do
with a value tracker.
36. Rate Function: You'll notice that
this animation starts off a little slow. Then it speeds up as
the numbers get higher. And then it also slows
down at the very end. And we can change this behavior. For example, if I wanted
every single number to change after the exact
same amount of time, I could add a comma here. Say rate underscore funk, which is rate
function is equal to rate underscore
functions period linear, which will set this
animation to be linear. And if I play this
now, the animation will not speed up or slow down. The time between every single
number will be the same. The default setting is not
linear, but it's smooth. If I say smooth, it
will now start counting slower then it will speed up and then it will slow
down towards the end. If you want a linear animation, just say rate funk is equal to rate functions
and then linear. But I'll leave it
as default for now.
37. RECAP - Value Trackers: Let's pause for a moment and
see what we've done here. First, we created
a value tracker. And we said that the value
tracker has an initial value of ten and we assigned the
value tracker to one next. We added a number which we
said it's a decimal number and then we had to specify
what kind of number it is. We said one get value, which means that
this number will be what's inside
of these brackets, it got the value from one. If I were to set this to 999, the value of this decimal
number would be 999. Next, we said that the number of decimal places is equal to zero, which means that this number
doesn't have a period. And some numbers
after the period. And the final thing we did to this number is added a update. We said that we want to
always redraw this number, and this is the syntax
for the updator. You have to say always
underscore, redraw, then put everything
inside of brackets, and then also add lambda and a colon at the
very beginning. Now everything here
will always be redrawn. Next, we said self dot play. Right the number on the screen, it wrote the number ten. And then we said self dot
play one dot animate. Which means that we
want to animate one, which is our value tracker. We said that we want
to animate this number going from whatever number
it is to the number 30. Right now it will go
from 999 to number 30. We said that we want to play this animation over 5 seconds. I'll rend this and
let's see if it goes from 999 to number 30. Over 5 seconds, there's
the number 999, it changes to number 30. That was the recap of
the value tracker. In the future lessons,
where we'll talk about axes and creating
graphs on the screen, we'll also be using
the value tracker. You'll be able to experiment and play with it a little more.
38. Axes 1 - Creating a new axes: The next thing that
we're going to be talking about is Axis. How to create them
and how to put different functions
onto those Axis. Again, I'll create a space
here to create a new scene. And I'll say class. I'll
name the scene axis, say scene inside of parentheses, and add a colon. Then I'll say deaf
construct self and I can begin
building my scene. Also close the manumcighteview. Let's start creating the axis. I will name my
axis the letter A, or actually I'll
just name it Axis. I'll say that axis
is equal to axis, which is the command
that creates an axis. Then inside of its brackets, I can see there's a lot of
things that I can define. The first thing I can
define is an x ray. From which number to which number my x
values are going to be. I'll say that my x underscore
range is equal to. And then I have to put brackets because they're going to
be two numbers in here. I want my x values to
go from -20 to 20. Then when I add a comma, I can also see that
there's a y range. I'll say y underscore
range is equal to, again, inside of parentheses. And I'll say something
like -15 to 15. Let's come down here,
say self weight, so that the animation waits a little bit once it finishes. And I'll say self dot play. Right? And axis, which will
put my axis onto the screen. Let's run the python file and it plays our previous scene. So what I can do is click
on this camera icon, which will let me change
a different scene. I want to play the
scene called axis. I'll just click on it
and it will generate. We can see that it
created the axis. The x values go from -20 to 20, and the y values
go from -15 to 15. If I want to see these
numbers on the axis, I can come to the very end a period and say add
underscore coordinates, which will add coordinates. I also have to provide
empty parentheses. As with everything
else, let's rerun this. And it should have numbers
on every single point here. Yes, there are numbers. You can see that it's
a little crammed here, but it goes from -15 to
14 and from -20 to 20, which is what we said over here. I'll remove the coordinates so that everything is easier to
39. Axes 1 - Putting stuff inside the axes: Next, let's add something
into these axes, because right now they're empty, I'll create a triangle. I'll say that tr is
equal to my triangle. And I'll say that my
triangle is scaled to 0.3 It's going
to be quite small. Now I've created the triangle, but it's going to be
just here in the center. And it doesn't really
have any relationship to the axis because I didn't say that it should live somewhere on the axis.
Next, let's do that. I'll say tri, which is my triangle Move underscore two inside of the parentheses. I want to say where
I want it to move. In order to move
something onto the axis, you have to first say the
name of the axis for me, is this one right here. Axis. Then say period two, which I think means coordinate
to point or something. And then inside of parentheses, you have to say which
coordinate you wanted to go to, which of course has
the x and y value. Our x values range from -22 20, from -22 20 over here. And our y values from -15 to 15, -15 here, and 15 here. Let's say that I want to put my rectangle
somewhere over here. I'll say that my x value
is equal to something like minus seven and my y value
to something like ten. Now I've created the
triangle and then I moved it to this spot
of the coordinates. Of course, I also need
to put it on the screen. I'll say self dot play, right? And triangle, which will
animate the triangle. This is how it looks
like. The triangle appears exactly on this spot. Now let's say self weight
and create something else. I'll create a dot.
I'll name it dot. And say that my dot is equal to dot with empty parentheses. Or I can assign something
like a color to it. I'll say color the dot red. Next, I want to play the dot to see where it
is on the screen. I'll say self play, create dot, just to mix it up. Right now, the triangle is here. Our dot is right
there in the center. Let's say I want to move this
dot to somewhere over here. I'll say dot, dot,
Move underscore two. Then inside of
parentheses, again, I have to say what's
the name of my axis? In this case it's just axis. Then I'll say period to
inside of its parentheses, I have to define
the coordinates. I'll say something
like x is equal to seven and y is
equal to minus ten, which is the exact
opposite of my triangle. The dot should move
somewhere over here. Let's see if that's
what really happens. There's the axis,
there's the triangle. Then there's the.in the center. And then it jumps over there. Now, why does it jump there, and why does it not move there? That's because I just said
do move to over there. I didn't tell Python
to animate anything. If I want to animate something, I have to use the self dot
play command in the front. I'll say self dot play. Then at parentheses and say dot. An animate move to axis. Now, instead of
jumping over there, it should move there
nicely. Let's run this. There's the coordinate
system. There's the triangle. The dot appears here and then
it nicely moves to that.
40. Axes 2 - Customizing axes: Okay, so let's learn to make
these axes a little bit more beautiful and experiment with other things that you
can do with them. Again, I will create
another scene called class axis two and then I'll say scene inside
of the parentheses. Next I'll say deaf
construct self and I can start
building out my scene. Again, I'll create my axis. I'll say that axis
is equal to axes. And then I have to define
the X range and the Y range. My X range is going to be
from minus one to ten, and my Y range is also going
to be from minus one to ten. But let's see what other
things we can define. We can also see that there's
an x length and y length. This essentially defines how long our axis is on the screen. Remember that the
screen in nim is made up of eight by 14 squares. If I say my x length
is longer than 14, it will not fit in the scene. But if I say it's equal to five, it will not take up
the whole scene. Let's say that x
length is equal to 13. Remember if I said 14, it would go out of bounds. And let's say y length
is equal to five. Then of course, let's say
self weight 3 seconds. And self play and write
the axis on the screen. Let's see what we get. This is our previous scene. Again, I can click
on this camera icon to choose a different scene. And I want to play the
scene named Axis two. I'll click on that, and
it says that it got an unexpected keyword
argument y length. Which means that I probably
misspelled the word length, y underscore length, and
now it should be okay. Yes, here are our coordinates. Now one thing I don't like are these arrows at the very end. Let's see if we
can remove those. I'll add another coma and see if there's anything to
do with these arrow. I can see that there's tips
here, which I'm assuming. Are these tips over here? By default it says true. If I say tips equal to false, I'm assuming that these
arrows should disappear. And yes, we don't
have any more arrows. Next, let's also come to
the end of the axis and say period underscore
coordinates, which will add coordinates. And we can also say period, set underscore color, and
let's set it to blue. We will add coordinates to
these axis and also make the whole thing
blue. There it is.
41. Axes 2 - Adding axes labels: Another thing you
might want to do is add labels to these axis. For example, I want
to say that this is the y axis and I want to say
that this is the X axis. I can create labels just
like any other variable. I'll say that x is
equal to axis period, get underscore x axis
underscore label. This is how you get the
label of these axis. Then inside of parentheses
I can say inside of quotation marks what
I want to name the axis. I'll name the x axis, X. Then I can copy this. And at this, and instead
of get X axis label, I can say get y axis label
and also name the y axis. But right now, both of these are assigned to the same letter X. I'll change this to Y as
well as playing out the axis, I can say write x
and then write y, which will write
out the axis labels as well as the axis itself. I'll play this and let's see
what happens. There it is. Our axes have names. This is the Y axis and
this is the x axis.
42. Axes 2 - Creating a dot with a label: Next, let's add a few spaces and create something
on these axis. Again, I'll create a dot. I'll say dot equals to do. Let's again make the color of this dot red so that
we can see it better. I'll move this dot. Move
underscore two, axis two. Inside of brackets, I can define the coordinates where I
want to move this dot. Let's say I want it
somewhere over here, which means that the
x value is equal to three and the y
value is equal to one. I'll say 31. Now, a red dot should appear over here whenever
I play it on the screen. Now let's also name this dot. Let's add a label for it. I'll say dot Underscore
label is equal to text. And I'll just name the
dot, the word dot. I'll say that the font size of this text is equal to
something like 24. And I'll say that this text
is next underscore two. And inside of our
brackets I'll say dot because I want it
to be next to the dot. And then after the coma I can
say where I want it to go, I want the label to be up. Again, I said that the dot
label is equal to this text, and I said that I want this
text to be next to the dot, which is this dot
for me over here, and I want it to be up.
Let's play everything. I'll say self dot play. Let's write out the dot label. And also write the dot itself. There's the axes and
there is the dot. You can see that it has
a label on top of it, and it's this label over here. And the dot appeared in
exactly these coordinates, x is equal to three
and y is equal to one, which is where we put
it with this command.
43. Axes 2 - Animating dot and dot label inside axes: Let me make this smaller so
you can see more of the code. Now let's say that we want
to animate this dot so that it moves from this position
to somewhere over here. But we also want it to
move with the label, which now means
we either have to put both of these into a group, or we can add an updtor
to this text so that it always redraws this text as
the dot moves along the axis. Let's take the harder route, and let's do it with an updator. We want this text to always
update as the dot moves. But first, we need to
tell the dot to move. Say self dot play. And then I want to
animate the dot. I will say dot period animate
move underscore two Again, I want to move it to a
specific of these axis. The syntax for that
is first the name of the axis, axis period two. And then inside of brackets, I can say where I
want it to move. I'll say that the x
value is equal to nine and the y value
is equal to six. You should move
somewhere over here. Now if I play this,
the dot should move, label should still
stay in the same spot. Yes. Now we want the label
to follow the dot as well. I'll come to the label and
after the equals sign, I'll say always underscore, redraw, then put this text
inside of parentheses, and then I'll come here and
say lambda and a colon. Now the label will always be redrawn to be next to our dot. Now if I play this, the label
should also follow the dot. There's the dot and it
moves with the label. Very nice. Again, an easier way to do this would have been
to just create a group. Say it's equal to V group. And then put both the dot and the dot label inside
of that group. And then instead of
animating the dot, we would have just needed
to animate the whole group. Which would have made the
dot move with the label. But we chose the hardware.
44. Axes 2 - Animating axes and clearing updaters: Now let's say that I want to put something else
on the screen, and I want all of
this to shrink down. I want these axes to end up somewhere over
here on the screen. I want to shrink everything. To do that, I will also need to put everything
inside of a group. I'll say group equals to V
group I spelled V group wrong. V group, by the way it
stands for vector group. Then inside of parentheses, I want to put everything first. I have the axis, then I
have the axis labels, which for me is x and
y. I'll say x, y. Then I have the dot
and the dot label. I'll say dot, underscore label. Everything you can see on
the screen is inside of this one group that I can animate together.
Let's animate it. I'll say self dot play
inside of parentheses. I'll say group do animate because everything is
inside of the group. And I'll say period scale to 0.3 It will scale this to 30% but it will scale
everything to the center. And I said that I want to move the axis somewhere
on the top left, say period, move underscore two. And the default
coordinates are 000, which means that the
object is in the center. Let's say that I
want to move it to minus three and y equals two, which will shift the
whole coordinate system minus three squares
from the center here, two squares, to
somewhere over here. I could also achieve pretty much the same thing by using
the two edge command. Instead of move to
the coordinates, I could say two underscore
edge and I'll say upper left. I want this scaled group
to move to the left edge. Let's see what happens. There's the coordinate
system, the dot, and everything shrinks
down to the upper left. But there is one slight issue, and that's the word dot. It's too big. We said
that we always want to redraw the dot label,
which is the word dot. And we said that the
font size should be 24. No matter what happens,
it will always update to the font
size equals to 24. This is why I chose the
harder way of doing things so that I can show
you how to fix this. See, there's another
very cool command that lets us clear updators. After some time, I
needed this dot label to be always redrawn
up until this point. But I don't want it to
be redrawn anymore from this point because I put
everything in a group already. So I don't really need to redraw anything because I'm
animating the whole group. What I can do is
name the variable, say dot underscore label, and then say period and clear underscore updators
and empty parentheses, which will now
clear the updators. It will remove the always redraw thing from the dot label. Now once I play
this, it will say text object has no
attribute, clear updat, I forgot to add the S at
the very end our variable, which we want to clear
the updators from. And then period
clear updatorsow. If I play this, the
dot label should be the same size as everything
else. Here's the axis. The dot moves there. The dot
label doesn't get redrawn to be font size 24 because
we removed the updators.
45. RECAP - Axes 2: Once again, let's pause and
see what happened here. I'll make it smaller so that you can see most of the code here. First, we created the axis. And we named our axis. Axis. But just with
the lower case A, I could have said anything here. I could have named
my axis shrek. Which means that I would need to change every single word, axis here to the word shrek. But I chose to name it Axis. I said that my X range is
equal from minus one to ten, which means that the
horizontal line, this x line over here, goes from minus one to ten. Then I said that my Y range
is from minus one to ten, which is this vertical line, and it goes from
minus one to ten. I said that my x
length is equal to 13. This basically defines the size of my x axis on the screen. If I were to say
it's equal to five, look at what happens
to the x axis. It will shrink down. See now it's very tiny. When I say 13, it means that
I want it to be the size of 13 squares that make
up or seen in Manum. Remember it's eight by 14. The reason I didn't say 14 is because it will
go out of bounds. The minus one or the
ten will be hidden. What I also did inside
of the axis was say that equal to false. And that's why we don't
have those arrows at the very end of
our y and x axis. Then I said period,
add coordinates, which added these numbers
to every single point. And I said set color to blue, which made the axis color blue. Next, I said that x
is equal to axis, Get x, axis label, and x, which basically
means that I want to add an axis label to the x axis. And I said that the
axis label will be x. If I changed this to
something like this, the label would have
been this text. There you go, I'll
switch it back to x. This basically helps
us name our axis. Of course, I needed to put
everything on the screen, and that's why I
said self dot play, right axis, which put
the axis on the screen. Self dot play, right x, which wrote the x label, because I assigned my x
label to the variable x. And I said right y, which put y on the
screen as well. Let me rerun this so that the text doesn't happen anymore. The next thing I did
was create a dot. And I said that I want to
move it to these axis, which we only have one
axis on the screen. So we didn't really
have a choice to put it inside of other axis. But if I had two axis, I could have said which axis
to move this dot inside of. I said axis two, which is just the syntax to define the coordinate
of the axis. And I said x is equal to
three and y is equal to one. Which means that I want to draw my dot inside of
this exact point. X is equal to three
and y is equal to one. The dot should appear over here. If I play this, the
dot is exactly there. Now another thing I created
was this dot label. I said that the dot label
is equal to this text. The text should say dot, and the font size should be 24, and that's why the
dot is this size. Next, I said that I want this
text to be next to our dot, which the dot for me is dot, and I want it to be up. So that's why the
label is on top of the dot and not somewhere
here, here, or here. I also added an updator to this label and I
said always redraw. Then I put everything inside of parentheses, inside
of parentheses. I also said lambda, which basically means
that it will always redraw the label no matter
where the dot goes. It will always try to set
the text dot to font size 24 and it will always try to
be next to our dot and up. No matter what
happens to our dot, no matter where it moves, no
matter what size it becomes, the text dot will always
redraw itself to be font size 24 and to always
be next to our dot up. Then I said self dot
play, right, dot label, and write the dot which put our dot and the dot
label on the screen. Then I said that I want to move my dot somewhere over here. Again, I used the
self dot play command and said that I want
to animate the dot. Remember, the dot label will
always be next to our dot. So that's why we don't need
to animate both of them. Wherever the dot goes, because of the always
redraw function, the label will always
follow the dot. I said dot, dot,
animate, move two. Again, I used the same
syntax as over here. I said that I want to
move it to these axes. And the I want to move it to x equals nine and Y equals six. X equals nine is over here, and y equals six is
somewhere over here. The dot should move
somewhere over here. When I play this, the
dot moves exactly there. Next, I wanted to
scale everything down, but in order to do
that, I needed to clear the updators
from the dot label. The reason I want to
clear the updators, which essentially just removes this part of the code
from this point onwards, is because if I didn't, it would always redraw the
text to be font size 24. And I want everything to shrink down as well as the dot label. I don't want it to be redrawn, to be bigger than
everything else. That's why I cleared Pdators. From this point onward, it will not redraw the.it will
just stay as it was next. Since I want to scale
everything down, I don't want to animate
every single thing. What I can do is
put everything into a group and animate
the whole group. Instead, I put
everything into a group. My axis, my axis labels
the dot and the dot label. And I said cells do
play group animate. I wanted to scale it down. I said scale 0.3 The default
scale is of course one. Essentially, I said
that I want to scale it to 30% and then I added another dot and said that as well as scaling it down, I want to animate it, moving to the upper left edge, and so this is the
animation that we got. There's the axis,
there's the.it, moves over there,
and then everything shrinks down to the
upper left corner. Okay, I hope
everything is clear.
46. Axes 3 - Creating the axes: Next we'll talk
about how to draw an actual curve on the axis. Let's create an
axis and then plot a cosine function
onto those axis. I'm going to move
everything down here and create a new scene. And I'll call it
axis three because this is the third lesson
in the Axis series. Then of course, deaf
construct self, we can start working
on this new scene. I'll move everything
down as well. Of course, don't forget
to indent your cursor by two times so that
everything lives under deaf construct self VS. Code automatically understands that I want to move it
here and not here. As soon as I press Tab once, it immediately gives me two
indents, which is very nice. Let's create our axis. This time I'm going to call
my axis something like dog. I'll say that it's
equal to axes. And then I'll
define the x range. I'll say that it's equal
to minus eight to eight. Whoops, I forgot the brackets. And then one more bracket
to close off the axis. Then I'll put the
comma here and say y range is equal
to something like -1.5 to 1.5 because the cosine function will
only reach to y equals one. We don't really need to go
higher than that anyway. Let's also add x length, which determines how long
the axis is on the screen, and I'll say 13. And also let's say y length is equal to something
like three, because I don't really
want the coordinate system to be super tall vertically. Then I'll also say
tips equals false, which will remove the arrows
at the end of our axis. This is what we have right now. I'll say self dot play. Right? And axis. I can immediately see that
VS code underlined the word self which tells me that there's probably a mistake
somewhere over here. And I can see that
the mistake is here. I said Cephal instead of self. It's just a spelling error. And once I corrected it, the self function
will work just fine. I'll also add self weight for
3 seconds at the very end. So that I can pause the
animation without it restarting. I'll run the python file. And it ran the previous
scene, axis number two. And this is axis number three. So if I want to
switch the scene, I can click on this camera
icon and say I want to play axis three
instead of axis two. Say that there is type object. Axis has no attribute
family members with points. I have no idea what that means. I'll try to troubleshoot this. The X range seems good, Y range seems good. X length 13, Y length is
three tips equals false. Everything seems to be in order. And I said that I
want to play axes, but I named my axis the word
dog. That was the mistake. I have to say write dog for it to write out
axes on the screen. I'll play this again and
let's see what happens. There's our axis, but
it doesn't look like an axis because it
doesn't have labels. Also create labels X underscore. Lab, which is label
is equal to dog, which is the name of our axis. Get underscore and then
I can choose this, Get x axis label. And then inside of parentheses
and quotation marks, I can say what I want
to name this axis. I'll say x axis. Then I'll copy this pasted here, Change the name of the
variable to be y label. Then say get y axis
instead of x axis. And I'll name this y axis. As well as writing the
axis on the screen, I will also write the x label and the y label on the screen. That every once I played the animation I got
another error type error. Math text object
is not callable. I'm assuming that I have
to put all of these into separate right animations. X lab and right Y lab. Let's see if that fixes
the problem. Yes, it does. Okay, Here's the axis, and there are the axis labels. I should have probably
said y x not axes. This is the final result. Now I will remove the word axes because it's probably
not necessary.
47. Axes 3 - Plotting cosine function onto axes: The next thing that
we want to do is draw a cosine function onto these
axes. How do we do that? I will come here after the
self dot play command, because we want to plot
the cosine function. After we've already put
everything on the screen, I will call my cosine function just curve. I'll say
that it's equal to. Then I have to put the name
of my axis, which is dog. Then I have to say
period and plot. This tells Python that I want to plot something onto these axes, these axes over here. Then inside of parentheses, I have to define the function
that I want to plot there. Since we want to plot
the cosine function, we're also going to need
to import another library. Remember that at
the very beginning to set up our manim thing, we said from maim
import snowflake, and this imported
the manim library. Now for the cosine
function to work, we also want to add another
library called num pi. I'll say import num pi as P. This is essentially all you need to do for the
cosine function to work, and also for the sine function
and many other things. But I will not talk about the num pi library in discourse. Let's plot out the
cosine function. Now to do that, we're
also going to use the lambda function inside
of these parentheses. Over here I will say
lambda x, then a colon. And then after that, P, which is this numi
library period, cosine x. I will explain
what this means in a second. I just want to
double check that it works self dot play, right? And curve that it plots
out the curve here. I will run the code, and there should be a cosine
function here. Yes.
48. Understanding how lambda functions work (my method): I'm not going to
lie. I don't really understand how Lambda
functions work, and I tried to figure
it out before, but as soon as I don't use them for one day, I forget
how they work. But I found a very
easy way to think about them when you're
trying to create a function. Let me open up Photoshop
and illustrate what I mean. Here's the syntax for
the lambda function. Lambda x, and then there was np dot cosine x. This
is the syntax. Now when you have
a normal function, you would say f of x or
y is equal to cosine x. This is how a normal
function would look like, which is also the same
as y equals cosine x. We can see some
similarities here. The main similarity
that I want to show you is that lambda x and a colon is essentially
the same as f of x is equal or y equals. You can basically
think of lambda x as being f of x or as
being y equals. This is exactly the same. Now what comes after
the colon is what comes after the equals sine
In a normal function, the cosine x is the same
as the cosine x over here. The only difference is that
we have this P over here, which basically tells
Python that we want to use this library to use
the cosine function. The P part is really the only difference when
it comes to this and this. Because this over here
is the same as this. Which is the same as this. This over here is the
same as this or as this. The only thing that's
different is P. Now let's say I want
another function instead of a cosine function. Let's say I want a parabola. The way I would
write a parabola in programming terms
would be lambda x, which is f of x is equal to the traditional parabola
is just x squared, which is the same as x times x. In a normal function,
it would be x and then squared like this. This is the same as this, because x squared is x times x. And this part over here
is the same as this. This is how I think
of lambda functions. I'm not sure if it's
100% correct or if this is how you should think about it, but
it works for me. If I say x times x, it should draw a
parabola on these axes. Yes, there is the pabla, I'll leave this
as P cosine of x. Now, there are also a couple of things that we could do here. First, I can say
that this curve, this cosine function,
will have a color red. And also I can add
coordinates to my axis. I'll come to the end
here and say period, add underscore coordinates,
which will add coordinates. Of course, don't forget the empty brackets at the very end. Now if I play this, the
cosine function should be red and there should
also be coordinates, which is exactly what we get. That's how you can plot
different curves onto the axis.
49. Axes 3 - Animating function on axes: Next. Once we've added
something onto our axis, let's learn how to animate it. Let's learn how to show that
function changing itself. In this case, I created
a cosine function, but let's create a pabla
instead instead of P cosine x. I will
say x times x. You can interpret this as
y is equal to x squared. This is the function that we're going plot on the dog axis. Now since this is a Pabola, I want to change the X range and the Y range to show
more of that Parabola. Say that X range is from
minus four to four. And since this parabola
doesn't go down, I will say Y range is from
zero to something like 16. I don't want the
horizontal dimensions of the axis to span across
the whole screen. I'll say X length is equal
to something like five. And I want the axis
to go vertically, pretty much across
the whole screen. I'll say y length equal to 6.5 Remember that the maximum I can go is eight
because the scene in manim is made up of
eight by 14 squares. I'll also leave tips as
false and add coordinates. I'll also leave the axis labels, but maybe I'll make
them lower case. Then here everything
stays the same. Self dot play right,
everything out. There's our curve,
which is the parabola. F of x is equal to x squared. And this time let's
make it blue. Instead of using the
right animation. Let's play around a
little bit and use the create animation which
is pretty similar to right. Let's see how it all looks like. There is the parabola. We have the x axis with the
length of five, that's why it's this short. And then we have
the y axis going 0-16 as you can see, 016. And then we said that the
length of this axis is 6.5 which is why it spans to almost the
very top of the frame. But now that I
have this parabola here, I want to change it. I want to animate it
moving for example, instead of x squared, I want to become two x squared. And I want to
animate everything. This is where we're going
to use the value tracker. The first thing I know
that I will need is an updator because I want to
always redraw this function. Because when it changes,
I want it to be redrawn on the screen to
match what it changes. Of course, I will say
always underscore, redraw, put all of this
into parentheses, and then add a lambda function
at the very beginning. This will make this curve
always update on the screen. Of course, if I play this now, nothing will change because
I'm not animating anything. It will be always redrawn
in the same exact place. Let's animate it. I'll
come here to the function. And I said that I want to
animate it so that it becomes from x squared to
two times x squared. But I want to be able to change this number two to something
like number five or number 0.5 And this
is where I can use the value tracker at
the top of the curve. I will also create this
number as a value track. I call it number and I'll
say equals to value tracker. By default I want it to be one, because by default
I want it to be one times x squared so that I
get this initial pabla. Now, I need to put this
value tracker in here. I'll say number, which is how
I named the value tracker. And then after the period, I will say get underscore
value and empty parentheses. What will happen now is
it will look at whatever the value trackers number is
and put that number in here. Of course, I forgot the times
symbol to make it so that the function is equal to
my number times x times x. Now we have everything set
up, but if I play this, nothing will change because
that number is equal to one. And it also doesn't change. We get the same
initial parabola, but we can animate
that number changing. I'll say self play and then
number period animate. Because I want to animate
this number changing. And then I'll say set
underscore value. Inside of parentheses, I can
pick whatever value I want. I'll say two also. I'll say underscore time
is equal to two so that the animation happens over the span of 2 seconds
instead of 1 second. Now if I play this, it
should draw the parabola. And the Parabola
should get bigger. There's the initial pabla, and there it stretches out. Now let's stretch it back down. I'll copy this, come to a new
line and set the new value to be something like 0.1 And
let's see what happens now. You should draw the
original pabla, Stretch it out, and then squish it back down, just for fun. Let's copy this again and add another one to
where it stretches to 0.5 This is how our
final animation looks like. It stretches out, then
it squishes down, and then it stretches back
up just a little bit.
50. RECAP - Animating functions on axes: Again, what we've
done here is we added a curve and we added an
updator to that curve. We said that we always
want to redraw the curve, so that when we
animate it down here, it will always redraw the curve, it will always update it. Then we said that
we want to plot this curve onto the dog axis, which we created up here. Next, we needed to
define what kind of function we wanted
to plot on the axis. And I said that the function
is equal to f of x equals whatever number this
is times x times x, which means f of x times our random number
times x squared. This is essentially how our
function looks like, F of x equal to a number that we
choose times x squared. It's a Proabola, but it has some sort of a
number in the front. In the beginning we said that this number is equal to one. No matter what we
multiply by one, it still stays the same. That's why the original
curve stayed the same. And we said that the color
of this curve is blue. And then over here, we changed this number
to be something else. At first I said it was equal
to two since there's always redraw function which always updates our Pbola as
the number updated. The probola also updated
on the screen, Okay.
51. Axes 4 - Zooming into axes: Let's create another example
with the value tracker. And this time let's also animate the axis as well as the
function inside of those axes. Say class axis five and
colon deaf construct self. We have the scene prepared. I'll say that axis
is equal to axis. I want to plot the sine
curve onto these axis. I'll choose the x range to be equal to minus eight to eight. And then the y range to be equal to something
like minus one to one. I'll say that X length is equal to seven and Y length
is equal to three. I'll also remove the
tips from these axis. Say tips equal false and also add coordinates
at the very end. Let's see how these
axes look like. Self play, right? Axis. Whoops. This is playing our previous
scene, axis three. I'll go into the camera icon
and choose axis number five, which will update the
scene to be like this. The animation stops really fast, so I'll say self weight 3
seconds at the very end. And I'll continue
working on these axis. I said that I want to draw
a sine function here. Again, I'll name
my function curve and I'll say it's
equals to axis, whatever the name of
the axes is, plot. And then inside of parentheses, I have to define the function
that I want to plot. I'll say lambdx, which
essentially means y equals two. And then P sine x, which means y is
equal to sine x. And we've now plotted
this function. To draw this function,
I'm going to say self dot play,
create, and curve. If I play this, it should also plot the sine function here. Yes, I will also say
that the color of this function is equal to blue. So that you can
differentiate it better from the axis like this. Now we have the axis and we have the function on those axis. But what if I want to
zoom into these axis? In other words, what
if I want to change the x length of these axis
and animated, changing. I want to zoom into this
point of the curve. I need to somehow figure
out how to animate the x length from seven
to something like 30. And for that I can
use a value tracker. I will make some
space here and then say that my value
tracker is equal to X. I'll create
the value tracker and let's say that the initial
length will be the same. Seven, I'll say seven
inside of my value tracker. Now I want to replace this
seven with my value tracker. I'll say that I want my
X length to be X period, get underscore value
and empty parentheses. Again, my X is my value tracker. For my x length, I'm essentially
getting the number, whichever is inside of
this value tracker. Right now it's equal to seven. Which means that if
I re run the code, the function and the axis
should look exactly the same. Yes, they do. But now I
want to animate this. And what that means is
that I want to change the value of the x.
I'll say self dot play. And then inside of parentheses, I'll say x period, animate period, set
underscore value. Let's say 30. What will happen now
is it will animate the value tracker to
be set to number 30. But on our screen, nothing will be changing
because we forgot one thing, and that's to update
this function. We need to add an updator
to the function so that it always redraws the function when something is
happening down here. I will say always underscore,
redraw, open parentheses. Then of course, close the
parentheses at the very end. And I also need to include lambda and a colon
for it to work. Now, it will always
redraw the axis. Now if I play this,
everything should zoom in. Of course, it's going to take a little longer to load
because it has to redraw the axis for every
single frame of our animation. There's the axis, there's the
function, and it zooms in. But you'll notice
that this stayed in place and that's because
our curve is not updating. We also need to say always underscore redraw lambda and
then close the parentheses. Of course now everything should
zoom in together because the axis will be redrawn and also the curve will be redrawn. Yes. Now everything zooms in together and the function
is correctly displayed.
52. Axes 4 - Animating axes and function: Let's say that I also want to animate the
function changing. I want to zoom into the axes. And then let's say that I
want the sine function. Instead of having x
inside of parentheses, I want to have something like ten times x inside
of parentheses. I also want to
animate that as well. We'll create another
value tracker. I'll say that that
number is equal to my value tracker and the
initial number will be one. Because I want to display
the sine function, how it is by default at first, then inside of the parentheses I want to include this number. I'll come here and
say number period, get underscore value
and empty parentheses. And then I have to
times this number by x. Now, inside of our
sine function, we have this number which whatever number
this is times x. At first, this
number will be one. But I want to animate it, changing 1-10 Come
here, say self weight, because I want to wait a little bit After the zooming completes, then I'll add a new line and say self dot play numtanimate, because I want to animate
this number changing to ten. And then I'll say period
set underscore value. Let's set the value to ten. Since we already
made this function, always redraw, don't have
to add anything else. In theory it should work. It zooms in and then the
function changes very nice. Once I've squeezed
this function, I can say self weight
to wait for one more second and then I can
zoom everything back out. I'll copy this one because it controls how much we zoom in. And then instead of 30, I'll
say something like five. Now the x length over
here will become five. Remember it initially was seven, then we changed it to 30, and now we're
changing it to five. This is how it will look like. There's the axis,
there's the function. It out. It changes the function and then it
zoom back out. Beautiful.
53. Transforming matching shapes (cool animation): I also want to show you a few cool things that you
can do with, man. The first one has
to do with text. I will say that A
is equal to text, and let's say that the
text here is mammal. Then I'll create another
text and I'll call it B instead of parentheses and
quotation marks. I'll say man. And then of course, I'll add
a self dot weight command of 3 seconds at the very end. And I'll say self dot play. And I'll put both of these
texts on the screen. I'll say right and then right. Right now they're going
to be in the center. So I'll say this one is next
underscore two A and right. So it will be on the right
side of the text mammal. The text, the text manim will be next to the text
on the right side. If I play this, this
is what we get. Mammal mani, both
of them are not in the center because the word
mammal is in the center. And this one is just
next to the word mammal. That's why they're not centered. But the cool thing I wanted
to show you is if I add another self play
command and then say transform matching shapes. And then inside of parentheses, I want to transform A and B. I must have
spelled it wrong. Transform matching
shapes. There we are. If I play this, look at
what happens, whoops. But the problem is
that we already had the text written on the screen. If I only write the text
A on the screen and leave invisible the text A will
transform into text. With a very cool animation. Here we have the
text and then it transforms the letters
move into the text. I can say run
underscore time and set the time to be
something like 3 seconds. Also, I don't need
this next two command because this text is invisible. There's the first word and then the letters morph
into another word. This is what the transform
matching shapes does. Whichever letters match, they just switch places and
make another word. This is a very cool animation. We change this text to say something like Baboon. This one. This is my first day at work. Let's transform
everything from baboon. This is my first day at work. See whichever letters
are the same, they just move into place of the matching letters
of the second word. And the other
letters that are not a match just fade
in from nothing. But if I switch both of
them, this will say Baboon. And this will say, this
is my first day at work. If I read this, the animation
should look better. There we go. This is one cool animation
that I wanted to show.
54. Arranging multiple elements next to each other with a group: Coming back to the
problem that we had before where we had
mammal and manim. We wanted to write out both of these pieces of
text on the screen, but the problem was that both of these texts were not
centered on the screen. I said next underscore
two and then a right, which made the text manim go to the right side of this
at, this is what we got. They were not centered, how do we center
them on the screen? What we can do instead
of saying next two is put both of these
into a V group, I'll say is equal to V group, inside of parentheses,
I'll say A and B. Now I've put both of
them into a group. The reason I did this
is because I can arrange elements
however I want to. When they're inside of a group, I'll create a new
line here and say, which is my V group. Then say inside of parentheses, I can define how I can
arrange these objects. One way I can
arrange them is dow, which means that the text
B will be below the text, A manim will be below
the word mammal. Let's see what happens
if I play out the group. Here are both of these texts, but now they're
aligned in the center. If I want to align
them to the left edge, I can say here I can see that
center is equal to true. By default I can say
center is equal to false. Now if I play this, it should align to the left
edge. Never mind. What happened now is
the text mammal is in the exact center of the frame and the text
maim is below it. If I add a large buffer, you should be able to
see what happened. If I play this, the mammal
will be in the center. And the text maim is somewhere down here, somewhere
off the screen. If I say two, it's going to be somewhere over
here, probably. Yes. If I say center
equals false, it will arrange the V group in a way so that the first object, the center of the frame, and then any other objects that are inside of the group are arranged in relation
to where this one is. But that's not what
I wanted to do. If I remove the center here, the center of both of these objects will
be in the center. The text mammal should
be somewhere here, and the text manum should
be somewhere here. If I play this, you'll be
able to see that the text mammal is no longer in
the center of the frame, but the center of both of these objects are now
the center of the frame. But I wanted to do something
else and that's arranged both of these texts
to the left edge. What I can say is aligned underscore edge
is equal to left. Now it should align both of
these texts to the left edge. Now if I don't want to
arrange the V group down, I can arrange it to the right. This is how it looks like now. Probably I don't want to have
the aligned edge left here. Yes, now it aligned both of these text objects next to each other and both of them
are in the center. If I were to say
center equals false, then only the text
mammal would be in the center and the text manim would be somewhere over here. Because now the
center of both of these objects is not the center. The first object is the
center of the frame. This is how you can arrange
two separate texts or two separate objects
next to each other and put them both in
the center of the frame.
55. Animation 3 - Changing shape parameters: Let's try to replicate a scene
that will look like this and that's it. Come down
here and create our scene. I'll say class
demonstration three. Scene of course, add parentheses
and deaf construct self. As always, now we
have our scene. Let's go through
this animation once again and explore
what happened here. First, there's this
shape that gets created. Then there's one piece of
text colored orange or gold. And then there's another
piece of text in another color right
next to this text. Then there is a rectangle that's drawn around
the second text. And then the rectangle grabs this text and moves
it down here. As this is happening, this bullet point or this shape
moves over there as well. Then the square will expand and all of
these three elements will nicely move next to
each other like this. Then from here, everything
transforms into a tiny dot. The dot expands and
fades to black. Let's try to create
this animation first. Let's start
off with this. Here, as you can see,
there is a circle and then a surrounding rectangle
around that circle. I'll first create the circle. I'll say that C is
equal to my circle. And then inside of parentheses, actually I will put nothing
inside of parentheses, but let's see how
big the circle is, right from the very beginning, I'll say self dot play and then which will create
the circle on the screen. I'll also come here and
say self weight for 3 seconds so that when every
single animation has played, there will be a
three second pause. At the very end, I'll come
here and say Run Python file. And from the manium
side view extension I will be able to choose
the demonstration scene. I'll click on that
and it will generate. Right now, the circle is
this big, it's color. What we want is for the
circle to be very tiny. I'll come here after the
circle, say period scale. And I'll scale it
to something like 0.1 Now the circle
will be very small, but this circle also
has a fill color. And the fill color is white. I can come here say
period is my circle. And I will say set
underscore fill here. I can define what color I want. I'll say that the fill
color will be white. Then I can add a comma
and choose the opacity. I'll say opacity equals one, 100% The white in the center of the circle will be 100% visible. Let's see what we get.
This is the circle, but the outline in the animation
that we want to create, the outline of the circle. This right here is
a little thicker. I can also increase the
thickness of the outline. I'll say period set
underscore stroke, which will define the stroke for this circle
because I named it. Then inside of parentheses I can say what color I
want for the stroke. And here it's red. I'll say red even though
the circle is already red. And then I want to choose
the width of the stroke. I want to make it thicker. Let's see if there's
an option for that. There's an attribute
called width. I'll say width equals, I'll set it to
something like seven, I believe by default
it's set to one. Let's see if the
circle is the same. Yes, the circle looks
pretty much disabled.
56. Animation 3 - Creating the surrounding rectangle: Next, I want this rectangle with rounded corners that
surrounds the circle, create a surrounding rectangle. I will assign the
surrounding rectangle to the letter and say that is equal to surrounding rectangle
inside of parentheses. I have to say what I
wanted to surround. In this case, I wanted
to surround the circle, which is the letter C for me. That's why I'll put C here. Then I'll add a coma. And say that the color of
this rectangle should be red because by default it's
yellowy color equals red. And then I want the
rounded corners. Remember the attribute for rounded corners is
underscore radius, and it immediately fills it in. So I'll click Tab, and
I'll say that it's equal to 0.1 Now we have the circle and the
surrounding rectangle that surrounds this circle. But I haven't yet
told VS code to put the surrounding
rectangle on the screen. I'll come into the self dot
play command at a comma here. And I'll say that I want write the surrounding rectangle
as well as the circle. Now if I play everything, both of these shapes will
appear on the screen. But in the animation that
we want to recreate, these shapes appear
in different ways. If we look closely, the rectangle spins
in from the center. Instead of using
the right command to animate these
shapes on the screen, I'll use the grow from center
command for the circle. And I'll use the spin in from nothing command for
the surrounding rectangle. And this is what
we get. It looks exactly the same as
in this animation.
57. Animation 3 - Arranging objects: We can see that there are
two words, hello there. Let's create those words. I'll assign my text
to the variable and say that text is
equal to hello there. Now, both of these pieces of
text have different colors, which means that you
could use text instead of text and then use latex
to format that text. But I'll show you how to do that by just using the text command. But first, in the animation
that we want to make, the text is next to this shape. If I were to put this
text on the screen, it would just appear in the center overlapping
with the shape. I want to put it
next to the shape. I'll say next underscore two for text because
I've assigned my letter to my text and I want it to
be next to the shape which is either the circle or the surrounding rectangle.
It doesn't really matter. I'll say the circle and
I'll put a comma and say which direction I
want the text to go. I wanted to go to the right. I want my text to be next to the circle and I want it
to be on the right side. Next, I'll say self dot play. Right my text to
also put the text on the screen. And there it is. But the text doesn't really look the same as in our animation. The font is a little too big and also everything
is off center. First, I'll decrease
the font size. I'm not sure what the default
font size is by default, but I'll say font
underscore size is equal to 32 and the text
should become smaller. Yes, next, I want to move everything here into the
center of the frame, because right now
this shape is in the center and the text
is off to the right. What we can do is put
all of these objects in a group and then align that
group to be in the center. I will come here and put
everything in a group. I'll call this group one. There will be multiple groups. I'll say group and then
inside of parentheses, I'll put everything that
I want into that group. Now if I put every
single object that I've created for the circle, for the surrounding
rectangle and for text, I will then align all of
them in a single line. Because it will first
put the circle, then it will put the
surrounding rectangle, and then it will put the text. But I want the circle and the surrounding rectangle
to stay together. That's why I'll put them in a separate group so that when the second group aligns itself, this group will count
as just one object. Say that the second group is equal to V group
and then I'll put the first group inside of the second group as
well as my text. And then I'll say two, which is the second group. And then period and arrange which means that I want to
arrange the second group. Now here I can define which direction I want
it to be arranged, but the default direction
is to the right side. I don't really
have to say right, I can just leave
empty parentheses. Also, I can define
the buff value, but in this case, I'll just
leave everything as default. Now if I play this, everything should be in the
center of the frame. Yes, but it teleported. And that is because I
first said self play. Put both of these
shapes on the screen, which put them in the center. And then I arranged the groups, which means that I first need to arrange all of the groups
and create the text. And only then put
everything on the screen so that it already plays
what's been arranged. First we arrange the groups, and then we play the
things on the screen. Because if we did it
from the other side, first it puts whatever's
on the screen, then it arranges those objects and then tries to play them, and that's why they teleport. Now if I play this,
everything should appear nicely in
the center. Yes.
58. Animation 3 - Changing colors of multiple words in a Text object: Next thing we can see
here is that the text has different colors and
even a different font. Let's first start
with the color. I'll put some space here. Remember from before that you
can separate text by using the text command instead of text which formats your
text in latex. Which essentially means that every single text
piece that you create, so one text inside
of quotation marks, and then if I put another text
inside of quotation marks, counts as a separate object. If I say self dot play, right? And then two, which
is this text for me. And then inside of brackets, I can define which
object I want to show. This is the object number zero and this is the
object number one. If I only say self play right, object number zero, it will
only put hello on the screen. It will not put
there on the screen. I'll move this next to my text down so that
it appears over there. If I play this, it
will say object has no attribute next to I
put it in the wrong spot. I should have said it's
here next to my text. Here, it's typed out
only the word hello. But when you're
using normal text, text like this with
a not text but text, you can't really create
multiple quotation marks with text inside of them. Let's see what
happens if I do that. If I say dog here and
try to play this, it will say could not
convert string to float dog, which means I can only put one quotation marks inside
of the text command, but we can still color
this text separately. You see in this case,
each of the letter will have its own number
inside of the array. The letter H will
be number zero. The number E will be number one. The letter L will be number two. Another letter L will
be number three. The letter will be number four. If I wanted to only write out the word hello
and not there, I would put brackets
next to the letter, because is our text
Inside of brackets, I could define which elements of that array I
wanted to print out. It starts from zero,
so I'll say zero. Then I'll add a colon. And remember that the
last number you put here doesn't actually
get written out. If the number of the last
element, the letter, is number four,
then I have to put number five here again, 01234. If I put five, the
fifth element, which is this space here, will not be put on the screen. And everything from number zero to number four will
be put on the screen. Now if I play this, only the
word hello should appear. In the same fashion I can color each of these
pieces of text, I'll say. Then add brackets 0-5
which is the word hello. I'll say period, set
underscore color, and I want it to color gold. I'll say the color will be gold. And then the remainder of
the text will be brackets. And then from the number
five up to the very end, have to define the last
number if I just put a colon and then nothing else after it, it
understands that. I mean from the number five up to everything
else that's remaining. I'll say period, set color, and I want the color to be tal. Inside of parentheses,
I'll say tal. Now, both of these pieces of text will have different color. Inside of the self play command, I forgot to remove the
brackets so that it plays out the full text here, Hello is in one color
and there is in another.
59. Animation 3 - Changing font of Text object: Next, comparing both of
these pieces of text, it's obvious that this
one has a different font. Compared to this, you
can also set a font. Now inside of Cues, you can find the name of the font that you
want to use and that you have installed inside
of an app called Font Book. Open the Font book,
I will be able to see all the fonts
that are available. And if I want to use
the Georgia font, for example, I will just
have to remember its name. In this case, I want to use
a font called Sentient. I just have to find
out what kind of fonts I have installed and what's
the name of the font. I'll come to my text,
add another coma. And I can see that one of
the parameters is font. I'll say font equals to, and then inside of
quotation marks, I'll tell it the font name. For me, it's sentient. Now, the font of this text
should turn into sentient. Yes, the font is
different and we've successfully recreated the
beginning of this animation.
60. RECAP - First half of the animation 3: Let's quickly pause and run through what
we've done so far. First, we made a circle. We said that our
circle is equal to the letter C and it's this circle right
here in the center. Then we said that we want the
fill color of the circle to be white and the opacity
of that color to be one. Which means 100% which put this white color
inside of our circle. Because of opacity equals one, this color is visible
to 100% We also said that we want our
circle to have a stroke, which is the red line
outside of the circle. We want the line to
be red and we want the width of this
line to be seven, that's why it's a
little thicker. Then we created a
surrounding rectangle that surrounds this circle. Surrounds the circle
because we put C over here. We told it to
surround the circle. Then we said that the color of this rectangle is red and that the corner radius is 0.1 which created
these rounded corners. Next, we wanted to put text Hello there next to this shape. First we made the text. We said that the text is
equal to text Hello there, which is the same
text as over here. The font size is equal to 32. And then we picked
a font that we already have installed
on our computer, found out the name of that font, and said that the
font of this text will be equal to that font. Next, we put this text next to our circle, next to the letter C,
which is the circle, and to the right side, that's why our text is on the
right side of the circle. Next, we said that
we want to color the first four
objects of our text. And I say four because the fifth one
doesn't get affected. Everything from
the object zero to the object four
got colored gold. And every single letter in this text is a separate object. The letter H is number zero, then 1234, every single letter of the word hello
got the color gold. Then we said that we
want every single object from the object five
onwards to be colored and the space is
the fifth object. Everything from the space
onwards got colored tal. That's why the
text Hello is gold and the text there is tal. Obviously, the
space doesn't have a color because it's
just empty space. Next, we wanted to arrange
everything so that everything is in the center of our frame and not off
to the right side. First, we created a
group called G one. And we put C, which
is the circle, which is the surrounding
rectangle, into a group. Now both the circle and the surrounding rectangle
counts as one object. Then we created another
group and put that object, G one, which is the circle, and the surrounding rectangle
which is now one object, that group and also put
text into that group. Inside of the second group, we have this shape as the first object and the
text as the second object. And then we said that we want to arrange the second group to the default parameters
which is to the right side and in
the center of the frame. That's why everything
is in the center. And then I said that
I want to play and show everything that
happened on the screen. That's all that
we've done so far. Let's move on to creating
the rest of this animation.
61. Animation 3 - Shifting things by decimal numbers: Let's continue building
out this animation. This is what we have right now. We have the spinning shape and then the two words, hello there. Now the next thing we want is a rectangle around
the word there. Now, there are a couple
of ways to do this, and the easiest one
would be to just create a surrounding rectangle
around this text over here, around five to everything
which means around this word. But I'm going to be
doing it the hard way to show you
one little thing. Instead of creating a
surrounding rectangle, I'll just create a square. I'll say that my square
is equal to square, and inside of its parentheses, I can choose the side length. And I'll say that my
side length is equal to 1.2 And now I want to put the square on the screen
to see where it lands. So then I can adjust it and
put it over the word there. Come here and say self
dot play, right square. And let's run this, and
let's see what it gives us. It says it got an unexpected
keyword, argument, side length, which means that I've misspelled
the word length. Once again, I'll say
length and it should work. Yes, we're okay. Now we have the text and then the
square is in the center. I want to shift the square over here so that it's
over the word there. Now, there are also a
couple of ways to do this. One is by getting the
center of this object. But this time I'm
also going to do it the hard way, the manual way. And I will try to
figure out exactly by how much I need to shift
the square to the right. Now. Luckily, I've already done that before when I was preparing for this lesson
shift right times. And then this is the reason why I wanted to put the square here. I wanted to show you that
you don't necessarily have to shift something
by whole numbers. Remember, the scene
in manim is made up of eight by 14 squares, and for a while I was thinking
that's little squares. What if I want more squares? Well, it turns out
that obviously you can shift something
not by a whole square, but by a fraction of a square. So I can shift
something by 0.5 or 0.005 or 0.42 069 or something. That's why I did
it with a square and not a surrounding rectangle. Just to show you that you
can shift something by 0.955 and it will end up
exactly over the word there. Keep in mind that you don't
have to shift something by whole squares or whole
coordinates, whole numbers. If I said move underscore two and then added
a coordinate here, I don't have to
say y equals one. I could say y equals
1.42 069 or something. And it will shift it
to that coordinate? It should shift
it somewhere over here at the top.
Yes, over there. That's the thing I
wanted to remind you of. But since we already
have the square, let's continue animating with the square instead of a
surrounding rectangle.
62. Animation 3 - Repositioning objects.mp4: The next thing that happens is this square picks up this text, and then both it and the
text move down here. This shape moves from here
to on top of the word hello. Let's first work on the
rectangle and the text. Of course, to move
them together, we're going to create a group
of both of those objects, the square and the text. I already have two groups. I will say this is group number three is equal to V group. And I'll put my
square as well as I want this piece of text
to end up inside as well. Remember, I can
separate this piece of text into two with
this type of syntax. It'll say I want my text, then the letter is the
01234566, so I will say six. Or actually, I can also
include the space, because that doesn't
really matter. So I'll say five and a
colon, which means that, as well as including
the fifth thing in this array,
which is the space. I also want to include everything else that
comes after it, the whole word there. Now this is inside of a group. Now let's move the group. I will say self
play group three, which is the group that
we just created next two. Then I want to put it next
to this text over here, Next to the text hello. And down the text hello
is bracket zero to five. Then I want to say
down after I put a, it will put my group, which
is this rectangle over here. And the word there next to
the word hello and down, it should end up over here. Let's run this and
see if that happens. Hello, there. Yes, it moves
to the correct location. But at the same time
that this is happening, I also want to move this shape over on top of the word hello. I'll add a comma inside of
the cell play animation. And I want to find
the group where I've grouped both
of these shapes. And I think that's
group number one, C. And C is my circle and is
my surrounding rectangle. That's group one. I will say
G one period animate period. Move underscore two
inside of brackets. I have to say where I
want to move it again, I want to move it on
top of the word hello. Again, this is the word hello. I will copy this
and paste it in. I'll say and because this time I want to end up on
top of the word hello. And if I run this, both of these shapes should move
into their places at the same time, never mind. That is very weird that this happened, some
unexpected behavior. I said, I want to move G
one, which is this group. Instead of next two, I accidentally said move two. I should have said
next underscore two. If I run this, everything
should be okay. Hello, there, moves here, and the shape moves
there. Perfect.
63. Animation 3 - Scaling and moving objects: Let's see what happens next. Now the square gets bigger
as well as this text moves closer to the word
hello. Let me play that again. The square gets bigger. This text moves
closer as well as it seems that everything realigns themselves into the center. Every single shape here slightly moves over to
the center of the frame. Yes, first let's make
the square bigger, and let's make it move to
the center of the frame. I'll come here and add
another self play command. And now I want to
animate the square, which I've called square. I'll say square period animate. And I want to make it bigger. I will say kale. And inside of
parentheses I have to say by how much I
want to scale it. I'll say three, which
means three times. Then I also want to move the square to the
center of the frame. I will say period,
move underscore two. Inside of parentheses,
I will say origin. Origin basically means
the center of something. In this case, it's the center of our frame of our
whole animation. The square is going to align
itself in the exact center. Let's play it and
see what happens. There's a square and yes, it looks like it's
in the center, but all of these things
aren't yet in the center. Let's first move these
two to the center, the shape and the word hello. Also in the animation, everything happens
at the same time. That means I have to use one self play command.
Add a comma here. And now I want to animate
both of these shapes, shifting to the origin
or to the center. Luckily for me, I've
already put both of these shapes in a group
which have called G two. I don't have to create another group to put them together. Two period animate,
move two and origin, which will move these
two to the origin. If I play this, both the square and these objects are
now in the center. There's one thing remaining, which is the word there in the animation that
we want to recreate, the word there is next to
the word hello and down. Let's move it from over
here to over there. I want to move only
the word there, which is this word here. Which means, again,
I have to specify that I don't want to
include the word hello. I will say, and
inside of brackets, I will say I want everything from the fifth object onward, five, and a colon. Then I will add a period. I'll say animate period, Move underscore two and origin, which will also move
this text, the origin. It should end up
somewhere there, but it will not be
below this text. Let's see what happened anyway, to understand how much
we need to move it down. Yes, both of these
texts now overlap. What I can do now is
add another command. And as well as moving
it to the origin, I can add another
period and say shift this object down by something
like 0.3 If I play this, the text should end up
nicely below the word hello. There it is. We recreated
everything up until this point.
64. RECAP - Scaling and moving objects: Remind you what happened here. We first said that we want to animate the square to
scale number three, and we also want to
move it to the origin. That's why the square
becomes bigger, and it also moves to the center. Then we said that we want
to animate the G two group, which for me, is
this group which houses the first
group and my text. The first group is essentially this shape and the
text is hello. It means that I want to move this shape and the
word hello somewhere. Where did I move
it to the origin, which means to the very
center of the frame. Finally, I wanted to move the text there next
to the word hello. But at the bottom of
it, first I said I was targeting from the
fifth element. For me is my text and the
space is the fifth element. I was targeting everything
from the space onwards, the space and the word there. Next, I said that I want to
move this text to the origin, again to the center,
since there was some overlap between
the word hello. And there I also shifted
this word down a little so that it nicely
rests below the word hello.
65. Animation 3 - Creating a dot and fading out: Let's see what happens next. Then everything morphs
into a tiny dot, and the dot expands into a white color and
then fades to black. Let's create the dot. I will name it dot. Then I will say it's equal to
dot and color equals white. Now since the dot
was pretty tiny, I'm also going to add a
scale attribute and say that its scale is 0.5 or
50% We have our dot. Now we want everything on the screen to merge
into this dot. What that means is that we
want everything that's on the screen to be
counted as one object. To do that, we can, of course, I will say four, which is group four
for me, group. Now, inside of parentheses, I can either put every
single object that I've created or I can use groups that I've also
already created. I have a group for the text. And this shape, I'm going to use this group
inside of the group. And then it leaves
only the squarre. I will put the square as well. And then to transform
everything into the dot, I will say self dot
play transform. Here I have to put
from what to what? From group four, which is every single object
on the screen, to my dot, which is the dot. Let's see if that happens. Yes, everything transformed
into a tiny dot. Now in the animation that
we want to recreate, this dot becomes super big and white and then
fades to black. So let's do that next. After the last self
dot play command. I'll also include
self weight for 1 second so that the dot stays on the screen
for a little while. Then I will say self dot play. Inside of parentheses,
I will say dot period, animate
period, scale. And let's say
something like 300. So I want to scale
this dot by 300 times. And finally, I want to
color the dot black. It fades to black. I will
say dot, dot, animate dot. Set underscore color. And we'll set it to black. And let's see what happens. So we've successfully
recreated this animation.
66. Creating a Manim config file: As we were creating all
of these animations here. Every single scene that we have created and run
with Python has of course been saved
on our computer in the direction where we
saved this nim demo file. So for me it's under
desktop and course demo. And if I go to my desktop, I'll find my course demo. And inside of it I'll
find the media folder. If I go into the media folder, then videos, Nim demo and ADP. All of the scenes that I've created
throughout this course will be in this folder
in ten ADP resolution. But what if I want
every single scene to be four K instead of ten ADP? Well, in that case, I can create a Im config file or a
configuration file. I want this config file to
live in the same location as my Python file where I wrote all the code for
my num animations. For me it's inside of
desktop and course demo. Now I can create
this file manually, but an easier way to do that
would be through VS code. I will come to my VS code, go up to file, and
choose new text file. Or I can click command or Control on my
keyboard, new file. And then I will hit
command on my keyboard or control on Windows to save
this file as a conflict file, as a CFG file, I'll say command S
because I'm on Mac. And then I have to
make sure that I'm in the same directory
as my manim file. The file where I wrote
all the animations. And by default, it should
take you to this location. If you don't see your
Python file in this folder, you have to find it and save
this file right next to it. Another important
thing is the name. Name it, manimtfg. Don't forget this CFG part. It's also important
if I say safe, I've now successfully
created my CFG file. You'll see that the icon of this file has turned
into a gear icon. And what we can do with
this CFG file is set various different configurations
for our manimfile, or how manim works. One thing that we can
do is set the quality.
67. How to set 4k output quality: To change the output
quality from ten ADP to four K. I'll have to add these
two brackets and say CLI. Then click Enter and
say Quality is equal to four K Underscore Quality. This is the syntax
that you have to use. I'm not sure why
they made it four K underscore quality
instead of just four K, but you have to say four K quality. And also
you have to put CLI inside of brackets
at the very top. Now if I save this file with command or control S on Windows, go back into my num demo, which is the file where
all of my code for the animations is and then
rerun one of the animations. For example, demonstration
number three. It will now render it in four K quality
instead of ten EDP, four times better quality. Of course, it will
take a little longer, but now if I go into
my desktop and go into my course demo
folder, go into media. I will see here that there's
a new resolution available, and this is four K. If
I expand this folder, I will find my scene
that I've just run. And this is the same
demonstration scene, ten DP quality. So with the CFG file, we've just configured that for every scene that we run
from this point onwards. Each of them will
have four K Quality instead of ten ADP,
which is very nice.
68. Other settings inside Manim cfg file: Of course, there are many
things that you can put inside of the CFG file, but to find out
what things you can put inside of the CFG file, you can come here
inside of the terminal and say manimCFG, right, and then minus,
which will create a CFG file in place of your CFG file with all
the available commands. And if I click Enter, here are all the
available commands inside of the num conflict. So I'll close my side view. And this down there at
the bottom and here are all the things that
you can configure. For example, you can change
the format of the video. You can choose the
background color, which by default is black. Let's say something like orange. So if I save this and
rerun one of my scenes, let's say the same scene, it should have an orange
background instead of black. It said that the predicted
output file does not exist at the location. Let's go and see
what happened there. Let's go into this folder. And for some reason it
didn't understand this file. But we can already see that
the background is orange. This animation plays on
an orange background. Also, if the maim
side view extension doesn't find your animation, you can always find it
inside of this location. Wherever your Python file is, there will be a
folder called media, and inside of that media
you go into videos, you go into maim
demo and then pick the resolution that you render in and the video will be there. Now the background is
orange, of course. It looks pretty bad, so I
will change it to black. Can change many different things here that I'm not
going to go over and I haven't gone over in the past because I simply
didn't really need to. When I make videos with Nim. I only leave one option here, which is this quality
equals four K quality. What I usually do is
just delete everything apart from quality
equals four K quality, and leave only CLI and
quality equals four K, which renders all of
my animations in nice, crisp four K quality. If you want to change it back to ten ADP quality instead
of four K quality, you can say high
underscore quality, which I believe will
change it back to ten ADP. If I play this, it
should generate this animation at
ten ADP resolution. Yes, if I click this arrow next to Details in the num side view, I'll be able to see
the output file. And I can see that
it's under ten DP, which means that high
quality is ten ADP and four K quality
is four K quality. I'll change mind back
to four K quality. Also, you can create a CFG file for every single Python file
that you're working with. You don't have to say that
all of your projects in the future will
have four K Quality or some sort of a setting. Inside of the num CFG file. You can create a
new CFG file with every single Python file that you create
on your computer.
69. Conclusion: That's the end of this
course. We've gone over all of the
essentials and most of the concepts that
you need to start creating beautiful
manim animations. If there's one thing I
hope you take away from it is that you really need
to get your hands dirty. Experiment with code and
try to build something yourself in order to learn and retain the
information best. That's what I'm
encouraging you to do. Install Nim, set up via
code and build code learn. The best way to learn is
by doing it yourself. The dopamine rush that you get when you encounter an error. Then search all of
Google, read it, stack overflow, or the manim community
website for how to fix it. And you finally figure
it out by piecing together three comments you found on three
different websites. Feeling is amazing
and it encourages you to build better, more
beautiful animations. At least that's how
it works for me. So thank you again for embarking
on this journey with me and I'll hopefully see you
in one of my other courses.