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

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

Issue 886723002: Add sky-drawer to the framework (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: nit 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
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 return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m
esprehn 2015/01/29 19:03:57 I wonder if this is faster or slow than just using
abarth-chromium 2015/01/29 19:16:45 I'll add a TODO comment with that question.
abarth-chromium 2015/01/29 19:16:45 I'll add a TODO comment with that question.
9 }
10
11 const kCubicErrorBound = 0.001;
12
13 class Linear {
14 transform(t) {
15 return t;
16 }
17 };
18
19 class Cubic {
20 constructor(a, b, c, d) {
21 this.a_ = a;
22 this.b_ = b;
23 this.c_ = c;
24 this.d_ = d;
25 Object.preventExtensions(this);
26 }
27
28 transform(t) {
29 var start = 0, end = 1;
30 while (1) {
31 var midpoint = (start + end) / 2;
32 var estimate = evaluateCubic(this.a_, this.c_, midpoint);
33
34 if (Math.abs(t - estimate) < kCubicErrorBound)
35 return evaluateCubic(this.b_, this.d_, midpoint);
36
37 if (estimate < t)
38 start = midpoint;
39 else
40 end = midpoint;
41 }
42 }
43 }
44
45 module.exports = {
46 Cubic: Cubic,
47 linear: new Linear(),
esprehn 2015/01/29 19:03:57 Why expose the Cubic class not but the Linear one?
abarth-chromium 2015/01/29 19:16:45 I'll expose the Linear class. Its constructor doe
48 ease: new Cubic(0.25, 0.1, 0.25, 1),
49 easeIn: new Cubic(0.42, 0, 1, 1),
50 easeOut: new Cubic(0, 0, 0.58, 1),
51 easeInOut: new Cubic(0.42, 0, 0.58, 1),
52 };
53 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698