Flutter Engine
 
Loading...
Searching...
No Matches
SpringAnimation Class Reference

#include <spring_animation.h>

Inheritance diagram for SpringAnimation:

Instance Methods

(instancetype) - initWithStiffness:damping:mass:initialVelocity:fromValue:toValue:
 
(double) - curveFunction:
 

Properties

double stiffness
 
double damping
 
double mass
 
double initialVelocity
 
double fromValue
 
double toValue
 

Detailed Description

Definition at line 23 of file spring_animation.h.

Method Documentation

◆ curveFunction:

- (double) curveFunction: (double)  t

Definition at line 20 of file spring_animation.mm.

50 :(double)t {
51 const double x0 = _toValue - _fromValue;
52
53 double y;
54 if (_zeta < 1) {
55 // Under damped.
56 const double envelope = exp(-_zeta * _omega0 * t);
57 y = _toValue - envelope * (((_v0 + _zeta * _omega0 * x0) / _omega1) * sin(_omega1 * t) +
58 x0 * cos(_omega1 * t));
59 } else {
60 // Critically damped.
61 const double envelope = exp(-_omega0 * t);
62 y = _toValue - envelope * (x0 + (_v0 + _omega0 * x0) * t);
63 }
64
65 return y;
66}
double y

References damping, fromValue, initialVelocity, mass, self, stiffness, and toValue.

◆ initWithStiffness:damping:mass:initialVelocity:fromValue:toValue:

- (instancetype) initWithStiffness: (double)  stiffness
damping: (double)  damping
mass: (double)  mass
initialVelocity: (double)  initialVelocity
fromValue: (double)  fromValue
toValue: (double)  toValue 

Definition at line 20 of file spring_animation.mm.

27 :(double)stiffness
28 damping:(double)damping
29 mass:(double)mass
31 fromValue:(double)fromValue
32 toValue:(double)toValue {
33 self = [super init];
34 if (self) {
35 _stiffness = stiffness;
36 _damping = damping;
37 _mass = mass;
38 _initialVelocity = initialVelocity;
39 _fromValue = fromValue;
40 _toValue = toValue;
41
42 _zeta = _damping / (2 * sqrt(_stiffness * _mass)); // Damping ratio.
43 _omega0 = sqrt(_stiffness / _mass); // Undamped angular frequency of the oscillator.
44 _omega1 = _omega0 * sqrt(1.0 - _zeta * _zeta); // Exponential decay.
45 _v0 = -_initialVelocity;
46 }
47 return self;
48}

Property Documentation

◆ damping

- (double) damping
readnonatomicassign

Definition at line 35 of file spring_animation.h.

Referenced by curveFunction:, and TEST().

◆ fromValue

- (double) fromValue
readwritenonatomicassign

Definition at line 38 of file spring_animation.h.

Referenced by curveFunction:, TEST(), TEST(), and TEST().

◆ initialVelocity

- (double) initialVelocity
readnonatomicassign

Definition at line 37 of file spring_animation.h.

Referenced by curveFunction:, and TEST().

◆ mass

- (double) mass
readnonatomicassign

Definition at line 36 of file spring_animation.h.

Referenced by curveFunction:, and TEST().

◆ stiffness

- (double) stiffness
readnonatomicassign

Definition at line 34 of file spring_animation.h.

Referenced by curveFunction:, and TEST().

◆ toValue

- (double) toValue
readwritenonatomicassign

Definition at line 39 of file spring_animation.h.

Referenced by curveFunction:, TEST(), TEST(), and TEST().


The documentation for this class was generated from the following files: