Skip to content

ManimCommunity/manim

main
Switch branches/tags
Code

Latest commit

* fix: fixed bad text slicing for Paragraph's lines

Inside Paragraph's _gen_chars method, a bad string slicing caused the text's characters to be obtained in an incorrect order. This would cause chars (and thus self.chars and self.lines in __init__) to store incorrect values.
If Paragraph's alignment parameter was None, nothing wrong seemed to happen, but if alignment was 'left', 'center or 'right', the text's lines would not display correctly.
This happened because the slicing was of the form [begin : begin + string_length + 1]. This bug was fixed by changing it to [begin : begin + char_count], where char_count is the number of characters in the corresponding string which are not " ", "\n" or "\t".
I've also cleaned __init__'s code:
- There was a redundant fragment of code which did exactly the same thing as _gen_chars, storing data in chars_lines_text_list. I deleted this code and used self.chars instead.
- lines_str joins the text strings with '\n', but then lines_str_list split lines_str again, with '\n' as delimiter. I rewrote lines_str_list as just list(text).
- self.lines is a list which essentially stores list(self.chars) as its first element. The original code used a for loop to append self.chars' lines, one by one, to self.lines[0]. I replaced this for loop with list(self.chars).
- self.lines' second element was rewritten as a repetition of [self.alignment], self.chars.__len()__ times.
- I replaced the for loop used to append the line centers to self.lines_initial_positions, and instead used [line.get_center() for line in self.lines[0]].

* revert: reverted lines_str and lines_str_list changes

* fix: added Paragraph.consider_spaces_as_chars to fix issue

* fix: changed `config` kwargs name to `kwargs`

Using `config` as a name for keyword arguments in `Paragraph.__init__` is inconsistent with the use of `kwargs` everywhere else and also shadows the `config` global variable, which is why this variable was renamed as `kwargs`.

* refactor: changed `var.__len__()` to `len(var)`

Changed 8 appearances (1 in `remove_invisible_chars`, 6 in `Paragraph` and 1 in `Text`) of magic method `__len__` (as in `var.__len__()`) to `len(var)`.

* refactor: changed docstrings and added type hints

* fix: changed space char hardcoding to isspace() string method

Co-authored-by: Tristan Schulz <mrdiverlp@gmail.com>
b5681fd

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time



PyPI Latest Release Docker image MIT License Reddit Twitter Discord Code style: black Documentation Status Downloads CI

An animation engine for explanatory math videos


Manim is an animation engine for explanatory math videos. It's used to create precise animations programmatically, as demonstrated in the videos of 3Blue1Brown.

NOTE: This repository is maintained by the Manim Community and is not associated with Grant Sanderson or 3Blue1Brown in any way (although we are definitely indebted to him for providing his work to the world). If you would like to study how Grant makes his videos, head over to his repository (3b1b/manim). This fork is updated more frequently than his, and it's recommended to use this fork if you'd like to use Manim for your own projects.

Table of Contents:

Installation

WARNING: These instructions are for the community version only. Trying to use these instructions to install 3b1b/manim or instructions there to install this version will cause problems. Read this and decide which version you wish to install, then only follow the instructions for your desired version.

Manim requires a few dependencies that must be installed prior to using it. If you want to try it out first before installing it locally, you can do so in our online Jupyter environment.

For local installation, please visit the Documentation and follow the appropriate instructions for your operating system.

Usage

Manim is an extremely versatile package. The following is an example Scene you can construct:

from manim import *


class SquareToCircle(Scene):
    def construct(self):
        circle = Circle()
        square = Square()
        square.flip(RIGHT)
        square.rotate(-3 * TAU / 8)
        circle.set_fill(PINK, opacity=0.5)

        self.play(Create(square))
        self.play(Transform(square, circle))
        self.play(FadeOut(square))

In order to view the output of this scene, save the code in a file called example.py. Then, run the following in a terminal window:

manim -p -ql example.py SquareToCircle

You should see your native video player program pop up and play a simple scene in which a square is transformed into a circle. You may find some more simple examples within this GitHub repository. You can also visit the official gallery for more advanced examples.

Manim also ships with a %%manim IPython magic which allows to use it conveniently in JupyterLab (as well as classic Jupyter) notebooks. See the corresponding documentation for some guidance and try it out online.

Command line arguments

The general usage of Manim is as follows:

manim-illustration

The -p flag in the command above is for previewing, meaning the video file will automatically open when it is done rendering. The -ql flag is for a faster rendering at a lower quality.

Some other useful flags include:

  • -s to skip to the end and just show the final frame.
  • -n <number> to skip ahead to the n'th animation of a scene.
  • -f show the file in the file browser.

For a thorough list of command line arguments, visit the documentation.

Documentation

Documentation is in progress at ReadTheDocs.

Docker

The community also maintains a docker image (manimcommunity/manim), which can be found on DockerHub. Instructions on how to install and use it can be found in our documentation.

Help with Manim

If you need help installing or using Manim, feel free to reach out to our Discord Server or Reddit Community. If you would like to submit a bug report or feature request, please open an issue.

Contributing

Contributions to Manim are always welcome. In particular, there is a dire need for tests and documentation. For contribution guidelines, please see the documentation.

However, please note that Manim is currently undergoing a major refactor. In general, contributions implementing new features will not be accepted in this period. The contribution guide may become outdated quickly; we highly recommend joining our Discord server to discuss any potential contributions and keep up to date with the latest developments.

Most developers on the project use poetry for management. You'll want to have poetry installed and available in your environment. Learn more about poetry at its documentation and find out how to install manim with poetry at the manim dev-installation guide in the manim documentation.

How to Cite Manim

We acknowledge the importance of good software to support research, and we note that research becomes more valuable when it is communicated effectively. To demonstrate the value of Manim, we ask that you cite Manim in your work. Currently, the best way to cite Manim is to go to our repository page (if you aren't already) and click the "cite this repository" button on the right sidebar. This will generate a citation in your preferred format, and will also integrate well with citation managers.

Code of Conduct

Our full code of conduct, and how we enforce it, can be read on our website.

License

The software is double-licensed under the MIT license, with copyright by 3blue1brown LLC (see LICENSE), and copyright by Manim Community Developers (see LICENSE.community).

About

A community-maintained Python framework for creating mathematical animations.

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.community

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages