vaweGitHub

SpringsJetpack Compose

Compose MediumBouncy with StiffnessLow

Both constants come from the Spring object: a damping ratio of 0.5 and the low stiffness, 200. Stiffness 200, damping 14.14 and mass 1 give a damping ratio of 0.5, so the spring is underdamped. It settles to within 0.1% in 0.9 s. It passes the end value by up to 16.3% at 0.256 s and crosses it 3 times.

Demo

Progress against time. The time axis runs 0 to 0.9 s, the settle time.0100.51progress50%90%
Dashed: a straight line. The dot and the line move with the box on the right.
Compose MediumBouncy with StiffnessLow
linear

Both boxes take 0.9 s. This is real time.

Your system asks for reduced motion, so nothing plays. The chart shows the whole move.

Code

A spring has no fixed duration, so the CSS takes the settle time (900 ms) and a linear() string that follows the spring.

css linear()
transition: translate 900ms linear(0, 0.0054, 0.0209, 0.0453, 0.0774, 0.1161, 0.1603, 0.2091, 0.2613, 0.3162, 0.3729, 0.4305, 0.4884, 0.546, 0.6026, 0.6577, 0.711, 0.7619, 0.8103, 0.8558, 0.8983, 0.9376, 0.9736, 1.0063, 1.0356, 1.0616, 1.0843, 1.1038, 1.1203, 1.1338, 1.1445, 1.1526, 1.1583, 1.1617, 1.1631, 1.1625, 1.1603, 1.1566, 1.1516, 1.1455, 1.1384, 1.1306, 1.1222, 1.1133, 1.1041, 1.0948, 1.0853, 1.0759, 1.0666, 1.0576, 1.0488, 1.0405, 1.0325, 1.025, 1.0179, 1.0114, 1.0054, 1, 0.9951, 0.9908, 0.9869, 0.9837, 0.9809, 0.9786, 0.9767, 0.9753, 0.9743, 0.9737, 0.9734, 0.9735, 0.9738, 0.9743, 0.9751, 0.9761, 0.9772, 0.9784, 0.9798, 0.9812, 0.9827, 0.9842, 0.9858, 0.9873, 0.9888, 0.9903, 0.9918, 0.9931, 0.9944, 0.9957, 0.9969, 0.9979, 0.9989, 0.9998, 1.0006, 1.0014, 1.002, 1.0026, 1.003, 1.0034, 1.0037, 1.004, 1.0042, 1.0043, 1.0043, 1.0043, 1.0043, 1.0042, 1.0041, 1.0039, 1.0038, 1.0036, 1.0033, 1.0031, 1.0029, 1.0026, 1.0024, 1.0021, 1.0019, 1.0016, 1.0014, 1.0012, 1);
web animations api
el.animate({ translate: ['0 0', '240px 0'] }, { duration: 900, easing: 'linear(0, 0.0054, 0.0209, 0.0453, 0.0774, 0.1161, 0.1603, 0.2091, 0.2613, 0.3162, 0.3729, 0.4305, 0.4884, 0.546, 0.6026, 0.6577, 0.711, 0.7619, 0.8103, 0.8558, 0.8983, 0.9376, 0.9736, 1.0063, 1.0356, 1.0616, 1.0843, 1.1038, 1.1203, 1.1338, 1.1445, 1.1526, 1.1583, 1.1617, 1.1631, 1.1625, 1.1603, 1.1566, 1.1516, 1.1455, 1.1384, 1.1306, 1.1222, 1.1133, 1.1041, 1.0948, 1.0853, 1.0759, 1.0666, 1.0576, 1.0488, 1.0405, 1.0325, 1.025, 1.0179, 1.0114, 1.0054, 1, 0.9951, 0.9908, 0.9869, 0.9837, 0.9809, 0.9786, 0.9767, 0.9753, 0.9743, 0.9737, 0.9734, 0.9735, 0.9738, 0.9743, 0.9751, 0.9761, 0.9772, 0.9784, 0.9798, 0.9812, 0.9827, 0.9842, 0.9858, 0.9873, 0.9888, 0.9903, 0.9918, 0.9931, 0.9944, 0.9957, 0.9969, 0.9979, 0.9989, 0.9998, 1.0006, 1.0014, 1.002, 1.0026, 1.003, 1.0034, 1.0037, 1.004, 1.0042, 1.0043, 1.0043, 1.0043, 1.0043, 1.0042, 1.0041, 1.0039, 1.0038, 1.0036, 1.0033, 1.0031, 1.0029, 1.0026, 1.0024, 1.0021, 1.0019, 1.0016, 1.0014, 1.0012, 1)', fill: 'both' });
vawe
import { spring, springDuration, springLinear } from '../../core/motion/springs.js';

const k = 200, d = 14.14;

// per-frame code (window.seek, vawe.onFrame): t is seconds since the move starts
const x = 240 * spring(t, k, d);

// CSS and Web Animations: 900 ms, the linear() string above
el.animate(
  { translate: ['0 0', '240px 0'] },
  { duration: springDuration(k, d) * 1000, easing: springLinear(k, d), fill: 'both' },
);

Numbers

Stiffness
200k, with mass 1
Damping
14.14d, with mass 1
Damping ratio
0.5underdamped
Settle time
0.9 swithin 0.1% of the end
Overshoot
16.3%peak at 0.256 s
Crosses the end
3times
50% of travel
0.092 s10% of the settle time
90% of travel
0.151 s17% of the settle time
Natural frequency
14.14 rad/ssqrt(k)
Ring period
0.513 sone swing of the overshoot
Peak speed
6.94xtimes the average speed
linear() points
121within 0.13% of travel

Computed with spring() and springDuration() from core/motion/springs.js. The settle time is the last moment the spring is more than 0.1% away from the end value; a library stops its own spring by its own rest thresholds, so its clock can run shorter.

Source of the numbers

Jetpack Composeandroidx main at 9adbcd8 (compose animation-core 1.14.0-alpha01)
spring(dampingRatio = Spring.DampingRatioMediumBouncy (0.5), stiffness = Spring.StiffnessLow (200))Spring.DampingRatioMediumBouncy, Spring.StiffnessLow

Conversion: Stiffness is used as it is with mass 1 (SpringSimulation takes the natural frequency as sqrt(stiffness)). damping = 2 x dampingRatio x sqrt(stiffness), the same c = 2 x naturalFreq x dampingRatio that SpringSimulation.getAcceleration uses.

The four closest curves in this set, by the average gap between the two springs over their first seconds. A gap of 0.01 is invisible; 0.1 is a different feel.

More springs