Index: gm/stringart.cpp |
diff --git a/gm/stringart.cpp b/gm/stringart.cpp |
index d381350e18c457d8b48df8e9272ba829ba8f4fa6..b1ca916592034dafbf9401ffc4039c0063b1c1cf 100644 |
--- a/gm/stringart.cpp |
+++ b/gm/stringart.cpp |
@@ -14,13 +14,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), fDelta(1) {} |
protected: |
@@ -42,15 +43,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 +59,20 @@ protected: |
canvas->drawPath(path, paint); |
} |
+ bool onAnimate(const SkAnimTimer& timer) override { |
+ fNumSteps += fDelta; |
+ if (fNumSteps >= kMaxNumSteps) { |
+ fDelta = -1; |
+ } else if (fNumSteps <= 0) { |
+ fDelta = 1; |
+ } |
+ return true; |
+ } |
+ |
private: |
+ int fNumSteps; |
+ int fDelta; |
+ |
typedef GM INHERITED; |
}; |