2018-03-19 18:26:58 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2020-06-19 15:11:03 +00:00
|
|
|
<title>Lottie Filmstrip Capture</title>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<script src="/lottie.js" type="text/javascript" charset="utf-8"></script>
|
|
|
|
<style type="text/css" media="screen">
|
|
|
|
body,
|
|
|
|
main,
|
|
|
|
.anim {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
2018-03-19 18:26:58 +00:00
|
|
|
|
2020-06-19 15:11:03 +00:00
|
|
|
main {
|
|
|
|
display: flex;
|
|
|
|
width: 1000px;
|
|
|
|
height: 1000px;
|
|
|
|
flex-flow: row wrap;
|
|
|
|
}
|
|
|
|
</style>
|
2018-03-19 18:26:58 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<main>
|
|
|
|
<div class=anim></div>
|
|
|
|
</main>
|
|
|
|
<script type="text/javascript" charset="utf-8">
|
|
|
|
(function () {
|
|
|
|
const TILE_COUNT = 5; // Number of tiles in x or y direction.
|
|
|
|
const TARGET_SIZE = 1000; // Image size in pixels both x and y direction.
|
|
|
|
const PATH = '/lottie.json';
|
|
|
|
|
2018-08-28 14:52:18 +00:00
|
|
|
let renderer = 'svg';
|
|
|
|
let hash = window.location.hash;
|
|
|
|
if (hash) {
|
|
|
|
renderer = hash.slice(1);
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:26:58 +00:00
|
|
|
// This global is used by puppeteer to determine if all tiles have finished drawing.
|
|
|
|
window._tileCount = 0;
|
|
|
|
|
|
|
|
// First load the animation for just a single tile
|
|
|
|
// so we can read out some values and calculate what
|
|
|
|
// the filmstrip should look like.
|
|
|
|
let anim = lottie.loadAnimation({
|
|
|
|
container: document.querySelector('.anim'),
|
2018-08-28 14:52:18 +00:00
|
|
|
renderer: renderer,
|
2018-03-19 18:26:58 +00:00
|
|
|
loop: false,
|
|
|
|
autoplay: true,
|
|
|
|
path: PATH,
|
|
|
|
rendererSettings: {
|
|
|
|
preserveAspectRatio:'xMidYMid meet'
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-20 20:03:13 +00:00
|
|
|
anim.addEventListener('data_ready', (e) => {
|
2018-03-19 18:26:58 +00:00
|
|
|
// Once the first tile is loaded, calculate what
|
|
|
|
// the filmstrip should look like.
|
2018-08-28 14:52:18 +00:00
|
|
|
let animationData = anim.animationData;
|
2018-08-29 17:52:10 +00:00
|
|
|
let totalFrames = anim.totalFrames;
|
2018-08-29 13:52:52 +00:00
|
|
|
// t_rate mimics DMSrcSink.cpp::SkottieSrc::draw
|
|
|
|
let t_rate = 1.0 / (TILE_COUNT * TILE_COUNT - 1);
|
2018-03-19 18:26:58 +00:00
|
|
|
|
|
|
|
let main = document.querySelector('main');
|
|
|
|
|
|
|
|
// Clear out the first div now that our measurements are done.
|
|
|
|
main.firstElementChild.remove();
|
|
|
|
|
2018-03-20 20:03:13 +00:00
|
|
|
// Add in all the tiles.
|
|
|
|
for (let i = 0; i < TILE_COUNT*TILE_COUNT; i++) {
|
2018-03-19 18:26:58 +00:00
|
|
|
let div = document.createElement('div');
|
|
|
|
div.classList.add('anim');
|
2018-08-29 13:52:52 +00:00
|
|
|
div.style.width = (TARGET_SIZE / TILE_COUNT) + 'px';
|
|
|
|
div.style.height = (TARGET_SIZE / TILE_COUNT) + 'px';
|
2018-03-19 18:26:58 +00:00
|
|
|
main.appendChild(div);
|
|
|
|
|
2018-08-28 14:52:18 +00:00
|
|
|
// create a new animation for each tile. It is tempting to try having
|
|
|
|
// one animation and "clone" each frame, but that doesn't work
|
|
|
|
// because of how bodymovin cleans up the URLObjects that are the path
|
|
|
|
// data for the svgs.
|
|
|
|
// We can re-use the animationData to avoid having to hit the
|
|
|
|
// (local) network a bunch of times.
|
2018-03-19 18:26:58 +00:00
|
|
|
let anim = lottie.loadAnimation({
|
|
|
|
container: div,
|
|
|
|
renderer: renderer,
|
|
|
|
loop: false,
|
2018-03-20 20:03:13 +00:00
|
|
|
autoplay: false,
|
2018-08-28 14:52:18 +00:00
|
|
|
animationData: animationData,
|
2018-03-19 18:26:58 +00:00
|
|
|
rendererSettings: {
|
|
|
|
preserveAspectRatio:'xMidYMid meet'
|
|
|
|
},
|
|
|
|
});
|
2018-03-20 20:03:13 +00:00
|
|
|
|
2018-08-29 13:52:52 +00:00
|
|
|
let t = Math.max(Math.min(t_rate * i, 1.0), 0.0);
|
2018-08-29 17:52:10 +00:00
|
|
|
let seekToFrame = totalFrames * t;
|
|
|
|
if (seekToFrame >= totalFrames) {
|
2018-08-29 13:52:52 +00:00
|
|
|
// bodymovin player sometimes draws blank when requesting
|
|
|
|
// to draw the very last frame. Subtracting a small value
|
|
|
|
// seems to fix this and make it draw the last frame.
|
2018-08-29 17:52:10 +00:00
|
|
|
seekToFrame -= .001;
|
2018-08-29 13:52:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 14:52:18 +00:00
|
|
|
// don't need to wait for data_ready because it's instantly ready.
|
2018-08-29 13:52:52 +00:00
|
|
|
console.log(`t = ${t}, go to frame ${seekToFrame}`);
|
|
|
|
anim.goToAndStop(seekToFrame, true);
|
2018-08-28 14:52:18 +00:00
|
|
|
window._tileCount += 1;
|
2018-03-19 18:26:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|