From 4ea2878f076cd41da803e6fcdcfb884b18a5b00c Mon Sep 17 00:00:00 2001 From: "jvanverth@google.com" Date: Thu, 19 Sep 2013 15:32:22 +0000 Subject: Add string art GM and sample. BUG=279014 R=robertphillips@google.com Review URL: https://codereview.chromium.org/23609037 git-svn-id: http://skia.googlecode.com/svn/trunk@11383 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/stringart.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 gm/stringart.cpp (limited to 'gm/stringart.cpp') diff --git a/gm/stringart.cpp b/gm/stringart.cpp new file mode 100644 index 0000000000..1dc86efef7 --- /dev/null +++ b/gm/stringart.cpp @@ -0,0 +1,66 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkCanvas.h" +#include "SkPath.h" + +// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014 + +static const int kWidth = 640; +static const int kHeight = 480; +static const SkScalar kAngle = 0.305f; + +// 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() {} + +protected: + virtual SkString onShortName() { + return SkString("stringart"); + } + + virtual SkISize onISize() { + return SkISize::Make(kWidth, kHeight); + } + + virtual void onDraw(SkCanvas* canvas) { + SkScalar angle = kAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI); + SkScalar size = SkMin32(kWidth, kHeight); + SkPoint center = SkPoint::Make(SkScalarHalf(kWidth), SkScalarHalf(kHeight)); + SkScalar length = 5; + SkScalar step = angle; + + SkPath path; + path.moveTo(center); + + while (length < (SkScalarHalf(size) - 10.f)) + { + SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX, + length*SkScalarSin(step) + center.fY); + path.lineTo(rp); + length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI)); + step += angle; + } + path.close(); + + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setColor(0xFF007700); + + canvas->drawPath(path, paint); + } + +private: + typedef GM INHERITED; +}; + +DEF_GM( return new StringArtGM; ) -- cgit v1.2.3