Jump to content
Search Community

Best way to morph from a shape with a hole in it to a solid rectangle / closing the hole

shy_seagull test
Moderator Tag

Recommended Posts

Hi there,

I’m trying to use the MorphSVGPlugin to animate a mask that hides/reveals the html element behind it. For that I’m using canvas for performance reasons.
I couldn’t really get a canvas clipping mask going so I just exported a subtracted shape from figma and used it as a single "evenodd" path. I am then morphing between those forms to change the hole/clipping area. There’s probably a better way to do this?


Anyway what I really want to do now is also completely closing / opening that hole by morphing to a solid rectangle. Right now when I do this every point just zooms to the top right as it morphs, which makes sense, but I would love to have it open and close from the center as in scaling the hole/clipping area to 0 and back. I hope I made myself clear.

Thank you!

See the Pen ZEBjLZq by lkssmnt-the-lessful (@lkssmnt-the-lessful) on CodePen

Link to comment
Share on other sites

So the negative space would just close up? Yeah I think grabbing the original vector and pull the points until it makes a solid rectangle would work well. You said you're using Figma, but I do have an article about organic morphing if you ever use Adobe Illustrator.

 

https://www.motiontricks.com/organic-morphing-getting-needed-points-from-adobe-illustrator/

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Thank you! Would there also be a way to animate the negative space instead of the positive? Right now I have one shape that looks like this (the shape is purple) but I think it might be easier to animate only the inner, negative shape and have another rectangle as the positive shape behind it.

 

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip

I tried to use these methods but couldn’t get it to work the other way around, meaning having a solid rectangle and subtracting an inner form from it.

See the Pen JjbaEpe by lkssmnt-the-lessful (@lkssmnt-the-lessful) on CodePen

Screenshot 2021-03-06 at 11.57.08.png

Link to comment
Share on other sites

I'm not entirely sure I follow. I would:

  1. Start with a rectangle
  2. Cut out the zagged shape for the reveal
  3. Duplicate the cut rectangle
  4. Push and pull points of the duplicate until it closes up
  5. Morph between the two shapes.

Something like this.

See the Pen MWbqOgb by PointC (@PointC) on CodePen

 

Does that help at all?

 

Happy tweening.

:)

 

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

I’m afraid I have one more question. At first I thought you had just put all of the points of the closed shape on one straight line but it appears you have pushed them further. I checked putting it into this pen:

 

See the Pen dyOqdZZ by lkssmnt-the-lessful (@lkssmnt-the-lessful) on CodePen

 

Now when I push my points in Figma or Illustrator over each other they create these kind of shapes which produce holes again. These holes also appear when I put them in my gsap project. So we are still doing something a bit different I guess? I just can’t figure it out, sorry!

Screenshot 2021-03-06 at 22.36.00.png

Link to comment
Share on other sites

And yet another update. Sadly the same problem with the overlap appears when I try to do just that while using canvas. I suppose it has something to do with the filltype="evenodd"?

See the Pen xxRaYyL by lkssmnt-the-lessful (@lkssmnt-the-lessful) on CodePen

 

Here is the same shape in an inline svg producing different results and closing the negative space:

See the Pen GRNXQXw by lkssmnt-the-lessful (@lkssmnt-the-lessful) on CodePen

Link to comment
Share on other sites

1 hour ago, shy_seagull said:

At first I thought you had just put all of the points of the closed shape on one straight line but it appears you have pushed them further.

Yep - that's intentional. With any of my SVG work like that I try to create a little overlap rather than make it pixel perfect. Depending on what you're doing, it may not be possible. But, if you can, it'll save you some headaches down the road. 

 

Glad to see you've got everything sorted now. Happy tweening and thank you for your continued support with a Club membership.

:)

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...