2012-03-28 14:44:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2015-02-02 20:55:02 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkMaskFilter.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2012-03-28 14:44:37 +00:00
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) {
|
2015-02-02 03:01:04 +00:00
|
|
|
if (!periodInSec) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-02 20:55:02 +00:00
|
|
|
double t = secs + phaseInSec;
|
2015-02-02 03:01:04 +00:00
|
|
|
t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
|
|
|
|
amplitude = SK_ScalarHalf * amplitude;
|
|
|
|
return amplitude * SkDoubleToScalar(sin(t)) + amplitude;
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class AnimBlurView : public Sample {
|
2019-07-17 13:08:11 +00:00
|
|
|
SkScalar fBlurSigma = 0;
|
|
|
|
SkScalar fCircleRadius = 100;
|
2012-03-28 14:44:37 +00:00
|
|
|
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("AnimBlur"); }
|
2012-03-28 14:44:37 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2014-04-28 16:25:35 +00:00
|
|
|
static const SkBlurStyle gStyles[] = {
|
|
|
|
kNormal_SkBlurStyle,
|
|
|
|
kInner_SkBlurStyle,
|
|
|
|
kSolid_SkBlurStyle,
|
|
|
|
kOuter_SkBlurStyle,
|
2012-03-28 14:44:37 +00:00
|
|
|
};
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom random;
|
2012-03-28 14:44:37 +00:00
|
|
|
|
2012-04-25 16:54:51 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) {
|
2012-03-28 14:44:37 +00:00
|
|
|
SkPaint paint;
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(gStyles[i],
|
|
|
|
fBlurSigma));
|
2012-03-28 14:44:37 +00:00
|
|
|
paint.setColor(random.nextU() | 0xff000000);
|
|
|
|
canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1,
|
|
|
|
200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1,
|
2015-02-02 03:01:04 +00:00
|
|
|
fCircleRadius, paint);
|
2012-03-28 14:44:37 +00:00
|
|
|
}
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 20:32:53 +00:00
|
|
|
bool onAnimate(double nanos) override {
|
|
|
|
fBlurSigma = get_anim_sin(1e-9 * nanos, 100, 4, 5);
|
|
|
|
fCircleRadius = 3 + get_anim_sin(1e-9 * nanos, 150, 25, 3);
|
2015-02-02 03:01:04 +00:00
|
|
|
return true;
|
2012-03-28 14:44:37 +00:00
|
|
|
}
|
|
|
|
};
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new AnimBlurView(); )
|