Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2497e5d

Browse files
committed
Merge pull request #6 from domokit/forces.dart
Add forces.dart
2 parents 08a1220 + 2092367 commit 2497e5d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

sky/sdk/lib/animation/forces.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2015 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:newton/newton.dart';
6+
7+
// Base class for creating Simulations for the animation Timeline.
8+
abstract class Force {
9+
Simulation release(double position, double velocity);
10+
}
11+
12+
class SpringForce extends Force {
13+
SpringForce(this.spring, {this.left: 0.0, this.right: 1.0});
14+
15+
final SpringDescription spring;
16+
// Where to put the spring's resting point when releasing left or right,
17+
// respectively.
18+
final double left, right;
19+
20+
Simulation release(double position, double velocity) {
21+
// Target just past the endpoint, because the animation will stop once the
22+
// Spring gets within the epsilon, and we want to stop at the endpoint.
23+
double target = velocity < 0.0 ?
24+
this.left - _kEpsilon : this.right + _kEpsilon;
25+
return new SpringSimulation(spring, position, target, velocity);
26+
}
27+
}
28+
29+
final SpringDescription _kDefaultSpringDesc =
30+
new SpringDescription.withDampingRatio(
31+
mass: 1.0, springConstant: 500.0, ratio: 1.0);
32+
final SpringForce kDefaultSpringForce = new SpringForce(_kDefaultSpringDesc);
33+
34+
const double _kEpsilon = 0.001;

0 commit comments

Comments
 (0)