| 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 |
*/ |
| 7 |
|
| 8 |
#include "include/core/SkBlurTypes.h" |
| 9 |
#include "include/core/SkCanvas.h" |
| 10 |
#include "include/core/SkMaskFilter.h" |
| 11 |
#include "src/base/SkRandom.h" |
| 12 |
#include "src/core/SkColorPriv.h" |
| 13 |
#include "tools/viewer/Slide.h" |
| 14 |
|
| 15 |
#include <iterator> |
| 16 |
|
| 17 |
SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) { |
| 18 |
if (!periodInSec) { |
| 19 |
return 0; |
| 20 |
} |
| 21 |
double t = secs + phaseInSec; |
| 22 |
t *= (2 * SK_ScalarPI) / periodInSec; |
| 23 |
amplitude = SK_ScalarHalf * amplitude; |
| 24 |
return amplitude * SkDoubleToScalar(sin(t)) + amplitude; |
| 25 |
} |
| 26 |
|
| 27 |
class AnimBlurSlide : public Slide { |
| 28 |
SkScalar fBlurSigma = 0; |
| 29 |
SkScalar fCircleRadius = 100; |
| 30 |
|
| 31 |
public: |
| 32 |
AnimBlurSlide() { fName ="AnimBlur"; } |
| 33 |
|
| 34 |
void draw(SkCanvas* canvas) override { |
| 35 |
static const SkBlurStyle gStyles[] = { |
| 36 |
kNormal_SkBlurStyle, |
| 37 |
kInner_SkBlurStyle, |
| 38 |
kSolid_SkBlurStyle, |
| 39 |
kOuter_SkBlurStyle, |
| 40 |
}; |
| 41 |
SkRandom random; |
| 42 |
|
| 43 |
for (size_t i = 0; i < std::size(gStyles); ++i) { |
| 44 |
SkPaint paint; |
| 45 |
paint.setMaskFilter(SkMaskFilter::MakeBlur(gStyles[i], |
| 46 |
fBlurSigma)); |
| 47 |
paint.setColor(random.nextU() | 0xff000000); |
| 48 |
canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1, |
| 49 |
200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1, |
| 50 |
fCircleRadius, paint); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
bool animate(double nanos) override { |
| 55 |
fBlurSigma = get_anim_sin(1e-9 * nanos, 100, 4, 5); |
| 56 |
fCircleRadius = 3 + get_anim_sin(1e-9 * nanos, 150, 25, 3); |
| 57 |
return true; |
| 58 |
} |
| 59 |
}; |
| 60 |
|
| 61 |
DEF_SLIDE( return new AnimBlurSlide(); ) |