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

Unified Diff: samplecode/SampleStringArt.cpp

Issue 23609037: Add string art GM and sample. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« gm/stringart.cpp ('K') | « gyp/gmslides.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleStringArt.cpp
diff --git a/samplecode/SampleStringArt.cpp b/samplecode/SampleStringArt.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c72edaa096bfb333acfbcec576c77863defa0b81
--- /dev/null
+++ b/samplecode/SampleStringArt.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 "SampleCode.h"
+#include "SkCanvas.h"
+
robertphillips 2013/09/12 15:19:56 // comment?
jvanverth1 2013/09/12 16:55:44 Done.
+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 + SK_ScalarPI*SK_ScalarHalf;
+
robertphillips 2013/09/12 15:19:56 this->width()? this->height()?
jvanverth1 2013/09/12 16:55:44 Done.
+ SkPoint center = SkPoint::Make( width()*SK_ScalarHalf, height()*SK_ScalarHalf );
+ SkScalar length = 5;
+ SkScalar step = angle;
+
+ SkPath path;
+ path.moveTo(center);
+
+ while (length < (SkMin32(width(), height())*SK_ScalarHalf - 10.f))
+ {
+ SkPoint rp = SkPoint::Make(length * SkScalarCos(step) + center.fX,
+ length * SkScalarSin(step) + center.fY);
+ path.lineTo(rp);
+ length += angle/(SK_ScalarPI*SK_ScalarHalf);
+ 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);
« gm/stringart.cpp ('K') | « gyp/gmslides.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698