aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-19 15:32:22 +0000
committerGravatar jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-19 15:32:22 +0000
commit4ea2878f076cd41da803e6fcdcfb884b18a5b00c (patch)
tree9cf183d19fa5ba3f0a5fd3883540be82fa0a628a
parente2fd2d265126ce778b07177fb6820a3ef08a6156 (diff)
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
-rw-r--r--gm/stringart.cpp66
-rw-r--r--gyp/SampleApp.gyp1
-rw-r--r--gyp/gmslides.gypi1
-rw-r--r--samplecode/SampleStringArt.cpp72
4 files changed, 140 insertions, 0 deletions
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; )
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index f4a1d78079..7b8b4bdde5 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -103,6 +103,7 @@
'../samplecode/SampleShaderText.cpp',
'../samplecode/SampleSkLayer.cpp',
'../samplecode/SampleSlides.cpp',
+ '../samplecode/SampleStringArt.cpp',
'../samplecode/SampleStrokePath.cpp',
'../samplecode/SampleTests.cpp',
'../samplecode/SampleText.cpp',
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index d985807f2e..7eb97fad07 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -112,6 +112,7 @@
'../gm/shadows.cpp',
'../gm/shallowgradient.cpp',
'../gm/simpleaaclip.cpp',
+ '../gm/stringart.cpp',
'../gm/spritebitmap.cpp',
'../gm/srcmode.cpp',
'../gm/strokefill.cpp',
diff --git a/samplecode/SampleStringArt.cpp b/samplecode/SampleStringArt.cpp
new file mode 100644
index 0000000000..c6547ed4fa
--- /dev/null
+++ b/samplecode/SampleStringArt.cpp
@@ -0,0 +1,72 @@
+/*
+ * 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 "SampleCode.h"
+#include "SkCanvas.h"
+
+// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
+
+// Renders a string art shape.
+// The particular shape rendered can be controlled by clicking horizontally, thereby
+// generating an angle from 0 to 1.
+
+class StringArtView : public SampleView {
+public:
+ StringArtView() : fAngle(0.305f) {}
+
+protected:
+ // overrides from SkEventSink
+ virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
+ if (SampleCode::TitleQ(*evt)) {
+ SampleCode::TitleR(evt, "StringArt");
+ return true;
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+
+ virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
+ SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
+
+ SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf(this->height()));
+ SkScalar length = 5;
+ SkScalar step = angle;
+
+ SkPath path;
+ path.moveTo(center);
+
+ while (length < (SkScalarHalf(SkMin32(this->width(), this->height())) - 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);
+ }
+
+ virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE {
+ fAngle = x/width();
+ this->inval(NULL);
+ return NULL;
+ }
+private:
+
+ SkScalar fAngle;
+ typedef SampleView INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static SkView* MyFactory() { return new StringArtView; }
+static SkViewRegister reg(MyFactory);