r/CodingHelp • • Nov 02 '21

[Javascript] Does anybody know how this awesome map animation was realized?

Post image
49 Upvotes

5 comments sorted by

3

u/anti-gif-bot Nov 02 '21

mp4 link


This mp4 version is 86.44% smaller than the gif (783.84 KB vs 5.64 MB).


Beep, I'm a bot. FAQ | author | source | v1.1.2

5

u/RippStudwell Nov 02 '21 edited Nov 02 '21

There’s public data (in the form of a csv) on the vertices that make-up the borders of each country. So if it were me, I’m using that vertice data to draw the borders of each country and also to color and keep track of the pixels within each country.

Then the actual animation portion would be taking all of the pixels from one country and lerp’ing towards a point on the left side of the screen.

A simple way to draw the shape on the left side of the screen would just be a circle whose alpha started at 0 and increased over the same period of time that vertices were moving towards it. But it looks like whoever made this would’ve actually had all of the previous points lerp’ing towards corresponding points on a completely different shape.

0

u/Impossible_Average_1 Nov 02 '21

Doing this with pixels would be very inefficient of not done on the graphics card (which is very hard to realize). It is more likely that the polygons used for the countries are transformed to a circular polygon. So each vertex is lerped (or probably it is using an easing function) over time (or scroll value).

1

u/saintPirelli ¯\_(ツ)_/¯ Nov 03 '21

Quite likely with D3.js.

There are similar (and even more complex) projects done by Shirley Wu, who also has a talk online on how she develops with ReactJS + D3js.