Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: gm/stringart.cpp

Issue 1870133003: Make some GMs animate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Actually use the timer Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/lighting.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/stringart.cpp
diff --git a/gm/stringart.cpp b/gm/stringart.cpp
index d381350e18c457d8b48df8e9272ba829ba8f4fa6..7eaac85ebcfc6e4a4401811b7b9f65a2e5da7ddf 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;
};
« no previous file with comments | « gm/lighting.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698