Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: sky/framework/fling-curve.dart

Issue 950603002: Port sky-scrollable to Dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: less setAttributes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/example-scrollable/index.sky ('k') | sky/framework/fling-curve.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 "dart:math" as math;
6
7 const double _kDefaultAlpha = -5707.62;
8 const double _kDefaultBeta = 172.0;
9 const double _kDefaultGamma = 3.7;
10
11 double _positionAtTime(double t) {
12 return kDefaultAlpha * math.exp(-kDefaultGamma * t) - kDefaultBeta * t - kDefa ultAlpha;
13 }
14
15 double _velocityAtTime(double t) {
16 return -kDefaultAlpha * kDefaultGamma * math.exp(-kDefaultGamma * t) - kDefaul tBeta;
17 }
18
19 double _timeAtVelocity(double v) {
20 return -math.log((v + kDefaultBeta) / (-kDefaultAlpha * kDefaultGamma)) / kDef aultGamma;
21 }
22
23 final double _kMaxVelocity = _velocityAtTime(0.0);
24 final double _kCurveDuration = _timeAtVelocity(0.0);
25
26 class FlingCurve {
27 double _timeOffset;
28 double _positionOffset;
29 double _startTime;
30 double _previousPosition;
31 double _direction;
32
33 FlingCurve(double velocity, double startTime) {
34 double startingVelocity = math.min(_kMaxVelocity, velocity.abs());
35 _timeOffset = _velocityAtTime(startingVelocity);
36 _positionOffset = _positionAtTime(_timeOffset);
37 _startTime = startTime / 1000.0;
38 _previousPosition = 0.0;
39 _direction = velocity.sign;
40 }
41
42 double update(double timeStamp) {
43 double t = timeStamp / 1000.0 - _startTime + _timeOffset;
44 if (t >= _kCurveDuration)
45 return 0.0;
46 double position = _positionAtTime(t) - _positionOffset;
47 double positionDelta = position - _previousPosition;
48 _previousPosition = position;
49 return _direction * math.max(0.0, positionDelta);
50 }
51 }
OLDNEW
« no previous file with comments | « sky/examples/example-scrollable/index.sky ('k') | sky/framework/fling-curve.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698