blob: c946a2aa2e70134099301a3e7fca1f1132393237 [file] [log] [blame]
bsalomon@google.com85003222012-03-28 14:44:37 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed76113a92015-02-02 12:55:02 -08007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkCanvas.h"
9#include "include/core/SkColorPriv.h"
10#include "include/core/SkMaskFilter.h"
11#include "include/utils/SkRandom.h"
12#include "samplecode/Sample.h"
bsalomon@google.com85003222012-03-28 14:44:37 +000013
reed76113a92015-02-02 12:55:02 -080014SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) {
reedd9adfe62015-02-01 19:01:04 -080015 if (!periodInSec) {
16 return 0;
17 }
reed76113a92015-02-02 12:55:02 -080018 double t = secs + phaseInSec;
reedd9adfe62015-02-01 19:01:04 -080019 t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
20 amplitude = SK_ScalarHalf * amplitude;
21 return amplitude * SkDoubleToScalar(sin(t)) + amplitude;
22}
23
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040024class AnimBlurView : public Sample {
Hal Canaryd7639af2019-07-17 09:08:11 -040025 SkScalar fBlurSigma = 0;
26 SkScalar fCircleRadius = 100;
bsalomon@google.com85003222012-03-28 14:44:37 +000027
Hal Canary8a027312019-07-03 10:55:44 -040028 SkString name() override { return SkString("AnimBlur"); }
bsalomon@google.com85003222012-03-28 14:44:37 +000029
mtklein36352bf2015-03-25 18:17:31 -070030 void onDrawContent(SkCanvas* canvas) override {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000031 static const SkBlurStyle gStyles[] = {
32 kNormal_SkBlurStyle,
33 kInner_SkBlurStyle,
34 kSolid_SkBlurStyle,
35 kOuter_SkBlurStyle,
bsalomon@google.com85003222012-03-28 14:44:37 +000036 };
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000037 SkRandom random;
bsalomon@google.com85003222012-03-28 14:44:37 +000038
robertphillips@google.com7460b372012-04-25 16:54:51 +000039 for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) {
bsalomon@google.com85003222012-03-28 14:44:37 +000040 SkPaint paint;
Mike Reed1be1f8d2018-03-14 13:01:17 -040041 paint.setMaskFilter(SkMaskFilter::MakeBlur(gStyles[i],
42 fBlurSigma));
bsalomon@google.com85003222012-03-28 14:44:37 +000043 paint.setColor(random.nextU() | 0xff000000);
44 canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1,
45 200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1,
reedd9adfe62015-02-01 19:01:04 -080046 fCircleRadius, paint);
bsalomon@google.com85003222012-03-28 14:44:37 +000047 }
reedd9adfe62015-02-01 19:01:04 -080048 }
49
Hal Canary41248072019-07-11 16:32:53 -040050 bool onAnimate(double nanos) override {
51 fBlurSigma = get_anim_sin(1e-9 * nanos, 100, 4, 5);
52 fCircleRadius = 3 + get_anim_sin(1e-9 * nanos, 150, 25, 3);
reedd9adfe62015-02-01 19:01:04 -080053 return true;
bsalomon@google.com85003222012-03-28 14:44:37 +000054 }
bsalomon@google.com85003222012-03-28 14:44:37 +000055};
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040056DEF_SAMPLE( return new AnimBlurView(); )