From 2e19170689d6e3deabd85b8c5ee95b56ef4d1710 Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 3 Jul 2019 00:28:06 +1000 Subject: [PATCH] bash circle --- client/src/components/anims/bash.circle.jsx | 99 +++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 client/src/components/anims/bash.circle.jsx diff --git a/client/src/components/anims/bash.circle.jsx b/client/src/components/anims/bash.circle.jsx new file mode 100644 index 00000000..eb8974e3 --- /dev/null +++ b/client/src/components/anims/bash.circle.jsx @@ -0,0 +1,99 @@ +const preact = require('preact'); +const { Component } = require('preact'); + +const anime = require('animejs').default; + +const { TIMES } = require('../../constants'); + +class Bash extends Component { + constructor() { + super(); + this.animations = []; + } + + render() { + return ( + + + + + + + + + + + + ); + } + + componentDidMount() { + this.animations.push(anime({ + targets: ['#bash'], + opacity: [ + { value: 1, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.2 }, + { value: 0, delay: TIMES.TARGET_DURATION_MS * 0.6, duration: TIMES.TARGET_DURATION_MS * 0.2 }, + ], + easing: 'easeInOutSine', + })); + + this.animations.push(anime({ + targets: ['#bash'], + scale: { + value: 1, + delay: TIMES.TARGET_DELAY_MS, + duration: TIMES.TARGET_DURATION_MS * 0.2, + easing: 'easeInExpo', + }, + rotate: { + value: 180, + easing: 'linear', + loop: true, + delay: TIMES.TARGET_DELAY_MS, + duration: TIMES.TARGET_DURATION_MS, + }, + delay: TIMES.TARGET_DELAY_MS + TIMES.TARGET_DURATION_MS * 0.1, + duration: TIMES.TARGET_DURATION_MS * 0.2, + easing: 'easeOutSine', + })); + + this.animations.push(anime({ + targets: ['#bashFilter feTurbulence', '#bashFilter feDisplacementMap'], + baseFrequency: 2, + scale: 10, + numOctaves: 5, + easing: 'easeOutSine', + + delay: TIMES.TARGET_DELAY_MS, + duration: TIMES.TARGET_DURATION_MS, + })); + } + + // this is necessary because + // skipping / timing / unmounting race conditions + // can cause the animations to cut short, this will ensure the values are reset + // because preact will recycle all these components + componentWillUnmount() { + for (let i = this.animations.length - 1; i >= 0; i--) { + this.animations[i].reset(); + } + } +} + +module.exports = Bash;