Elad Bezalel Profile picture
Sep 5 โ€ข 8 tweets โ€ข 4 min read โ€ข Read on X
Ok, this is a sign to post a long awaited thread about confetti & DOM aware physics
1/8๐Ÿงต
At @lemonade_inc, we wanted to go beyond simple confetti when you buy a policy. we wanted a celebration that interact with the page itself. Here's how we brought this mockup to life: Image
Enter DOM-aware physics. I created a system where 2d elements don't just fall - they bounce off text, buttons, and other DOM elements in real-time.
For physics, i used Matter.js, it handles all complex calculations for realistic particle behavior.

Looking at their examples i encountered this:


What if i could trace the DOM and convert it to matter.js terrain? brm.io/matter-js/demoโ€ฆ
Image
Applying CSS filters to the DOM container enhances key UI elements for better tracing, then capture a high-contrast B&W snapshot using
* if you use dom-to-image or html2canvas, replace it w/ modern-screenshot, it's a better solution w/ web worker support! github.com/qq15725/modernโ€ฆ

Image
Image
Convert snapshot to SVG paths using potrace, a powerful tracing solution. We leveraged @tomayac's excellent WASM wrapper:
github.com/tomayac/esm-poโ€ฆ
Image
pathToVertices method converts SVG paths into vertices that matter can work with

* This conversion is resource intensive and slow. To maintain performance, we only run this once, making the 2D physics interactive but not reflective of dynamic DOM changes. brm.io/matter-js/docsโ€ฆ
Image
Finally, we overlay a transparent Matter.js canvas and spread confetti with rects and forces. On click, confetti flies and bounces off DOM elements ๐ŸŒŸ

You can even use this method to create fluid-like goo effects. Endless possibilities! ๐Ÿš€

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Elad Bezalel

Elad Bezalel Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @elad_bezalel

Jan 14, 2022
ืื ื™ ื—ื•ืฉื‘ ืœืขืฉื•ืช ืกื“ืจืช ืฆื™ื•ืฆื™ื/ืคื•ืกื˜ ืขืœ ืื™ืš ืœื”ื’ืฉื™ื ืœืžืขืฆื‘ื™ื ืืช ื”ื—ืœื•ืžื•ืช ืฉืœื”ื
ื–ื” ื™ื›ื™ืœ ื“ื‘ืจื™ื ื›ืžื• - ืœื”ื‘ื™ืŸ ืืช ื”ื‘ืขื™ื”, ืœืžืฆื•ื ื‘ืื™ื ื˜ืจื ื˜ ืคืชืจื•ืŸ ืงืจื•ื‘, ืœื”ืชืื™ื ืื•ืชื• ืืœื™ื ื• ื•ืœืฉืคืจ ืื•ืชื• ื›ื“ื™ ืฉื™ื”ื™ื” ืžื“ื”ื™ื
ื”ืื ื–ื” ื™ืขื ื™ื™ืŸ ืžื™ืฉื”ื•?
#ืคื™ื“ืชื›ื ื•ืช
1/ ื›ืฉืื ื™ ื• @noamokman ื”ื™ื™ื ื• ื‘ืฆื‘ื ื•ื ื™ืกื™ื ื• ืœื“ื—ื•ืฃ nodejs ื”ื™ื” ืœื ื• ืžืฉืคื˜ โ€œืื ื–ื” ื‘ื™ื˜ ืฉื™ื•ืฆื ืžื”ืžื—ืฉื‘ ืื ื—ื ื• ื ืขืฉื” ืืช ื–ื”โ€œ, ืœื™ืžื™ื, ื›ืฉ FE ื”ืคืš ืืฆืœื™ ืœืขื™ืกื•ืง ื”ืขื™ืงืจื™ ืฉื™ื ื™ืชื™ ืืช ื”ืžืฉืคื˜ ืœ โ€œืื ื–ื” ืคื™ืงืกืœ ืขืœ ื”ืžืกืš, ืื ื™ ื™ื›ื•ืœ ืœืขืฉื•ืช ืืช ื–ื”โ€
ื•ื–ื” ืžื” ืฉืื ื™ ืชืžื™ื“ ืื•ืžืจ ืœืžืขืฆื‘ื™ื ืฉืื ื™ ืขื•ื‘ื“ ืื™ืชื.
2/ ื”ืชืณืจื“ ื”ื‘ื ื™ืชืžืงื“ ื‘ื‘ื ื™ื™ืช ืงื•ืžืคื•ื ื ื˜ื•ืช/ื—ื•ื•ื™ื•ืช ื™ื—ืกื™ืช ืžื•ืจื›ื‘ื•ืช ืื‘ืœ ืžื ื™ืกื™ื•ืŸ ื ื™ืชืŸ ื•ื›ื“ืื™ ืœื”ืฉืœื™ืš ืขืœ ื“ื‘ืจื™ื ืคืฉื•ื˜ื™ื ื™ื•ืชืจ.
ื›ื“ืื™ ืœืฆื™ื™ืŸ ืฉื–ื”ื• ืœื ืคืชืจื•ืŸ ืงืกื, ืžืฆืืชื™ ืืช ืขืฆืžื™ ื—ื•ื–ืจ ืขืœ ืื•ืชืŸ ืคืขื•ืœื•ืช ื•ื—ืฉื‘ืชื™ ืฉื›ื“ืื™ ืœืฉืชืฃ :)
ื ืฉืชืžืฉ ื‘ืงื•ืžืคื•ื ื ื˜ื” ืžื”ื˜ื•ื•ื™ื˜ ื”ืžืงื•ืจื™ - ืขืฅ ืจื™ื— ืžืชื ื“ื ื“ - ื›ื“ื•ื’ืžื”.
Read 13 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(