blob: e6fad25772db27b6a8ca642b3885ca2c14a12981 [file] [log] [blame]
reed19d8f9f2015-01-29 10:48:16 -08001/*
2 * Copyright 2015 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 "gm.h"
reed76113a92015-02-02 12:55:02 -08009#include "SkAnimTimer.h"
reed19d8f9f2015-01-29 10:48:16 -080010#include "SkCanvas.h"
11#include "SkRandom.h"
12
13class AddArcGM : public skiagm::GM {
reedd9adfe62015-02-01 19:01:04 -080014public:
15 AddArcGM() : fRotate(0) {}
16
reed19d8f9f2015-01-29 10:48:16 -080017protected:
18 SkString onShortName() SK_OVERRIDE { return SkString("addarc"); }
19
20 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1040, 1040); }
21
22 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
23 canvas->translate(20, 20);
24
25 SkRect r = SkRect::MakeWH(1000, 1000);
26
27 SkPaint paint;
28 paint.setAntiAlias(true);
29 paint.setStyle(SkPaint::kStroke_Style);
30 paint.setStrokeWidth(15);
31
32 const SkScalar inset = paint.getStrokeWidth() + 4;
33 const SkScalar sweepAngle = 345;
34 SkRandom rand;
35
reedd9adfe62015-02-01 19:01:04 -080036 SkScalar sign = 1;
reed19d8f9f2015-01-29 10:48:16 -080037 while (r.width() > paint.getStrokeWidth() * 3) {
38 paint.setColor(rand.nextU() | (0xFF << 24));
39 SkScalar startAngle = rand.nextUScalar1() * 360;
40
reedd9adfe62015-02-01 19:01:04 -080041 SkScalar speed = SkScalarSqrt(16 / r.width()) * 0.5f;
42 startAngle += fRotate * 360 * speed * sign;
43
reed19d8f9f2015-01-29 10:48:16 -080044 SkPath path;
45 path.addArc(r, startAngle, sweepAngle);
46 canvas->drawPath(path, paint);
47
48 r.inset(inset, inset);
reedd9adfe62015-02-01 19:01:04 -080049 sign = -sign;
reed19d8f9f2015-01-29 10:48:16 -080050 }
51 }
52
reed76113a92015-02-02 12:55:02 -080053 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE {
54 fRotate = timer.scaled(1, 360);
reedd9adfe62015-02-01 19:01:04 -080055 return true;
56 }
57
reed19d8f9f2015-01-29 10:48:16 -080058private:
reedd9adfe62015-02-01 19:01:04 -080059 SkScalar fRotate;
reed19d8f9f2015-01-29 10:48:16 -080060 typedef skiagm::GM INHERITED;
61};
62DEF_GM( return new AddArcGM; )