kandi background
Explore Kits

manim | Animation engine for explanatory math videos | Animation library

 by   3b1b Python Version: v1.6.1 License: MIT

 by   3b1b Python Version: v1.6.1 License: MIT

Download this library from

kandi X-RAY | manim Summary

manim is a Python library typically used in User Interface, Animation applications. manim has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install manim' or download it from GitHub, PyPI.
Manim is an engine for precise programmatic animations, designed for creating explanatory math videos. Note, there are two versions of manim. This repository began as a personal project by the author of 3Blue1Brown for the purpose of animating those videos, with video-specific code available here. In 2020 a group of developers forked it into what is now the community edition, with a goal of being more stable, better tested, quicker to respond to community contributions, and all around friendlier to get started with. See this page for more details.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • manim has a highly active ecosystem.
  • It has 43754 star(s) with 4805 fork(s). There are 823 watchers for this library.
  • There were 2 major release(s) in the last 6 months.
  • There are 320 open issues and 629 have been closed. On average issues are closed in 93 days. There are 8 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of manim is v1.6.1
manim Support
Best in #Animation
Average in #Animation
manim Support
Best in #Animation
Average in #Animation

quality kandi Quality

  • manim has 0 bugs and 0 code smells.
manim Quality
Best in #Animation
Average in #Animation
manim Quality
Best in #Animation
Average in #Animation

securitySecurity

  • manim has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • manim code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
manim Security
Best in #Animation
Average in #Animation
manim Security
Best in #Animation
Average in #Animation

license License

  • manim is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
manim License
Best in #Animation
Average in #Animation
manim License
Best in #Animation
Average in #Animation

buildReuse

  • manim releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • Installation instructions, examples and code snippets are available.
  • It has 16789 lines of code, 1734 functions and 101 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
manim Reuse
Best in #Animation
Average in #Animation
manim Reuse
Best in #Animation
Average in #Animation
Top functions reviewed by kandi - BETA

kandi has reviewed manim and discovered the below as its top functions. This is intended to give you an instant insight into manim implemented functionality, and help decide if they suit your requirements.

  • Visualize the function graph .
  • Parse command line arguments .
  • Initialize the configuration .
  • Get configuration .
  • Return a section of the slope segment
  • Calculate the earclip of a triangle .
  • Compute the cubic approximation of the cubic approximation .
  • Updates the shadow cloud
  • Generate a list of animation instances from play_args .
  • Modify special characters .

manim Key Features

Animation engine for explanatory math videos

Directly

copy iconCopydownload iconDownload
# Install manimgl
pip install manimgl

# Try it out
manimgl

Directly (Windows)

copy iconCopydownload iconDownload
git clone https://github.com/3b1b/manim.git
cd manim
pip install -e .
manimgl example_scenes.py OpeningManimExample

Mac OSX

copy iconCopydownload iconDownload
brew install ffmpeg mactex

Using manim

copy iconCopydownload iconDownload
manimgl example_scenes.py OpeningManimExample

Manim MathTex - Multiple text fragments in numerator of fraction

copy iconCopydownload iconDownload
text = MathTex(r"\frac{a}{b}", font_size=24)
self.add(index_labels(text[0]))
text[0][0:1].set_color(YELLOW)
text[0][1:2].set_color(RED)
self.add(text)
-----------------------
MathTex("{ {{a}} \\over { {{b}} } }").submobjects
# [SingleStringMathTex('{ '), SingleStringMathTex('a'), SingleStringMathTex(' \\over { '), SingleStringMathTex('b'), SingleStringMathTex(' } }')]

how can I rotate line with only changing theta?

copy iconCopydownload iconDownload
theta_vt = ValueTracker(theta)

dot_P_text.add_updater(lambda mobj: mobj.next_to([4*np.cos(theta_vt.get_value()*2),4*np.sin(theta_vt.get_value()*2)-1.5,0]))
line_AP.add_updater(lambda mobj: mobj.put_start_and_end_on([-4, 1.5, 0], [4*np.cos(theta_vt.get_value()*2),4*np.sin(theta_vt.get_value()*2)-1.5,0]))

self.play(theta_vt.animate.set_value(2*PI))
P = Mobject().move_to([4*np.cos(theta*2),4*np.sin(theta*2)-1.5,0])
-----------------------
theta_vt = ValueTracker(theta)

dot_P_text.add_updater(lambda mobj: mobj.next_to([4*np.cos(theta_vt.get_value()*2),4*np.sin(theta_vt.get_value()*2)-1.5,0]))
line_AP.add_updater(lambda mobj: mobj.put_start_and_end_on([-4, 1.5, 0], [4*np.cos(theta_vt.get_value()*2),4*np.sin(theta_vt.get_value()*2)-1.5,0]))

self.play(theta_vt.animate.set_value(2*PI))
P = Mobject().move_to([4*np.cos(theta*2),4*np.sin(theta*2)-1.5,0])

manim camera.move_to and camera.scale at the same time don't work

copy iconCopydownload iconDownload
self.camera.frame.animate.move_to(<code>).scale(<code>)

manim set_z_index with value_tracker

copy iconCopydownload iconDownload
        self.play(
            remplissage_de_base.animate.become(
                Rectangle(height=remplissage_de_base.height,
                            width=pourcentage_homme*4,
                            stroke_color=BLACK).align_to(rectangle_de_base, LEFT+UP).set_fill(BLUE, opacity=0.8)
            ),
            tracker.animate.set_value(pourcentage_homme)
        )

Debug Manim community in PyCharm

copy iconCopydownload iconDownload
with tempconfig({"quality": "medium_quality"}):
    scene = YourSceneClass()
    scene.render()

How do I pass arguments to Manim Community via command line?

copy iconCopydownload iconDownload
with tempconfig({"quality": "medium_quality", "preview": True}):
    scene = YourSceneClass()
    scene.render()

Javascript: frame precise video stop

copy iconCopydownload iconDownload
   const callback = (now, metadata) => {
      if (startTime == 0) {
        startTime = now;
      }
      elapsed = metadata.mediaTime;
      currentFrame = metadata.presentedFrames - doneCount;

      fps = (currentFrame / elapsed).toFixed(3);
      fps = !isFinite(fps) ? 0 : fps;

      updateStats();
      if (stopFrames.includes(currentFrame)) {
        pauseMyVideo();
      } else {
        video.requestVideoFrameCallback(callback);
      }
   };
   video.requestVideoFrameCallback(callback);
-----------------------
<!DOCTYPE html>
<html>
<body>

<h1 style="position: absolute; top: 10px; left: 10px" > Demo // Stop Video at Specific Frame(s) : </h1>
<br>

<div style="z-index: 1; overflow:hidden; position: absolute; top: 60px; left: 10px; font-family: OpenSans; font-size: 14px">
<p> <b> Choose an .MP4 video file... </b> </p>
<input type="file" id="choose_media" accept=".mov, .mp4" />
</div>

<video id="myVideo" width="640" height="480" controls muted playsinline 
style="position: absolute; top: 80px; left: 10px" >
<source src="vc_timecode3.mp4" type="video/mp4">
</video>

<div id="cont_texts" style="position: absolute; top: 80px; left: 700px" >

<span> Current Time : </span> <span id="txt_curr_time"> 00:00:00 </span> 
<br><br>
<span> Estimated Frame Num : </span> <span id="txt_est_frame"> 0 </span> 
<br><br>
<span> Total Frames (video) : </span> <span id="txt_total_frame"> -999 </span> 
<br><br>

<span onclick="check_points()" > Stopping Points Array : </span> <input type="text" id="stopPointsArray" value="" > 

</div>

</body>


<script>


////////////////////////////////

//# VARS
var myVideo = document.getElementById( 'myVideo' );
var video_duration;

var h; var m; var s;
var h_time; var m_time; var s_time;

var vid_curr_time = document.getElementById( 'txt_curr_time' );
var vid_est_frame = document.getElementById( 'txt_est_frame' );
var vid_total_frame = document.getElementById( 'txt_total_frame' );

var reader; //to get bytes from file into Array
var bytes_MP4; //updated as Array

//# MP4 related vars
var got_FPS = false; var video_FPS = -1; 
var temp_Pos = 0;  var sampleCount = -1;
var temp_int_1, temp_int_2 = -1;

                    
var array_points = document.getElementById("stopPointsArray");
array_points.addEventListener('change', check_points );

//# EVENTS
document.getElementById('choose_media').addEventListener('change', onFileSelected, false);

myVideo.addEventListener("timeupdate", video_timeUpdate);           
myVideo.addEventListener("play", handle_Media_Events );
myVideo.addEventListener("pause", handle_Media_Events );
myVideo.addEventListener("ended", handle_Media_Events );

//# LET'S GO...
        
function onFileSelected ( evt )
{
    file = evt.target.files[0];
    path = (window.URL || window.webkitURL).createObjectURL(file);
    
    reader = new FileReader();
    reader.readAsArrayBuffer(file);
    
    
    reader.onloadend = function(evt) 
    {
        //alert( " file is selected ... " );
        
        if (evt.target.readyState == FileReader.DONE) 
        {
            bytes_MP4 = new Uint8Array( evt.target.result );
            get_MP4_info( bytes_MP4 );
            
            //# use bytes Array as video tag source
            let path_MP4 = (window.URL || window.webkitURL).createObjectURL(new Blob([bytes_MP4], { type: 'video/mp4' })); //'image/png' //'application/octet-stream'
            myVideo.src = path_MP4;
            myVideo.load();
            
            video_duration = myVideo.duration;
            txt_total_frame.innerHTML =( sampleCount);
            //alert("video FPS : " + video_FPS);
        }
        
    }
    
}

function check_points (e)
{
    alert( "Array Points are : " + e.target.value );
}

function handle_Media_Events()
{
    if ( event.type == "ended" )
    { 
        myVideo.currentTime = 0; myVideo.play(); myVideo.pause(); myVideo.play();
    }
    
    //{ myVideo.currentTime = 8; btn_ctrl.src = "ico_vc_play.png"; vid_isPlaying = false; bool_isPlaying = true; }
    
    if ( event.type == "play" )
    {
        if ( myVideo.nodeName == "VIDEO" )
        {

        }
    
    }
    
    else if ( event.type == "pause" )
    {
        
        
    }
    
    else if ( event.type == "seeked" )
    {
        
        
    }
    
}

function video_timeUpdate()
{
    vid_curr_time.innerHTML = ( convertTime ( myVideo.currentTime ) );
    
    vid_est_frame.innerHTML = Math.round ( video_FPS * myVideo.currentTime );
    
}

function convertTime ( input_Secs ) 
{
    h = Math.floor(input_Secs / 3600);
    m = Math.floor(input_Secs % 3600 / 60);
    s = Math.floor(input_Secs % 3600 % 60);

    h_time = h < 10 ? ("0" + h) : h ;
    m_time = m < 10 ? ("0" + m) : m ;
    s_time = s < 10 ? ("0" + s) : s ;
    
    if ( (h_time == 0) && ( video_duration < 3600) ) 
    { return ( m_time + ":" + s_time ); }
    else 
    { return ( h_time + ":" + m_time + ":" + s_time ); }
     
}

function get_MP4_info( input ) //# "input" is Array of Byte values
{
    //# console.log( "checking MP4 frame-rate..." );
    
    got_FPS = false;
    temp_Pos = 0; //# our position inside bytes of MP4 array
     
    let hdlr_type = "-1"; 
    
    while(true)
    {
        //# Step 1) Prepare for when metadata pieces are found  
        //# When VIDEO HANDLER Atom is found in MP4
        
        //# if STSZ ... 73 74 73 7A  
        if (input[ temp_Pos+0 ] == 0x73)
        {
            if ( ( input[temp_Pos+1] == 0x74 ) && ( input[temp_Pos+2] == 0x73 ) && ( input[temp_Pos+3] == 0x7A ) )
            {
                if ( hdlr_type == "vide" ) //# only IF it's the "video" track
                {
                    temp_Pos += 12;
                    sampleCount = ( ( input[temp_Pos+0] << 24) | (input[temp_Pos+1] << 16) | (input[temp_Pos+2] << 8) | input[temp_Pos+3] );
                    console.log( "found VIDEO sampleCount at: " + sampleCount );
                    
                    video_FPS = ( ( sampleCount * temp_int_1 ) / temp_int_2 );
                    console.log( "FPS of MP4 ### : " +  video_FPS );
                }
                
            }
            
        }
        
        //# Step 2) Find the pieces of metadata info
        //# Find other Atoms with data needed by above VIDEO HANDLER code.
        
        
        //# for MOOV and MDAT
        if (input[ temp_Pos ] == 0x6D) //0x6D
        {
            //# if MDAT ... 6D 64 61 74
            if ( ( temp_Pos[temp_Pos+1] == 0x64 ) && ( input[temp_Pos+2] == 0x61 ) && ( input[temp_Pos+3] == 0x74 ) )
            {
                temp_int = ( ( input[temp_Pos-4] << 24) | (input[temp_Pos-3] << 16) | (input[temp_Pos-2] << 8) | input[temp_Pos-1] );
                temp_Pos = (temp_int-1);
                if ( temp_Pos >= (input.length-1) ) { break; }
            }
            
            //# if MOOV ... 6D 6F 6F 76
            if ( ( input[temp_Pos+1] == 0x6F ) && ( input[temp_Pos+2] == 0x6F ) && ( input[temp_Pos+3] == 0x76 ) )
            {
                temp_int = ( ( input[temp_Pos-4] << 24) | (input[temp_Pos-3] << 16) | (input[temp_Pos-2] << 8) | input[temp_Pos-1] );
            }
            
            //# if MDHD ... 6D 64 68 64
            if ( ( input[temp_Pos+1] == 0x64 ) && ( input[temp_Pos+2] == 0x68 ) && ( input[temp_Pos+3] == 0x64 ) )
            {
                temp_Pos += 32;
                
                //# if HDLR ... 68 64 6C 72
                if (  input[temp_Pos+0] == 0x68 )
                {
                    if ( ( input[temp_Pos+1] == 0x64 ) && ( input[temp_Pos+2] == 0x6C ) && ( input[temp_Pos+3] == 0x72 ) )
                    {
                        temp_Pos += 12;
                        hdlr_type = String.fromCharCode(input[temp_Pos+0], input[temp_Pos+1], input[temp_Pos+2], input[temp_Pos+3] );
                    }
                }
            }
            
            //# if MVHD ... 6D 76 68 64
            if ( ( input[temp_Pos+1] == 0x76 ) && ( input[temp_Pos+2] == 0x68 ) && ( input[temp_Pos+3] == 0x64 ) )
            {
                temp_Pos += (12 + 4);
                
                //# get timescale
                temp_int_1 = ( ( input[temp_Pos+0] << 24) | (input[temp_Pos+1] << 16) | (input[temp_Pos+2] << 8) | input[temp_Pos+3] );
                ///console.log( "MVHD timescale at: " + temp_int_1 );
                
                //# get duration
                temp_int_2 = ( ( input[temp_Pos+4+0] << 24) | (input[temp_Pos+4+1] << 16) | (input[temp_Pos+4+2] << 8) | input[temp_Pos+4+3] );
                ///console.log( "MVHD duration at: " + temp_int_2 );
            }
            
        }
        
        if( temp_Pos >= (input.length-1) ) { break; }
        if( got_FPS == true) { break; }
        
        temp_Pos++;
    }
    
}

</script>

</html>

ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects

copy iconCopydownload iconDownload
apt-get install sox ffmpeg libcairo2 libcairo2-dev
apt-get install texlive-full
pip3 install manimlib  # or pip install manimlib
pip3 install manimce  # or pip install manimce
-----------------------
apt-get install sox ffmpeg libcairo2 libcairo2-dev
apt-get install texlive-full
pip3 install manimlib  # or pip install manimlib
pip3 install manimce  # or pip install manimce

manim add dots to circle list

copy iconCopydownload iconDownload
from manim import *

class PathExample(Scene):

    def construct(self):
        num_points = 16
        
        angles = [n * (360 / num_points) for n in range(num_points)]

        outer_circle = Circle(color=RED, radius=3)
        
        circles = [Circle(color=RED, radius=1).move_to(outer_circle.point_at_angle(n*DEGREES)) 
                    for n in angles]

        dots = []
        for c, n in zip(circles, angles):
            #c.add_updater(lambda m: m.rotate(-0.01))
            dot = Dot(color=RED, radius=.1, stroke_width=0).move_to(c.point_at_angle(n*DEGREES))
            dots.append(dot)

        # # First attempt
        #dots = [Dot(color=RED, radius=.1, stroke_width=0).move_to(c.point_at_angle(n*DEGREES)) 
        #            for c, n in zip(circles, angles)]

        rolling_outer_circle = VGroup(outer_circle, *circles, *dots)

        rolling_outer_circle.add_updater(lambda m: m.rotate(-0.01))
        
        self.add(rolling_outer_circle, outer_circle, *dots)
        self.play(rolling_outer_circle.animate, run_time=10, rate_func=linear)
        self.wait()
                
if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-ql', __file__, 'PathExample'])

How to print out from two different columns the min and max in a csv file?

copy iconCopydownload iconDownload
# These functions return a single-row data frame.
# We only care about the first row
min_row = df.nsmallest(1, 'costs').iloc[0]
max_row = df.nlargest(1, 'costs').iloc[0]

print(f"Min Cost is = {min_row['Qualification']} {min_row['costs']}")
print(f"Max Cost is = {max_row['Qualification']} {max_row['costs']}")

Community Discussions

Trending Discussions on manim
  • Manim MathTex - Multiple text fragments in numerator of fraction
  • how can I rotate line with only changing theta?
  • manim camera.move_to and camera.scale at the same time don't work
  • manim set_z_index with value_tracker
  • Debug Manim community in PyCharm
  • Manim exception in text mobject example
  • How do I pass arguments to Manim Community via command line?
  • Add buff only in one end of a manim line / arrow
  • Javascript: frame precise video stop
  • ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects
Trending Discussions on manim

QUESTION

Manim MathTex - Multiple text fragments in numerator of fraction

Asked 2022-Mar-17 at 19:36

I am working on a Manim project where I am manipulating equations algebraically. This is made easy using many of the provided utilities, but in order to do so smoothly I must separate MathTex objects into multiple isolated "fragments". This can be done in many ways, but I have opted to use the double brace syntax:

MathTex("{{a}} + {{b}}").submobjects
# [SingleStringMathTex('a'), SingleStringMathTex(' + '), SingleStringMathTex('b')]

This works for most math equations, including those which have a fragment in the denominator of a fraction

MathTex("\\frac{ a }{ {{b}} }}").submobjects
# [SingleStringMathTex('\\frac{ a }{ '), SingleStringMathTex('b'), SingleStringMathTex(' }}')]

However, no matter which method I use it seems as though I am not able to create a fragment within the numerator.

MathTex("\\frac{ {{a}} }{ {{b}} }}").submobjects
# ERROR    LaTeX compilation error: Missing }       tex_file_writing.py:265
#          inserted.

This seems to be a limitation imposed by the LaTeX compilation and not Manim's fragment system. I am looking for any workarounds that will allow me to create a Manim fragment in the numerator of a fraction.

ANSWER

Answered 2022-Mar-13 at 22:53

The Manim CE examples also mention another method for complex strings when isolating sub-strings do not work. It involves considering manual indices of the individual substrings and setting the colour on the substring indices directly.

So, for the Tex code \frac{a}{b}, it would probably look a bit like this:

text = MathTex(r"\frac{a}{b}", font_size=24)
self.add(index_labels(text[0]))
text[0][0:1].set_color(YELLOW)
text[0][1:2].set_color(RED)
self.add(text)

I would verify and tell you if it worked, but I use ManimGL so MathTex isn't compatible on my installation of Manim.

Source https://stackoverflow.com/questions/70175366

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install manim

WARNING: These instructions are for ManimGL only. Trying to use these instructions to install ManimCommunity/manim or instructions there to install this version will cause problems. You should first decide which version you wish to install, then only follow the instructions for your desired version. Note: To install manim directly through pip, please pay attention to the name of the installed package. This repository is ManimGL of 3b1b. The package name is manimgl instead of manim or manimlib. Please use pip install manimgl to install the version in this repository. Manim runs on Python 3.6 or higher (Python 3.8 is recommended).
Install LaTeX as above.
Create a conda environment using conda create -n manim python=3.8.
Activate the environment using conda activate manim.
Install manimgl using pip install -e ..

Support

Documentation is in progress at 3b1b.github.io/manim. And there is also a Chinese version maintained by @manim-kindergarten: docs.manim.org.cn (in Chinese). manim-kindergarten wrote and collected some useful extra classes and some codes of videos in manim_sandbox repo.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Reuse Pre-built Kits with manim
Try Top Libraries by 3b1b
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.