# Animating Particles with Javascript source: https://developer.mastercard.com/blog/animating-particles-with-javascript/index.md Authors: Russell Weiss. Summary Mastercard Developers homepage animations are built in-house and in code by our designers and developers Creating the Mastercard Developers coded animations was a challenge with multiple iterations Mastercard Developers eventually built a tool that allows the design team to generate animations without any developments or deployments When the updated Mastercard Developers site launched in 2016, the homepage included a looping video clip. Simply put, it was too big--- about 3 MB in size---and too promotional. It belonged more to a marketing site than an API platform. We knew we needed a change: a new visual hero that would demonstrate the robust nature of Mastercard Developers. The design team came up with animation concepts and developed one for each category of Mastercard APIs, our solutions and more. I was tasked with creating the animations in code because it would allow us to hit our target file size, include dynamic variation and allow seamless looping. And because we all agreed that it would be pretty cool. You can view the outcome of my work on the homepage , where we now use animations to promote different parts of the platform. If you're interested to learn how it was built, keep reading! First iteration: the dot animations and the hard-coded map The animations were visually clean. I knew that compression artifacts would make them less so. They were also simple enough that we could fit all of the animations into JavaScript code, which would be smaller than a single video clip. It would also allow us to quickly iterate on animations with colors and sizes, in addition to making them responsive to screen size or device. The downside was that poor performance could kill the browsing experience. The particle and pulse effects The animations proposed were just dots moving across or blinking within a map of the world. The easiest way to create these animations in code seemed to be creating them as particle effects. Each animation was a different kind of particle emitter that would create a different kind of particle effect. A simple example is: "Create a \[red\] dot that starts at \[x1\] and moves to \[x2\]". The original 2 types were "particle" and "pulse". Particle This had rectangular bounds of where a particle could be randomly created and a second rectangular bounds where the particle would randomly die. There were also a few parameters that would define how long it would take the particle to fade in and out of opacity, and the color of the particle. Once started, particles would fly from one rectangular bounds to another. The start and end bounds would control if the particles moved left, right, up or down. Pulse The "pulse" type was simpler and took the same array that we used for the map. It picked a random map coordinate to fade a particle in, waited a few seconds, and then faded that particle out. This made the map look as if it was pulsing different colors. Animation Loop The animation loop is a single timer that calls a function on an interval. The framework call this function 60 times a second to create nice, smooth animations. I wanted the maximum number of particles to animate at once without impacting performance. Keeping this in mind, I used animation types (or emitters) that would spit out the particles and fill the animation array. Each particle knew its start and end point, what color it was and how big it was. Next, I needed an animation loop to tell each particle to progress forward with its animation. At every interval of the animation, the framework calls "step" on each particle and passes it the delta in time from when it was last called. Each particle's progress is checked, and once the particle has completed its animation, it's removed from the array. At this point, the particle emitter creates a new particle. The cycle continues. The animations play. The Map The map, as a grid of dots, was originally a hard coded multi-dimensional array. Here's the code on the left: Javascript /\* Map recipe \*/ MCGrid.mapProps = { rows: 0 , cols: 0 , offsetX: 0 , offsetY: 0 }; MCGrid.map = function() { var x = 'x' var mapArr = \[ \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,,,,x,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x,x,,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,,,,,,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,x,x,x,x,,,,,,,,,,x,x,x,,,,,,,,,x,x,x,x,x,x,x,x,x,x,x,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x,x,x,x,x,x,x\] , \[,,,,,,,,,,x,x,x,,,,,,,,,,x,x,x,x,x,x,,,x,x,,,x,x,x,x,x,,,,,,,,x,x,x,x,x,x,x,x,x,x,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,,,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,,,,,,x,x\] , \[,,,,,x,x,x,x,x,x,x,x,x,,,x,x,x,x,x,x,,,x,x,x,,,,x,x,,,x,,,x,x,x,,,,,,,x,x,x,x,x,x,x,x,x,x,,,,,,,,,,,,,,,x,x,x,x,x,x,x,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x,x,x,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x,x\] , \[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,x\] \]; MCGrid.mapProps.rows = mapArr.length; for (var i = 0; i \< mapArr.length; i++) { if( MCGrid.mapProps.cols \< mapArr\[i\].length ) { MCGrid.mapProps.cols = mapArr\[i\].length; } } return mapArr; }; MCGrid.mapLookup = function( x, y ) { var mapArr = this.state.map; x = x - MCGrid.mapProps.offsetX; y = y - MCGrid.mapProps.offsetY; if( mapArr\[y\] !== undefined \&\& mapArr\[y\]\[x\] !== undefined ) { return true; } return false }; MCGrid.mapCoords = function( mapArr ) { var coordsArr = \[\]; for (var y = 0; y \< mapArr.length; y++) { for (var x = 0; x \< mapArr\[y\].length; x++) { if( !!mapArr\[y\] \&\& !!mapArr\[y\]\[x\] ) { coordsArr.push( \[ x, y \] ); } } } return coordsArr; }; I wanted to make a function that would take a PNG file and create these arrays automatically, but I had limited time and didn't know if I could get it to work the way I wanted. Also, the PNG files themselves needed to be created as black and white pixels, and the map did not exist in this format. I counted the dots and made the map array by hand---to save time. I would later create a feature for the animation tool that would take black and white PNG files to create / save these arrays for the design team. Second iteration: teaching designers how to fish I exposed a lot of properties to the design team so they could play around with and tweak the animations. Still, any new animation types needed to be created by a developer that was familiar with the code. I quickly realized that it would be beneficial (to the designers and the developers) for the design team to be able to create new animations themselves. I also realized that it wouldn't be easy. I needed to rework the current animation code into a framework that could read new animations that were fed into it. Luckily, because I had exposed a lot of modifiable properties in the original animations, this wasn't as hard as it could have been. Within a month or so, I put together a web-based design tool and the framework that could take the output and render the animations. The Framework The original animation code was tightly coupled to the canvas rendering that was happening. There was some caching that was happening, but originally each particle had its own canvas that it When I started on the framework, my first inclination was to feed it a nicely formatted JSON that would hold color values, sprite values and animation properties. The framework would extract that information to set up the animations. Performance issues of the framework Initially, I was discouraged because the performance was very poor. After testing, I realized that rendering was fast, but the lookups and transformations of colors and coordinates on every frame was taking too much time. I needed to do a lot more caching to make this work. So, instead of using a multi-dimensional array and doing a look up of each coordinate. I would run the background or sprite definition through a function that would flatten the array into explicit x and y coordinates. The array would take up more space, but it would be a lot faster to process. Even though there are no heavy calculations in the canvas renderer portion of the framework (it only receives coordinate and color information), I knew rendering could be sped up. For example, It is faster to draw one canvas into another than it is to draw a completely new dot every time, so I create a separate canvas cache for every color and dot size combination. I also cached the entire background and a few tile sizes of background dots to speed up drawing, especially for the background world map. With multiple canvases and caching, it can get pretty complex. There are still more improvements that could be made to the canvas renderer, but I want to replace it with an SVG renderer first. I think this could remove a lot of complexity in cache management. The animation design tool The animation tool allows the design team to create new animations without any setup from a developer---but designers are already pushing its limits and asking for new functionality. Luckily for me, any future improvements to allow for more interesting animation variety won't necessarily require new code deployments. You can see the animation tool in action here: