Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow animations with run_time=0 and implement convenience Add animation #4017

Merged
merged 8 commits into from
Nov 27, 2024

Conversation

chopan050
Copy link
Contributor

@chopan050 chopan050 commented Nov 14, 2024

Closes #4004

This PR refactors the Animation.run_time validation. Instead of checking in Animation.begin() that each individual animation has a positive run_time which is large enough for the current frame rate, we now have the following:

  • Animation.run_time is now a property that only checks that the given value is not negative. A run_time of 0 is allowed.
  • validate_run_time, originally a function defined in manim.animation.animation, is now a Scene class method, because it's now called only inside other Scene methods. Instead of it being called inside Animation.begin() to validate the run_time of a single animation, it's now called inside Scene.get_run_time() to validate the total obtained run time. This is the one which is not allowed to be 0. If it's too small for the current frame rate, it will be enlarged. Individual animations will not be affected.

This PR also introduces a convenience animation: Add. It is similar to Scene.add, but it's an animation which can be grouped inside other animations and has a default run_time of 0. Thus, if people needs to instantly add Mobjects in the middle of an animation, they can now do so in an easier way.

Examples for using Add are also provided in the documentation: https://manimce--4017.org.readthedocs.build/en/4017/reference/manim.animation.animation.Add.html

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

manim/animation/animation.py Dismissed Show dismissed Hide dismissed
manim/animation/animation.py Dismissed Show dismissed Hide dismissed
manim/scene/scene.py Dismissed Show dismissed Hide dismissed
manim/scene/scene.py Dismissed Show dismissed Hide dismissed
manim/scene/scene.py Dismissed Show dismissed Hide dismissed
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you very much!

manim/animation/animation.py Outdated Show resolved Hide resolved
manim/animation/animation.py Outdated Show resolved Hide resolved
@chopan050 chopan050 enabled auto-merge (squash) November 27, 2024 00:38
@chopan050 chopan050 merged commit f81d571 into ManimCommunity:main Nov 27, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Please remove or weaken run_time validation in Animation class, so as to allow animations with run_time = 0
2 participants