Skip to content

Conversation

@irvanalhaq9
Copy link
Contributor

@irvanalhaq9 irvanalhaq9 commented Jan 12, 2025

Overview: What does this pull request change?

This pull request introduces a new example for the Homotopy class. This example is inspired by the previous PR in PR #2959. The idea of a waving square is simple and easy to understand, so I modify the code. This new example demonstrates a smooth transition from the original square shape to a waving square. Unlike the example there, which started directly with the deformed shape, this update ensures that the original square is visible at the start, and the deformation happens gradually. This change aims to provide a more intuitive and visually clear demonstration of how homotopy works.

  • Added a new Homotopy example showing a smooth transition from the original square to the waving square.
  • The transition starts with the original square, which then gradually deforms into the waving square.

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

Links to added or changed documentation pages

Further Information and Comments

The result is below

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

@irvanalhaq9
Copy link
Contributor Author

HomotopyPR.mp4

@irvanalhaq9
Copy link
Contributor Author

irvanalhaq9 commented Jan 14, 2025

This is my second option for the example:

class HomotopySineWave(Scene):
    def construct(self):
        square = Square()

        def homotopy(x, y, z, t):
            if t <= 0.25:
                progress = t / 0.25  
                return (x, y + progress * 0.2 * np.sin(x), z)
            elif t <= 0.75:  
                wave_progress = (t - 0.25) / 0.5
                return (x, y + 0.2 * np.sin(x + 10 * wave_progress), z)
            else:  
                end_progress = (t - 0.75) / 0.25  
                current_y = y + 0.2 * np.sin(x + 10)  
                return (x, interpolate(current_y, y, end_progress), z)

        self.play(Homotopy(homotopy, square, rate_func=linear, run_time=2))
        self.wait()

The result is:

HomotopySineWave.mp4

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 great, thank you!

@behackl behackl merged commit def7241 into ManimCommunity:main Jan 19, 2025
22 of 23 checks passed
@behackl behackl added the documentation Improvements or additions to documentation label Jan 19, 2025
@behackl behackl added this to the v0.19.0 milestone Jan 19, 2025
@irvanalhaq9
Copy link
Contributor Author

Thank you.

@irvanalhaq9 irvanalhaq9 deleted the homotopy-example-update branch January 20, 2025 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants