Skip to content

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

Merged
merged 3 commits into from
Mar 20, 2021

Conversation

aebkea
Copy link
Contributor

@aebkea aebkea commented Mar 14, 2021

Motivation

I found that it was a hassle, especially when working within an AnimationGroup, to animate the undoing of Write. Of course one could pass rate_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 an Uncreate animation to complement ShowCreation, but no corresponding function to complement Write.

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 parameter reverse which, if False, renders the animation from left to right (assuming text oriented in the usual way), but if True, it renders right to left.

Examples

class UnwriteReverseFalse(Scene):
    def construct(self):
        text = Tex("Alice and Bob").scale(3)
        self.add(text)
        self.play(Unwrite(text)) # reverse=False is the default
UnwriteReverseFalse.mp4
class UnwriteReverseTrue(Scene):
    def construct(self):
        text = Tex("Alice and Bob").scale(3)
        self.add(text)
        self.play(Unwrite(text,reverse=True))
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 so Unwrite 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 of Write 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 or lambda: t: rate_function(1-t), where rate_function is the function passed as a parameter to Unwrite. 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 name slow_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 by fast_then_slow.

Acknowledgements

  • I have read the Contributing Guidelines
  • I have chosen a descriptive PR title (see top of PR template for examples)

Reviewer Checklist

  • Newly added functions/classes are either private or have a docstring
  • Newly added functions/classes have tests added and (optional) examples in the docs
  • Newly added documentation builds, looks correctly formatted, and adds no additional build warnings
  • The PR title is descriptive enough

Comment on lines 335 to 337
vmobject.submobjects[0].submobjects = list(
reversed(vmobject.submobjects[0].submobjects)
)
Copy link
Member

Choose a reason for hiding this comment

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

  1. Why only the first submobject?
  2. 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 override end() to restore them?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Member

@eulertour eulertour left a 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.

@jsonvillanueva jsonvillanueva changed the title Added Unwrite animation class, to complement Write Added Unwrite animation class to complement Write Mar 20, 2021
@jsonvillanueva
Copy link
Member

Tests are missing, but I think that's okay for now as we have ongoing issues with testing Write currently #157

@jsonvillanueva jsonvillanueva merged commit e2bc1f6 into ManimCommunity:master Mar 20, 2021
@aebkea aebkea deleted the unwrite branch March 20, 2021 23:47
@jsonvillanueva jsonvillanueva added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Mar 23, 2021
@jsonvillanueva jsonvillanueva changed the title Added Unwrite animation class to complement Write Added :class:~.Unwrite animation class to complement :class:~.Write Mar 24, 2021
@behackl behackl added this to the Release v0.5.0 milestone Mar 24, 2021
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
None yet
Development

Successfully merging this pull request may close these issues.

4 participants