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

Side by Side Diff: sky/framework/animation/curves.sky

Issue 942413002: Port sky-drawer to Dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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/animation/curves.dart ('k') | sky/framework/animation/timer.dart » ('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 function evaluateCubic(a, b, m) {
8 // TODO(abarth): Would Math.pow be faster?
9 return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m
10 }
11
12 const kCubicErrorBound = 0.001;
13
14 class Linear {
15 transform(t) {
16 return t;
17 }
18 };
19
20 class Cubic {
21 constructor(a, b, c, d) {
22 this.a_ = a;
23 this.b_ = b;
24 this.c_ = c;
25 this.d_ = d;
26 Object.preventExtensions(this);
27 }
28
29 transform(t) {
30 var start = 0, end = 1;
31 while (1) {
32 var midpoint = (start + end) / 2;
33 var estimate = evaluateCubic(this.a_, this.c_, midpoint);
34
35 if (Math.abs(t - estimate) < kCubicErrorBound)
36 return evaluateCubic(this.b_, this.d_, midpoint);
37
38 if (estimate < t)
39 start = midpoint;
40 else
41 end = midpoint;
42 }
43 }
44 }
45
46 module.exports = {
47 Linear: Linear,
48 Cubic: Cubic,
49 linear: new Linear(),
50 ease: new Cubic(0.25, 0.1, 0.25, 1),
51 easeIn: new Cubic(0.42, 0, 1, 1),
52 easeOut: new Cubic(0, 0, 0.58, 1),
53 easeInOut: new Cubic(0.42, 0, 0.58, 1),
54 };
55 </script>
OLDNEW
« no previous file with comments | « sky/framework/animation/curves.dart ('k') | sky/framework/animation/timer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698