diff options
author | robertphillips <robertphillips@google.com> | 2016-04-08 13:35:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-08 13:35:14 -0700 |
commit | 651bb5fafe1edd723425dffd478dfa67b113da73 (patch) | |
tree | 4699dc4326f07711b94016f39110b4bbc1d74b04 /gm/stringart.cpp | |
parent | 7cbffda6c85e0634399d74607db2a82943abe06a (diff) |
Make some GMs animate
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1870133003
Review URL: https://codereview.chromium.org/1870133003
Diffstat (limited to 'gm/stringart.cpp')
-rw-r--r-- | gm/stringart.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/gm/stringart.cpp b/gm/stringart.cpp index d381350e18..7eaac85ebc 100644 --- a/gm/stringart.cpp +++ b/gm/stringart.cpp @@ -6,6 +6,7 @@ */ #include "gm.h" +#include "SkAnimTimer.h" #include "SkCanvas.h" #include "SkPath.h" @@ -14,13 +15,14 @@ static const int kWidth = 640; static const int kHeight = 480; static const SkScalar kAngle = 0.305f; +static const int kMaxNumSteps = 140; // Renders a string art shape. // The particular shape rendered can be controlled by adjusting kAngle, from 0 to 1 class StringArtGM : public skiagm::GM { public: - StringArtGM() {} + StringArtGM() : fNumSteps(kMaxNumSteps) {} protected: @@ -42,15 +44,13 @@ protected: SkPath path; path.moveTo(center); - while (length < (SkScalarHalf(size) - 10.f)) - { + for (int i = 0; i < fNumSteps && length < (SkScalarHalf(size) - 10.f); ++i) { SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX, length*SkScalarSin(step) + center.fY); path.lineTo(rp); length += angle / SkScalarHalf(SK_ScalarPI); step += angle; } - path.close(); SkPaint paint; paint.setAntiAlias(true); @@ -60,7 +60,24 @@ protected: canvas->drawPath(path, paint); } + bool onAnimate(const SkAnimTimer& timer) override { + static const SkScalar kDesiredDurationSecs = 3.0f; + + // Make the animation ping-pong back and forth but start in the fully drawn state + SkScalar fraction = 1.0f - timer.scaled(2.0f/kDesiredDurationSecs, 2.0f); + if (fraction <= 0.0f) { + fraction = -fraction; + } + + SkASSERT(fraction >= 0.0f && fraction <= 1.0f); + + fNumSteps = (int) (fraction * kMaxNumSteps); + return true; + } + private: + int fNumSteps; + typedef GM INHERITED; }; |