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

Implement :attr:.Mobject.always, and move builders to their own file #3852

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

JasonGrace2282
Copy link
Member

@JasonGrace2282 JasonGrace2282 commented Jul 12, 2024

Motivation

Allows for syntax like

d = Dot()
s = Square()
d.always.next_to(s, UP)
self.add(s, d)
self.play(s.animate.to_edge(LEFT))

Changelog

  • Implemented _UpdaterBuilder
  • Moved _AnimationBuilder and _UpdaterBuilder to their own file.
  • Made _AnimationBuilder generic in it's mobject, to match experimental

Note

I opted to allow imports of _UpdaterBuilder/_AnimationBuilder from Mobject itself, even though they're in their own file (manim.mobject.builders).

Warning

.always is a thin wrapper around add_updater, as such the usual caveats apply. If two updaters are added that affect the position, weird things could happen.

Documentation

https://manimce--3852.org.readthedocs.build/en/3852/reference/manim.mobject.mobject.Mobject.html#manim.mobject.mobject.Mobject.always

@JasonGrace2282 JasonGrace2282 added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Jul 12, 2024
manim/mobject/builders.py Dismissed Show dismissed Hide dismissed
manim/mobject/mobject.py Fixed Show fixed Hide fixed
@behackl
Copy link
Member

behackl commented Jul 12, 2024

This is actually very interesting, huge +1 for the API; I like it a lot!

Will review in-depth over the weekend, but I strongly believe we should ship this with the next release. 🚀

@MrDiver
Copy link
Collaborator

MrDiver commented Jul 21, 2024

Currently incomptaible with ValueTracker, on hold until ValueTracker is lazy!

@MrDiver MrDiver marked this pull request as draft July 21, 2024 14:54
@JasonGrace2282
Copy link
Member Author

I think it might be better just to get it merged in its current state. Valuetrackers can be added in a later PR, but I would love to have this in 0.19.0

if TYPE_CHECKING:
from typing_extensions import Self

from manim.animation.animation import Animation

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.mobject.builders
, as the
definition
of Animation occurs after the cyclic
import
of manim.mobject.builders.
'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.mobject.builders
, as the
definition
of Animation occurs after the cyclic
import
of manim.mobject.builders.
'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.mobject.builders
, as the
definition
of Animation occurs after the cyclic
import
of manim.mobject.builders.
'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.mobject.builders
, as the
definition
of Animation occurs after the cyclic
import
of manim.mobject.builders.
'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.mobject.builders
, as the
definition
of Animation occurs after the cyclic
import
of manim.mobject.builders.
from typing_extensions import Self

from manim.animation.animation import Animation
from manim.mobject.mobject import Mobject

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'Mobject' is not used.
from typing_extensions import Self

from manim.animation.animation import Animation
from manim.mobject.mobject import Mobject

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Mobject' may not be defined if module
manim.mobject.mobject
is imported before module
manim.mobject.builders
, as the
definition
of Mobject occurs after the cyclic
import
of manim.mobject.builders.
'Mobject' may not be defined if module
manim.mobject.mobject
is imported before module
manim.mobject.builders
, as the
definition
of Mobject occurs after the cyclic
import
of manim.mobject.builders.
'Mobject' may not be defined if module
manim.mobject.mobject
is imported before module
manim.mobject.builders
, as the
definition
of Mobject occurs after the cyclic
import
of manim.mobject.builders.

from manim.animation.animation import Animation
from manim.mobject.mobject import Mobject
from manim.mobject.opengl.opengl_mobject import OpenGLMobject

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'OpenGLMobject' is not used.

from manim.animation.animation import Animation
from manim.mobject.mobject import Mobject
from manim.mobject.opengl.opengl_mobject import OpenGLMobject

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'OpenGLMobject' may not be defined if module
manim.mobject.opengl.opengl_mobject
is imported before module
manim.mobject.builders
, as the
definition
of OpenGLMobject occurs after the cyclic
import
of manim.mobject.builders.
@@ -38,6 +38,7 @@
from ..utils.iterables import list_update, remove_list_redundancies
from ..utils.paths import straight_path
from ..utils.space_ops import angle_between_vectors, normalize, rotation_matrix
from .builders import _AnimationBuilder, _UpdaterBuilder

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'_AnimationBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.mobject
, as the
definition
of _AnimationBuilder occurs after the cyclic
import
of manim.mobject.mobject.
'_AnimationBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.mobject
, as the
definition
of _AnimationBuilder occurs after the cyclic
import
of manim.mobject.mobject.
@@ -38,6 +38,7 @@
from ..utils.iterables import list_update, remove_list_redundancies
from ..utils.paths import straight_path
from ..utils.space_ops import angle_between_vectors, normalize, rotation_matrix
from .builders import _AnimationBuilder, _UpdaterBuilder

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.mobject.
'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.mobject.
@@ -16,6 +16,7 @@

from manim import config, logger
from manim.constants import *
from manim.mobject.builders import _UpdaterBuilder

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.opengl.opengl_mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.opengl.opengl_mobject.
'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.opengl.opengl_mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.opengl.opengl_mobject.
'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.opengl.opengl_mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.opengl.opengl_mobject.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

3 participants