-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Added :class:~.Unwrite
animation class to complement :class:~.Write
#1107
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
Conversation
manim/animation/creation.py
Outdated
vmobject.submobjects[0].submobjects = list( | ||
reversed(vmobject.submobjects[0].submobjects) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why only the first submobject?
- Modifying the animated Mobject will be unexpected to users, especially since indexing into Latex is already tricky. If it isn't possible to do it with the rate function is it at least possible to override
begin()
to reverse the mobjects and overrideend()
to restore them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing those out! I'll try to get get those problems addressed within the next few days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reimplemented the reversing to address both issues, but I'm running into a problem where running something like
class UnwriteScene(Scene):
def construct(self):
text = VGroup(Tex("Hello").shift(LEFT),Tex("Bye").shift(RIGHT))
text[0].set_color(RED)
self.play(Write(text))
self.play(Unwrite(text))
self.play(Write(text))
returns this instead of finishing by writing back to the screen, as I intended. I've noticed that the same thing happens with ShowCreation
and Uncreate
when used in the same fashion. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the problem with it not appearing also happens with ShowCreation/Uncreate it's probably not related to this, so that's fine.
Tests are missing, but I think that's okay for now as we have ongoing issues with testing Write currently #157 |
~.Unwrite
animation class to complement :class:~.Write
Motivation
I found that it was a hassle, especially when working within an
AnimationGroup
, to animate the undoing ofWrite
. Of course one could passrate_func = lambda t: -linear(t)+1
, but this would animate the unwriting in the opposite direction of how Write would act. It also was unbalanced how there existed anUncreate
animation to complementShowCreation
, but no corresponding function to complementWrite
.Overview / Explanation for Changes
Added :class:
Unwrite
which inherits from :class:~.Write
. It automatically reverses the animation of :class:~.Write
by passing the reversed rate function, but it also takes an additional boolean parameterreverse
which, ifFalse
, renders the animation from left to right (assuming text oriented in the usual way), but ifTrue
, it renders right to left.Examples
UnwriteReverseFalse.mp4
UnwriteReverseTrue.mp4
Testing Status
All tests pass on my machine (Windows 10 v1909, Python3.9.2). I did not write any new tests because it seems as per Issue #157 that
Write
is untestable, and soUnwrite
is as well.Further Comments
Possibly this should be added to the reference/demo animation in the docs under
manim.animation.creation
. It looks like it would be tricky to fit it in with the other animations in the scene without removing one of them or making them smaller.It is worth noting the artifact displayed when rendering a scene whose last animation is
Unwrite
, with no wait afterwards. I believe that this is a consequence ofWrite
drawing to the screen on the first frame of its animation, so reversing that would have it end on that frame. I haven't looked into it too much, but with what time I did spend, I was unable to figure out how to fix this.There's also room for debate about whether the rate function used for the reversed should be
lambda t: -rate_function(t) + 1
orlambda: t: rate_function(1-t)
, whererate_function
is the function passed as a parameter toUnwrite
. I went with the first option, because it ensures that asymmetric rate functions keep their properties sensibly. For example, the rate function which could be described by the nameslow_then_fast
will render with the first given rate function in that manner, whereas if the second function would be used, the animation would play in a way which is better described byfast_then_slow
.Acknowledgements
Reviewer Checklist