blob: 1d81e13f6a02399f72905531f22eb30ad75736c1 [file] [log] [blame]
jvanverth@google.com4ea28782013-09-19 15:32:22 +00001/*
2 * Copyright 2013 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"
9#include "SkCanvas.h"
10#include "SkPath.h"
11
12// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
13
jvanverth@google.comeb95d6a2013-09-19 17:21:39 +000014static const int kWidth = 640;
15static const int kHeight = 480;
jvanverth@google.com4ea28782013-09-19 15:32:22 +000016static const SkScalar kAngle = 0.305f;
17
18// Renders a string art shape.
19// The particular shape rendered can be controlled by adjusting kAngle, from 0 to 1
20
21class StringArtGM : public skiagm::GM {
22public:
23 StringArtGM() {}
24
25protected:
26 virtual SkString onShortName() {
27 return SkString("stringart");
28 }
29
30 virtual SkISize onISize() {
31 return SkISize::Make(kWidth, kHeight);
32 }
33
34 virtual void onDraw(SkCanvas* canvas) {
35 SkScalar angle = kAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
jvanverth@google.comeb95d6a2013-09-19 17:21:39 +000036 SkScalar size = SkIntToScalar(SkMin32(kWidth, kHeight));
jvanverth@google.com4ea28782013-09-19 15:32:22 +000037 SkPoint center = SkPoint::Make(SkScalarHalf(kWidth), SkScalarHalf(kHeight));
38 SkScalar length = 5;
39 SkScalar step = angle;
40
41 SkPath path;
42 path.moveTo(center);
43
44 while (length < (SkScalarHalf(size) - 10.f))
45 {
46 SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
47 length*SkScalarSin(step) + center.fY);
48 path.lineTo(rp);
49 length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
50 step += angle;
51 }
52 path.close();
53
54 SkPaint paint;
55 paint.setAntiAlias(true);
56 paint.setStyle(SkPaint::kStroke_Style);
57 paint.setColor(0xFF007700);
58
59 canvas->drawPath(path, paint);
60 }
61
62private:
63 typedef GM INHERITED;
64};
65
66DEF_GM( return new StringArtGM; )