From a037d5e93bdca93a087d8c4cdd76ae246d83efa3 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 11 Jun 2019 19:50:59 +1000 Subject: [PATCH] amp and hex --- client/package.json | 1 + client/src/components/svgs/amplify.jsx | 41 ++++++--------- client/src/components/svgs/hex.jsx | 71 +++++++++++--------------- 3 files changed, 47 insertions(+), 66 deletions(-) diff --git a/client/package.json b/client/package.json index cfb5ac49..90f5fbdb 100644 --- a/client/package.json +++ b/client/package.json @@ -14,6 +14,7 @@ "author": "", "license": "UNLICENSED", "dependencies": { + "anime": "^0.1.2", "animejs": "^3.0.1", "async": "^2.6.2", "borc": "^2.0.3", diff --git a/client/src/components/svgs/amplify.jsx b/client/src/components/svgs/amplify.jsx index 5b308ead..9a1df5e0 100644 --- a/client/src/components/svgs/amplify.jsx +++ b/client/src/components/svgs/amplify.jsx @@ -1,30 +1,22 @@ const preact = require('preact'); const { Component } = require('preact'); -class TrippyTriangle extends Component { +const anime = require('animejs').default; + +class Amplify extends Component { constructor() { super(); - this.state = { delta: 0 }; - this.progress = this.progress.bind(this); + this.id = Math.random(); } render() { - const { delta } = this.state; - - const curvePoint = 200 * Math.sin(delta); - - const path = ` - M0,100 - C 100,${100 - curvePoint} - 100,${100 + curvePoint} - 200,100 - `; + const path = 'M0,100 C100,-100 100,300 200,100'; return ( @@ -32,20 +24,21 @@ class TrippyTriangle extends Component { ); } - progress() { - const delta = this.state.delta + 0.1; - this.setState({ delta }); - if (delta > 20) return false; - requestAnimationFrame(this.progress); - } - componentDidMount() { - requestAnimationFrame(this.progress); + const altPath = 'M0,100 C100,300 100,-100 200,100'; + anime({ + targets: '#hex path', + d: [{ value: altPath }], + stroke: ['#a52a2a', '#3498db'], + duration: 1000, + loop: true, + direction: 'alternate', + easing: 'easeInOutSine', + }); } componentWillUnmount() { - // clearAnimation(this.props.id); } } -module.exports = TrippyTriangle; +module.exports = Amplify; diff --git a/client/src/components/svgs/hex.jsx b/client/src/components/svgs/hex.jsx index 4904079e..ec1c0ae0 100644 --- a/client/src/components/svgs/hex.jsx +++ b/client/src/components/svgs/hex.jsx @@ -1,61 +1,48 @@ const preact = require('preact'); const { Component } = require('preact'); -class TrippyTriangle extends Component { - constructor() { - super(); - this.state = { delta: 0 }; - this.progress = this.progress.bind(this); - } +const anime = require('animejs').default; +// shamelessly lifted from teh anime docs +// https://animejs.com/documentation/#svgAttr + +class Hex extends Component { render() { - const { delta } = this.state; - - const curvePoint = 200 * Math.sin(delta); - - const curve = min => min * 2 + (min / 2) * Math.sin(delta); - return ( - - - - - - + viewBox="0 0 128 128"> + + + + + ); } - progress() { - const delta = this.state.delta + 0.1; - this.setState({ delta }); - requestAnimationFrame(this.progress); - } - componentDidMount() { - requestAnimationFrame(this.progress); - } + anime({ + targets: ['.hex-anim polygon'], + points: '64 69.88600002141976 8.574 99.91603773440568 62.29420564057706 66.93105659089863 64 3.916037734405676 65.70579435942294 66.93105659089863 119.426 99.91603773440568', + loop: true, + direction: 'alternate', + easing: 'easeInOutExpo', + }); - componentWillUnmount() { - // clearAnimation(this.props.id); + anime({ + targets: ['feTurbulence', 'feDisplacementMap'], + points: '64 69.88600002141976 8.574 99.91603773440568 62.29420564057706 66.93105659089863 64 3.916037734405676 65.70579435942294 66.93105659089863 119.426 99.91603773440568', + baseFrequency: 0.05, + scale: 15, + loop: true, + direction: 'alternate', + easing: 'easeInOutExpo', + }); } } -module.exports = TrippyTriangle; +module.exports = Hex;