Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
882f32bb
Commit
882f32bb
authored
Aug 18, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #666 from vlidholt/master
Adds bounce and elastic easing to animation curves
parents
e4ac5189
b9629155
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
25 deletions
+85
-25
action.dart
examples/game/lib/action.dart
+0
-25
game_demo.dart
examples/game/lib/game_demo.dart
+1
-0
curves.dart
packages/flutter/lib/animation/curves.dart
+84
-0
No files found.
examples/game/lib/action.dart
View file @
882f32bb
...
...
@@ -553,28 +553,3 @@ class _ColorDiff {
_ColorDiff
(
this
.
alpha
,
this
.
red
,
this
.
green
,
this
.
blue
);
}
double
_bounce
(
double
t
)
{
if
(
t
<
1.0
/
2.75
)
{
return
7.5625
*
t
*
t
;
}
else
if
(
t
<
2
/
2.75
)
{
t
-=
1.5
/
2.75
;
return
7.5625
*
t
*
t
+
0.75
;
}
else
if
(
t
<
2.5
/
2.75
)
{
t
-=
2.25
/
2.75
;
return
7.5625
*
t
*
t
+
0.9375
;
}
t
-=
2.625
/
2.75
;
return
7.5625
*
t
*
t
+
0.984375
;
}
class
BounceOutCurve
implements
Curve
{
const
BounceOutCurve
();
double
transform
(
double
t
)
{
return
_bounce
(
t
);
}
}
const
BounceOutCurve
bounceOut
=
const
BounceOutCurve
();
examples/game/lib/game_demo.dart
View file @
882f32bb
...
...
@@ -7,6 +7,7 @@ import 'sprites.dart';
import
'package:sky/rendering/object.dart'
;
import
'package:sky/widgets/framework.dart'
;
import
'package:sky/widgets/navigator.dart'
;
import
'package:sky/animation/curves.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
part
'game_demo_world.dart'
;
packages/flutter/lib/animation/curves.dart
View file @
882f32bb
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:math'
as
math
;
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
;
...
...
@@ -79,6 +81,82 @@ class Cubic implements Curve {
}
}
double
_bounce
(
double
t
)
{
if
(
t
<
1.0
/
2.75
)
{
return
7.5625
*
t
*
t
;
}
else
if
(
t
<
2
/
2.75
)
{
t
-=
1.5
/
2.75
;
return
7.5625
*
t
*
t
+
0.75
;
}
else
if
(
t
<
2.5
/
2.75
)
{
t
-=
2.25
/
2.75
;
return
7.5625
*
t
*
t
+
0.9375
;
}
t
-=
2.625
/
2.75
;
return
7.5625
*
t
*
t
+
0.984375
;
}
class
BounceInCurve
implements
Curve
{
const
BounceInCurve
();
double
transform
(
double
t
)
{
return
1.0
-
_bounce
(
1.0
-
t
);
}
}
class
BounceOutCurve
implements
Curve
{
const
BounceOutCurve
();
double
transform
(
double
t
)
{
return
_bounce
(
t
);
}
}
class
BounceInOutCurve
implements
Curve
{
const
BounceInOutCurve
();
double
transform
(
double
t
)
{
if
(
t
<
0.5
)
return
(
1.0
-
_bounce
(
1.0
-
t
))
*
0.5
;
else
return
_bounce
(
t
*
2.0
-
1.0
)
*
0.5
+
0.5
;
}
}
class
ElasticInCurve
implements
Curve
{
const
ElasticInCurve
([
this
.
period
=
0.4
]);
final
double
period
;
double
transform
(
double
t
)
{
double
s
=
period
/
4.0
;
t
=
t
-
1.0
;
return
-
math
.
pow
(
2.0
,
10.0
*
t
)
*
math
.
sin
((
t
-
s
)
*
(
math
.
PI
*
2.0
)
/
period
);
}
}
class
ElasticOutCurve
implements
Curve
{
const
ElasticOutCurve
([
this
.
period
=
0.4
]);
final
double
period
;
double
transform
(
double
t
)
{
double
s
=
period
/
4.0
;
return
math
.
pow
(
2.0
,
-
10
*
t
)
*
math
.
sin
((
t
-
s
)
*
(
math
.
PI
*
2.0
)
/
period
)
+
1.0
;
}
}
class
ElasticInOutCurve
implements
Curve
{
const
ElasticInOutCurve
([
this
.
period
=
0.4
]);
final
double
period
;
double
transform
(
double
t
)
{
double
s
=
period
/
4.0
;
t
=
2.0
*
t
-
1.0
;
if
(
t
<
0.0
)
return
-
0.5
*
math
.
pow
(
2.0
,
10.0
*
t
)
*
math
.
sin
((
t
-
s
)
*
(
math
.
PI
*
2.0
)
/
period
);
else
return
math
.
pow
(
2.0
,
-
10.0
*
t
)
*
math
.
sin
((
t
-
s
)
*
(
math
.
PI
*
2.0
)
/
period
)
*
0.5
+
1.0
;
}
}
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
);
...
...
@@ -86,3 +164,9 @@ 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
);
const
ParabolicRise
parabolicRise
=
const
ParabolicRise
();
const
ParabolicFall
parabolicFall
=
const
ParabolicFall
();
const
BounceInCurve
bounceIn
=
const
BounceInCurve
();
const
BounceOutCurve
bounceOut
=
const
BounceOutCurve
();
const
BounceInOutCurve
bounceInOut
=
const
BounceInOutCurve
();
const
ElasticInCurve
elasticIn
=
const
ElasticInCurve
();
const
ElasticOutCurve
elasticOut
=
const
ElasticOutCurve
();
const
ElasticInOutCurve
elasticInOut
=
const
ElasticInOutCurve
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment