Commit 7c23eded authored by Hixie's avatar Hixie

SawTooth

parent 5b8b9812
......@@ -28,6 +28,16 @@ class Linear implements Curve {
double transform(double t) => t;
}
/// A sawtooth curve that repeats a given number of times over the unit interval.
class SawTooth implements Curve {
const SawTooth(this.count);
final int count;
double transform(double t) {
t *= count;
return t - t.truncateToDouble();
}
}
/// A curve that is 0.0 until start, then curved from 0.0 to 1.0 at end, then 1.0.
class Interval implements Curve {
const Interval(this.start, this.end, { this.curve: Curves.linear });
......
......@@ -191,42 +191,22 @@ class CircularProgressIndicator extends ProgressIndicator {
_CircularProgressIndicatorState createState() => new _CircularProgressIndicatorState();
}
// This class assumes that the incoming animation is a linear 0.0..1.0.
class _RepeatingCurveTween extends Animatable<double> {
_RepeatingCurveTween({ this.curve, this.repeats });
Curve curve;
int repeats;
double evaluate(Animation<double> animation) {
double t = animation.value;
t *= repeats;
t -= t.truncateToDouble();
if (t == 0.0 || t == 1.0) {
assert(curve.transform(t).round() == t);
return t;
}
return curve.transform(t);
}
}
// Tweens used by circular progress indicator
final _RepeatingCurveTween _kStrokeHeadTween = new _RepeatingCurveTween(
curve: new Interval(0.0, 0.5, curve: Curves.fastOutSlowIn),
repeats: 5
);
final _RepeatingCurveTween _kStrokeTailTween = new _RepeatingCurveTween(
curve: new Interval(0.5, 1.0, curve: Curves.fastOutSlowIn),
repeats: 5
);
final StepTween _kStepTween = new StepTween(begin: 0, end: 5);
final _RepeatingCurveTween _kRotationTween = new _RepeatingCurveTween(
curve: Curves.linear,
repeats: 5
);
final Animatable<double> _kStrokeHeadTween = new CurveTween(
curve: new Interval(0.0, 0.5, curve: Curves.fastOutSlowIn)
).chain(new CurveTween(
curve: new SawTooth(5)
));
final Animatable<double> _kStrokeTailTween = new CurveTween(
curve: new Interval(0.5, 1.0, curve: Curves.fastOutSlowIn)
).chain(new CurveTween(
curve: new SawTooth(5)
));
final Animatable<int> _kStepTween = new StepTween(begin: 0, end: 5);
final Animatable<double> _kRotationTween = new CurveTween(curve: new SawTooth(5));
class _CircularProgressIndicatorState extends State<CircularProgressIndicator> {
AnimationController _animationController;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment