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

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

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/framework/fling-curve.dart ('k') | sky/framework/sky-element.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 <!--
2 // Copyright 2015 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 -->
6 <script>
7 const kDefaultAlpha = -5707.62;
8 const kDefaultBeta = 172;
9 const kDefaultGamma = 3.7;
10
11 function positionAtTime(t) {
12 return kDefaultAlpha * Math.exp(-kDefaultGamma * t) - kDefaultBeta * t - kDefa ultAlpha;
13 }
14
15 function velocityAtTime(t) {
16 return -kDefaultAlpha * kDefaultGamma * Math.exp(-kDefaultGamma * t) - kDefaul tBeta;
17 }
18
19 function timeAtVelocity(v) {
20 return -Math.log((v + kDefaultBeta) / (-kDefaultAlpha * kDefaultGamma)) / kDef aultGamma;
21 }
22
23 var kMaxVelocity = velocityAtTime(0);
24 var kCurveDuration = timeAtVelocity(0);
25
26 module.exports = class FlingCurve {
27 constructor(velocity, startTime) {
28 var startingVelocity = Math.min(kMaxVelocity, Math.abs(velocity));
29 this.timeOffset_ = timeAtVelocity(startingVelocity);
30 this.positionOffset_ = positionAtTime(this.timeOffset_);
31 this.startTime_ = startTime / 1000;
32 this.previousPosition_ = 0;
33 this.direction_ = Math.sign(velocity);
34 Object.preventExtensions(this);
35 }
36
37 update(timeStamp) {
38 var t = timeStamp / 1000 - this.startTime_ + this.timeOffset_;
39 if (t >= kCurveDuration)
40 return 0;
41 var position = positionAtTime(t) - this.positionOffset_;
42 var positionDelta = position - this.previousPosition_;
43 this.previousPosition_ = position;
44 return this.direction_ * Math.max(0, positionDelta);
45 }
46 };
47 </script>
OLDNEW
« no previous file with comments | « sky/framework/fling-curve.dart ('k') | sky/framework/sky-element.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698