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

Wednesday, December 20, 2017

Writing text with the Manim

Hi!

In my previous blog posts, we were setting and running our first example animation with the engine called 'Manim'. The example animation only consisted of drawing a square and transforming it into a circle. This time, I want to try out the so called 'WriteStuff' scene in the example_scenes.py. This scene, for the first time, renders a text with cool vector animation that is unique to 3Blue1Brown.

What's the problem with the 'WriteStuff' scene?

So, if you try running this command:
 python extract_scene.py -p example_scenes.py WriteStuff 
to preview the WriteStuff scene, you would probably see an error that tells you that there is a .svg file missing. This error is caused by the lack of a framework called 'LaTeX' that is used to convert text to .svg files to be able to render the text with all of the cool animations. LaTeX is mentioned as a primary requirement in the readme file on the official GitHub page of the Manim. So, today we are going to install it and test it.

Installing LaTeX

HERE is a link for the setup file, install it just like any other setup. That simple.

Checking if LaTeX works properly

As Anthony Northrup talks about checking if LaTeX and dvisvgm work (it's a LaTeX tool that converts DVI and EPS files to SVG files, hence the name dvi - svg):
Once you've tried to preview/save the WriteStuff scene, you should have a file <NUMBERS>.tex in the /files/Tex directory. If you ran into issues when viewing the scene, try calling the conversion calls (found at the bottom of mobject/tex_mobject.py) manually (but with logging) from the command line. For example:
> cd /files/Tex/
> copy "<NUMBERS>.tex" test.tex
> latex -halt-on-error test.tex
> dvisvgm test.dvi -n -o test.svg
If there aren't any errors at each step, it should convert properly when running via the extract_scenes file, but the dvisvgm might pop an error.

So, what if the dvisvgm pops an error? 

With couple of simple steps you would need to replace the existing dvisvgm tool with the most recent version found HERE (you can also compile from the latest source found here). Choose the correct architecture (32 or 64 bit) and download the .zip archive. There, you will find couple of files including dvisvgm.exe.
Now you will need to use this new version instead of the included version from MiKTeX (or whichever LaTeX installation you are using). To do this, we will need to extract the zip to a folder, then add that folder to the system PATH variable. You can find instructions for doing this here. Once that has been added, you can verify the system is pointing to the updated dvisvgm by opening a new command prompt window (you may have to restart on older machines for the PATH variable to be properly updated) and use the where command:
> where dvisvgm
<THE ABSOLUTE PATH(S) OF dvisvgm IF FOUND>
If the folder you extracted the zip to is at the top, you are ready to test again, otherwise you'll need to fix the PATH.

Now, if you try just the last command, it should work properly converting the dvi to svg.

Try running the preview command again and it would hopefully work:
 python extract_scene.py -p example_scenes.py WriteStuff 


That's it ! You can now render any text you want !
Share:

Monday, December 18, 2017

The Manim -- Follow up

Hi!

This is a follow up blog post for the Manim (the animation engine for explanatory math videos). Today we are going to save the example animation.

So, in the previous blog post, I left you wondering how to save the actual example animation.

After you have done every step carefully and methodically, I assume you can run the command and preview the example animation 'SquareToCircle' in low quality movie format:
 python extract_scene.py -p example_scenes.py SquareToCircle 


Now to actually save it... First, find the 'constants.py' file and in it, change the MOVIE_DIR from
 os.path.join(os.path.expanduser('~'), "Dropbox/3b1b_videos/animations/") 
to 
"<your absolute/fixed output folder path>" 

For example:  "C:/Videos/" 

then try running the command: (Note: that instead of -p we write -w)
 python extract_scene.py -w example_scenes.py SquareToCircle 

You may see an error saying that there is no 'ffmpeg' command. That's because ffmpeg is a framework that needs to be installed and that's fairly easy to do. Just follow the instructions HERE.

After downloading the ffmpeg and adding it to the environmental path variable, you should be good to go. Run the command again and you should see something like this:



Explained by anthonynorthrup314 (Huge shoutout to him for correcting this blog post):

The error you are seeing at the end: The system cannot find the path specified is because it plays a chord when it finishes rendering a scene, you can find this method at the top of the helpers.py file: play_chord(*nums). It tries to call a program play, which isn't installed on Windows. Installing SoX on Linux fixes the problem, but I haven't tried installing it on Windows to actually prove that it will fix the issue. But, in the end, it's nothing to worry about.

Wala!  Now you have created your first movie via The Manim! Congrats!

That's all for today, I'll take a look into the actual code now...
Share:

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:

Contributors

Powered by Blogger.