bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #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.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 13 | |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 14 | SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) { |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 15 | if (!periodInSec) { |
| 16 | return 0; |
| 17 | } |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 18 | double t = secs + phaseInSec; |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 19 | t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec; |
| 20 | amplitude = SK_ScalarHalf * amplitude; |
| 21 | return amplitude * SkDoubleToScalar(sin(t)) + amplitude; |
| 22 | } |
| 23 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 24 | class AnimBlurView : public Sample { |
Hal Canary | d7639af | 2019-07-17 09:08:11 -0400 | [diff] [blame] | 25 | SkScalar fBlurSigma = 0; |
| 26 | SkScalar fCircleRadius = 100; |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 27 | |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 28 | SkString name() override { return SkString("AnimBlur"); } |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 29 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | void onDrawContent(SkCanvas* canvas) override { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 31 | static const SkBlurStyle gStyles[] = { |
| 32 | kNormal_SkBlurStyle, |
| 33 | kInner_SkBlurStyle, |
| 34 | kSolid_SkBlurStyle, |
| 35 | kOuter_SkBlurStyle, |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 36 | }; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 37 | SkRandom random; |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 38 | |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 39 | for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) { |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 40 | SkPaint paint; |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 41 | paint.setMaskFilter(SkMaskFilter::MakeBlur(gStyles[i], |
| 42 | fBlurSigma)); |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 43 | 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, |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 46 | fCircleRadius, paint); |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 47 | } |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 50 | 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); |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 53 | return true; |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 54 | } |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 55 | }; |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 56 | DEF_SAMPLE( return new AnimBlurView(); ) |