Skip to content

Keep submobject opacity in ShowIncreasingSubsets and its subclasses - #5117

Open
Thanatos9404 wants to merge 1 commit into
ManimCommunity:mainfrom
Thanatos9404:show-increasing-subsets-opacity
Open

Thanatos9404 wants to merge 1 commit into
ManimCommunity:mainfrom
Thanatos9404:show-increasing-subsets-opacity

Conversation

@Thanatos9404

Copy link
Copy Markdown

Overview: What does this pull request change?

Fixed :class:.ShowIncreasingSubsets, :class:.ShowSubmobjectsOneByOne, :class:.AddTextLetterByLetter and :class:.TypeWithCursor making translucent submobjects fully opaque.

Motivation and Explanation: Why and how do your changes improve the library?

Fixes #3424. These animations hide submobjects with set_opacity(0) and show them with set_opacity(1), so a square with fill_opacity=0.2 ends the animation fully opaque.

The animation now records each submobject's fill and stroke opacities before hiding it, for every member of its family (also the background stroke for Cairo VMobjects). It restores those values when the submobject is shown. Anything that is not a vectorized mobject still uses set_opacity(1), as before: ImageMobject.set_opacity is already relative to its own alpha.

I did not use save_state()/restore() from the issue, because it would overwrite a state the user saved and also restore positions.

Two details:

  • Animations built back to back: in Succession(AddTextLetterByLetter(t), RemoveTextLetterByLetter(t)), the second animation is created while the first has already hidden the text. So the opacities are recorded again in begin() once the submobjects are visible again. A submobject that is fully transparent when recorded falls back to opacity 1, as before.
  • Overshooting rate functions (e.g. ease_out_back) still work, because the shown submobjects are taken from a slice as before.

The cursor of TypeWithCursor is unchanged: it is still shown at opacity 1.

Links to added or changed documentation pages

None.

Further Information and Comments

Tests in tests/module/animation/test_creation.py cover the four animations, two animations built back to back, an overshooting rate function, and the restored fill_opacity attribute. They fail on main.

The rest of the suite gives the same results with and without this change. I don't have LaTeX installed, so the TeX tests fail locally on both. pre-commit passes.

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

ShowIncreasingSubsets hid each submobject with set_opacity(0) and showed
it again with set_opacity(1), so a translucent submobject ended up fully
opaque. Record each submobject's fill and stroke opacities before hiding
it and restore them when it is shown. ShowSubmobjectsOneByOne,
AddTextLetterByLetter and TypeWithCursor use the same code.

The opacities are recorded again in begin() when another animation has
shown the submobjects since, for example the previous one in a
Succession, and a submobject that is still fully transparent is shown
at full opacity as before.

Fixes ManimCommunity#3424.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with ShowIncreasingSubsets Animation: Fill Opacity Change

1 participant