We explore all kinds of technologies, starting from programming, electronics ending in the photography sector. A bit for everyone.

Monday, December 18, 2017

Animation engine for explanatory math videos -- The Manim

UPDATE: This is an out-dated tutorial, I'm sorry. I'm working on new tutorials...

 
Hi!


I want to make animations for explaining programming concepts and, of course, upload them on my YouTube channel. Watching 3Blue1Brown's YouTube videos, I was wondering how does he make them? If you don't already know, he has a animation engine that he built with python. NOTE: Don't rush it, you are going to have a lot of problems if you do so. Here's the link to his GitHub repository.


one more NOTE: It's going to take you a fair bit of time (couple of hours) setting and learning things up. So, first ask yourself is it worth it! Not saying to discourage, but to warn...

In the process of actually starting it, I downloaded it in my Python27 installation folder (btw, for this to run properly, you need Python 2.7 not the newer 3.6 version). When installing Python, is a VERY good practice (and that's what I did for this tutorial) to add it to the environment path variable (just google - add python to path). When you have downloaded Python27 and the Manim project folder, you can see the required modules for running it in a text file called "requirements.txt". You can see there all of the versions of the modules that are necessary. Here's the catch. You will have a lot of issues with it.

First of foremost, you need to have pip installed, because pip doesn't come with Python27.
The easiest way to install pip (and that's what I did) is to download THIS module in the python folder and run it using the command  python get-pip.py 

Now you have pip installed. The next step is to install every single required module. Here's the catch that I was talking about. In the readme file on the Manim GitHub repository, it's mentioned that you can do this :  pip install -r requirements.txt  but I don't recommend it! Of course first you would need to  cd Scripts  and then using pip, install all requirements manually, by hand and don't forget the version [ EX:  pip install colour==0.1.2  ]. Read them from the text file, one by one and install them. If you have any problems with numpy and scipy, download them individually from HERE as .whl files in the Scripts directory and just run  pip install <the .whl file name>  . This should work without a problem. Of course, keep in mind that you would need to install numpy before scipy.
I would recommend always installing numpy and scipy from the .whl files, because even though I had them both installed, the Manim wouldn't run... As soon as I installed them from the .whl files, everything was working properly.
The last module (aggdraw) is going to require having THIS C++ Compiler Package for Python 2.7 and GitHub installed to be able to clone the repository. I had the GitHub installed on my PC, but if you don't you may try manually downloading and extracting the directory from the link given in the requirements.txt file -- [GitHub link] -- and then manually using pip to installing it. It's a nice thing to have GitHub though, I recommend it every day of the week.

If all of the requirements were installed successfully, you are good to go.

I'll leave you here today...

The next phase is running the Manim from it's project folder
(for me, it's - C:/Python27/Manim - you should be in the folder where you have downloaded Manin)
  python extract_scene.py -p example_scenes.py SquareToCircle  

Thanks for all of the corrections that were suggested by anthonynorthrup314

Next time, will attempt to save the same example animation...
Share:

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hey there! I am having trouble and I THINK the problem is aggdraw.
    When I try to install it manually, I execute the following line and get the following error:

    C:\Python27\aggdraw>python setup.py build_ext -i
    === freetype support disabled
    running build_ext
    building 'aggdraw' extension
    Traceback (most recent call last):
    File "setup.py", line 88, in
    library_dirs=library_dirs, libraries=libraries
    File "C:\Python27\lib\distutils\core.py", line 151, in setup
    dist.run_commands()
    File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
    File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
    File "C:\Python27\lib\distutils\command\build_ext.py", line 337, in run
    self.build_extensions()
    File "C:\Python27\lib\distutils\command\build_ext.py", line 446, in build_exte
    nsions
    self.build_extension(ext)
    File "C:\Python27\lib\distutils\command\build_ext.py", line 496, in build_exte
    nsion
    depends=ext.depends)
    File "C:\Python27\lib\distutils\msvc9compiler.py", line 474, in compile
    self.initialize()
    File "C:\Python27\lib\distutils\msvc9compiler.py", line 384, in initialize
    vc_env = query_vcvarsall(VERSION, plat_spec)
    File "C:\Python27\lib\distutils\msvc9compiler.py", line 300, in query_vcvarsal
    l
    raise ValueError(str(list(result.keys())))
    ValueError: [u'path']

    For selftest.py, I get

    C:\Python27\aggdraw>python selftest.py
    Traceback (most recent call last):
    File "selftest.py", line 5, in
    import Image
    ImportError: No module named Image


    And when I install aggdraw, I get this message and I'm not sure if it is okay:

    === freetype support disabled
    running install
    running build
    running build_ext
    running install_lib
    running install_egg_info
    Removing C:\Python27\Lib\site-packages\aggdraw-1.1_64bits-py2.7.egg-info
    Writing C:\Python27\Lib\site-packages\aggdraw-1.1_64bits-py2.7.egg-info

    I think this is not alright.
    When I execute python extract_scene.py -p example_scenes.py SquareToCircle , I get the following:

    C:\Python27\manim> python extract_scene.py -p example_scenes.py SquareToCircle
    Traceback (most recent call last):
    File "extract_scene.py", line 14, in
    from scene.scene import Scene
    File "C:\Python27\manim\scene\scene.py", line 14, in
    from animation.animation import Animation
    File "C:\Python27\manim\animation\animation.py", line 5, in
    from mobject.mobject import Mobject
    File "C:\Python27\manim\mobject\mobject.py", line 11, in
    from utils.bezier import interpolate
    File "C:\Python27\manim\utils\bezier.py", line 3, in
    from scipy import linalg
    File "C:\Python27\lib\site-packages\scipy\__init__.py", line 61, in
    from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
    ImportError: cannot import name NUMPY_MKL

    Any suggestion?

    ReplyDelete
    Replies
    1. Do you have the C++ compiler and the freetype prerequisites? I see there freetype support disabled, that may be the issue somehow... Or you still have the option of installing GitHub and via GitHub downloading it. Let me know more info!

      Delete
  3. terrível, até hoje estou penando pra conseguir fazer ao menos uma animação.

    ReplyDelete
    Replies
    1. As I translated, you are not happy with animating, or? You should know that this thing here is used for making complex mathematical animations that can't be made for example in After Effects, Flash (if anyone still uses it) or softwares like them. So, please, be sure to reconsider your choice of animation software.

      Delete

Contributors

Powered by Blogger.