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

Side by Side Diff: gm/addarc.cpp

Issue 888283002: allow GMs to animate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use SPACE to toggle animations Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | gm/gm.h » ('j') | gm/gm.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
11 11
12 class AddArcGM : public skiagm::GM { 12 class AddArcGM : public skiagm::GM {
13 public:
14 AddArcGM() : fRotate(0) {}
15
13 protected: 16 protected:
14 SkString onShortName() SK_OVERRIDE { return SkString("addarc"); } 17 SkString onShortName() SK_OVERRIDE { return SkString("addarc"); }
15 18
16 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1040, 1040); } 19 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1040, 1040); }
17 20
18 void onDraw(SkCanvas* canvas) SK_OVERRIDE { 21 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
19 canvas->translate(20, 20); 22 canvas->translate(20, 20);
20 23
21 SkRect r = SkRect::MakeWH(1000, 1000); 24 SkRect r = SkRect::MakeWH(1000, 1000);
22 25
23 SkPaint paint; 26 SkPaint paint;
24 paint.setAntiAlias(true); 27 paint.setAntiAlias(true);
25 paint.setStyle(SkPaint::kStroke_Style); 28 paint.setStyle(SkPaint::kStroke_Style);
26 paint.setStrokeWidth(15); 29 paint.setStrokeWidth(15);
27 30
28 const SkScalar inset = paint.getStrokeWidth() + 4; 31 const SkScalar inset = paint.getStrokeWidth() + 4;
29 const SkScalar sweepAngle = 345; 32 const SkScalar sweepAngle = 345;
30 SkRandom rand; 33 SkRandom rand;
31 34
35 SkScalar sign = 1;
32 while (r.width() > paint.getStrokeWidth() * 3) { 36 while (r.width() > paint.getStrokeWidth() * 3) {
33 paint.setColor(rand.nextU() | (0xFF << 24)); 37 paint.setColor(rand.nextU() | (0xFF << 24));
34 SkScalar startAngle = rand.nextUScalar1() * 360; 38 SkScalar startAngle = rand.nextUScalar1() * 360;
35 39
40 SkScalar speed = SkScalarSqrt(16 / r.width()) * 0.5f;
41 startAngle += fRotate * 360 * speed * sign;
42
36 SkPath path; 43 SkPath path;
37 path.addArc(r, startAngle, sweepAngle); 44 path.addArc(r, startAngle, sweepAngle);
38 canvas->drawPath(path, paint); 45 canvas->drawPath(path, paint);
39 46
40 r.inset(inset, inset); 47 r.inset(inset, inset);
41 48 sign = -sign;
42 } 49 }
43 } 50 }
44 51
52 bool onAnimatePulse(SkMSec curr) SK_OVERRIDE {
53 fRotate = curr / SkIntToScalar(1000);
54 return true;
55 }
56
45 private: 57 private:
58 SkScalar fRotate;
46 typedef skiagm::GM INHERITED; 59 typedef skiagm::GM INHERITED;
47 }; 60 };
48 DEF_GM( return new AddArcGM; ) 61 DEF_GM( return new AddArcGM; )
OLDNEW
« no previous file with comments | « no previous file | gm/gm.h » ('j') | gm/gm.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698