JavaScript animation engine
Add canvas fireworks demo
Julian Garnierc9b4a8ee2a1b
diff --git a/examples/assets/css/styles.css b/examples/assets/css/styles.cssindex 7e7eecd4..0d98a2d3 100644--- a/examples/assets/css/styles.css+++ b/examples/assets/css/styles.css@@ -17,6 +17,8 @@ body {height: 100%;color: white;font-family: sans-serif;+ text-transform: uppercase;+ letter-spacing: 1px;-webkit-font-smoothing: antialiased;}diff --git a/examples/canvas-fireworks.html b/examples/canvas-fireworks.htmlnew file mode 100644index 00000000..ad8f55e2--- /dev/null+++ b/examples/canvas-fireworks.html@@ -0,0 +1,221 @@+<!DOCTYPE html>+<html>+<head>+ <title>Canvas fireworks | anime.js</title>+ <meta charset="utf-8">+ <link rel="icon" type="image/png" href="assets/img/favicon.png" />+ <link href="assets/css/styles.css" rel="stylesheet">+ <script src="../anime.js"></script>+ <style>+ .logo-animation {+ display: flex;+ align-items: center;+ justify-content: center;+ width: 100%;+ height: 100%;+ margin-top: -40px;+ }+ .letters {+ position: relative;+ display: flex;+ width: 682px;+ height: 162px;+ }+ .letter {+ position: relative;+ width: 162px;+ height: 162px;+ }+ .letter:not(:first-child) {+ margin-left: -42px;+ }+ .letter-i {+ z-index: 1;+ width: 82px;+ transform-origin: 100% 50%;+ }+ .dot {+ position: absolute;+ width: 42px;+ height: 42px;+ }+ .dot-i {+ top: 0;+ left: 240px;+ }+ .dot-e {+ bottom: 0;+ right: 0;+ }+ .logo-icon {+ display: flex;+ position: absolute;+ left: 230px;+ top: -10px;+ width: 222px;+ height: 62px;+ }+ .icon {+ width: 62px;+ height: 62px;+ opacity: 0;+ }+ .icon-text {+ position: absolute;+ top: 60px;+ left: 60px;+ width: 160px;+ height: 62px;+ }+ .icon-text path,+ .icon-text polygon {+ opacity: 0;+ }+ /*.letter, .dot {+ mix-blend-mode: lighten;+ }*/+ </style>+</head>+<body>+ <canvas></canvas>+ <script>+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');+ ga('create', 'UA-79927007-1', 'auto');+ ga('send', 'pageview');+ </script>+ <script>++ function getFontSize() {+ return parseFloat(getComputedStyle(document.documentElement).fontSize);+ }++ var canvasEl = document.querySelector('canvas');+ var ctx = canvasEl.getContext('2d');+ var tap = ('ontouchstart' in window || navigator.msMaxTouchPoints) ? 'touchstart' : 'mousedown';+ var numberOfParticules = 24;+ var distance = 200;+ var x = 0;+ var y = 0;+ var animations = [];+ var colors = ['#FF1461', '#18FF92', '#5A87FF', '#FBF38C'];++ function setCanvasSize() {+ canvasEl.width = window.innerWidth * 2;+ canvasEl.height = window.innerHeight * 2;+ canvasEl.style.width = window.innerWidth + 'px';+ canvasEl.style.height = window.innerHeight + 'px';+ canvasEl.getContext('2d').scale(2,2)+ }++ function updateCoords(e) {+ x = e.clientX || e.touches[0].clientX;+ y = e.clientY || e.touches[0].clientY;+ }++ function createCircle(x,y) {+ var p = {};+ p.x = x;+ p.y = y;+ p.color = colors[anime.random(0, colors.length - 1)];+ p.color = '#FFF';+ p.radius = 0;+ p.alpha = 1;+ p.lineWidth = 6;+ p.draw = function() {+ ctx.globalAlpha = p.alpha;+ ctx.beginPath();+ ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true);+ ctx.lineWidth = p.lineWidth;+ ctx.strokeStyle = p.color;+ ctx.stroke();+ ctx.globalAlpha = 1;+ }+ return p;+ }++ function createParticule(x,y) {+ var p = {};+ p.x = x;+ p.y = y;+ p.color = colors[anime.random(0, colors.length - 1)];+ p.radius = anime.random(getFontSize(), getFontSize() * 2);+ p.draw = function() {+ ctx.beginPath();+ ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true);+ ctx.fillStyle = p.color;+ ctx.fill();+ }+ return p;+ }++ function createParticles(x,y) {+ var particules = [];+ for (var i = 0; i < numberOfParticules; i++) {+ var p = createParticule(x, y);+ particules.push(p);+ }+ return particules;+ }++ function removeAnimation(animation) {+ var index = animations.indexOf(animation);+ if (index > -1) animations.splice(index, 1);+ }++ function animateParticules(x, y) {+ setCanvasSize();+ var particules = createParticles(x, y);+ var circle = createCircle(x, y);+ var particulesAnimation = anime({+ targets: particules,+ x: function(p) { return p.x + anime.random(-distance, distance); },+ y: function(p) { return p.y + anime.random(-distance, distance); },+ radius: 0,+ duration: function() { return anime.random(1200, 1800); },+ easing: 'easeOutExpo',+ complete: removeAnimation+ });+ var circleAnimation = anime({+ targets: circle,+ radius: function() { return anime.random(getFontSize() * 8.75, getFontSize() * 11.25); },+ lineWidth: 0,+ alpha: {+ value: 0,+ easing: 'linear',+ duration: function() { return anime.random(400, 600); }+ },+ duration: function() { return anime.random(1200, 1800); },+ easing: 'easeOutExpo',+ complete: removeAnimation+ });+ animations.push(particulesAnimation);+ animations.push(circleAnimation);+ }++ var mainLoop = anime({+ duration: Infinity,+ update: function() {+ ctx.clearRect(0, 0, canvasEl.width, canvasEl.height);+ animations.forEach(function(anim) {+ anim.animatables.forEach(function(animatable) {+ animatable.target.draw();+ });+ });+ }+ });++ document.addEventListener(tap, function(e) {+ updateCoords(e);+ animateParticules(x, y);+ ga('send', 'event', 'Fireworks', 'Click');+ }, false);++ window.addEventListener('resize', setCanvasSize, false);++ </script>+ <script src="assets/js/stats.js"></script>+</body>+</html>diff --git a/examples/ease-visualizer.html b/examples/ease-visualizer.htmlindex 807ed86e..da34dcee 100644--- a/examples/ease-visualizer.html+++ b/examples/ease-visualizer.html@@ -124,6 +124,7 @@border: 1px solid #09090B;background: transparent;margin: -1px 0 0 -1px;+ letter-spacing: 1px;}label {display: flex;