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

Unified Diff: sky/framework/animation/curves.dart

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/animation/controller.sky ('k') | sky/framework/animation/curves.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/animation/curves.dart
diff --git a/sky/framework/animation/curves.dart b/sky/framework/animation/curves.dart
new file mode 100644
index 0000000000000000000000000000000000000000..367d4cd4069110baa5ccd00eeb84d6df03c0a6e2
--- /dev/null
+++ b/sky/framework/animation/curves.dart
@@ -0,0 +1,54 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+double _evaluateCubic(double a, double b, double m) {
+ // TODO(abarth): Would Math.pow be faster?
+ return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m;
+}
+
+const double _kCubicErrorBound = 0.001;
+
+abstract class Curve {
+ double transform(double t);
+}
+
+class Linear implements Curve {
+ const Linear();
+
+ double transform(double t) {
+ return t;
+ }
+}
+
+class Cubic implements Curve {
+ final double a;
+ final double b;
+ final double c;
+ final double d;
+
+ const Cubic(this.a, this.b, this.c, this.d);
+
+ double transform(double t) {
+ double start = 0.0;
+ double end = 1.0;
+ while (true) {
+ double midpoint = (start + end) / 2;
+ double estimate = _evaluateCubic(a, c, midpoint);
+
+ if ((t - estimate).abs() < _kCubicErrorBound)
+ return _evaluateCubic(b, d, midpoint);
+
+ if (estimate < t)
+ start = midpoint;
+ else
+ end = midpoint;
+ }
+ }
+}
+
+const Linear linear = const Linear();
+const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0);
+const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0);
+const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0);
+const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0);
« no previous file with comments | « sky/framework/animation/controller.sky ('k') | sky/framework/animation/curves.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698