degToRad() V4
Converts degrees into radians.
const radians = utils.degToRad(degrees);
Parameters
Name | Accepts |
---|---|
degrees (opt) | Number |
Returns
A Number
if degrees are provided, otherwise a chain-able utility Function
to convert degrees to radians:
const degToRad = utils.degToRad();
degToRad(360); // 6.283185307179586
const roundDegToRad = utils.degToRad().round(2); // Convert degrees to radians then round to 2 decimal places
roundDegToRad(180); // 3.14
roundDegToRad(90); // 1.57
degToRad() code example
import { animate, createAnimatable, utils } from 'animejs';
const radAnimatable = createAnimatable('.rad', {
rotate: { unit: 'rad', duration: 0 },
});
const [ $deg ] = utils.$('.deg');
const degAnimation = animate($deg, {
rotate: '360deg',
ease: 'linear',
loop: true,
onUpdate: () => {
const degrees = utils.get($deg, 'rotate', false);
radAnimatable.rotate(utils.degToRad(degrees));
}
});
<div class="x-large spaced-evenly row">
<div class="col">
<div class="clock deg"></div>
<div class="label">degrees</div>
</div>
<div class="col">
<div class="clock rad"></div>
<div class="label">radians</div>
</div>
</div>