Smooth animations with Math.sin()
Remember geometry class? Well, I don't.
But I do know that when you're making a synthesizer, a sine wave produces a nice smooth sound.
And as it turns out, a sine wave has a smooth curve. So, you can use Math.sin()
to animate smooth motions like so:
const domNode = document.querySelector('#waveEmoji')
function animate() {
const a = Math.sin(Date.now() / speed) * range + offset;
domNode.style = `transform: rotate(${a}deg);`;
requestAnimationFrame(animate);
}
animate();
Tweet