You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To simulate an object under constant force (e.g. gravity) hitting a surface with a constant coefficient of restitution. The function I've defined below is a function generating function, which takes two parameters: the number of bounces and the coefficient of restitution (called "decay"). A number of pre-calculations are performed to improve the performance of the actual transition function.
bounce: function(bounces, decay) {
// default values
if(decay == null) decay = 1/3;
if(bounces == null) bounces = 2;
// solve geometric series to calculate speed
var rootd = Math.sqrt(decay);
var rootdn = Math.sqrt(Math.pow(decay, bounces));
var f = Math.pow((1 + rootd - (2 * rootdn)) / (1 - rootd), 2);
// pre-calculate offsets
var offsets = [];
var offset = 0;
var apex = 1;
for(var b = 0; b < bounces; b++) {
offsets.push(offset)
offset += Math.sqrt(apex / f);
apex *= decay;
offset += Math.sqrt(apex / f);
}
// generate the bounce function
return (function (pos) {
var h = 0;
var apex = 1;
for(var b = 0; b < bounces; b++) {
h = Math.max(h, apex - (f * Math.pow(pos - offsets[b], 2)));
apex *= decay;
}
return 1 - h;
});
},
Usage:
transition: Effect.Transitions.bounce() // use default values of 5, 1/3
or
transition: Effect.Transitions.bounce(3) // 3 bounces, default decay (1/3)
or
transition: Effect.Transitions.bounce(4, 1/2) // 4 bounces, decay 1/2
The text was updated successfully, but these errors were encountered:
To simulate an object under constant force (e.g. gravity) hitting a surface with a constant coefficient of restitution. The function I've defined below is a function generating function, which takes two parameters: the number of bounces and the coefficient of restitution (called "decay"). A number of pre-calculations are performed to improve the performance of the actual transition function.
Usage:
transition: Effect.Transitions.bounce() // use default values of 5, 1/3
or
transition: Effect.Transitions.bounce(3) // 3 bounces, default decay (1/3)
or
transition: Effect.Transitions.bounce(4, 1/2) // 4 bounces, decay 1/2
The text was updated successfully, but these errors were encountered: