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

Unified Diff: gm/stringart.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
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | samplecode/SampleStringArt.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/stringart.cpp
diff --git a/gm/stringart.cpp b/gm/stringart.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3164275e9946c7aaff519df32a538b5210ea7f25
--- /dev/null
+++ b/gm/stringart.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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"
+
+// Based on http://www.saccade.com/rtor/
+
robertphillips 2013/09/12 15:19:56 Does it need to be this big?
jvanverth1 2013/09/12 16:55:44 Done.
+static const int kWidth = 1909;
+static const int kHeight = 1105;
+static const SkScalar kAngle = 0.305f;
+
robertphillips 2013/09/12 15:19:56 // description?
jvanverth1 2013/09/12 16:55:44 Done.
+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) {
robertphillips 2013/09/12 15:19:56 There is also SkScalarHalf()
jvanverth1 2013/09/12 16:55:44 Done.
+ SkScalar angle = kAngle * SK_ScalarPI + SK_ScalarPI*SK_ScalarHalf;
+ SkScalar size = SkMin32( kWidth, kHeight );
+ SkPoint center = SkPoint::Make( kWidth*SK_ScalarHalf, kHeight*SK_ScalarHalf );
+ SkScalar length = 5;
+ SkScalar step = angle;
+
+ SkPath path;
+ path.moveTo(center);
+
+ while (length < (size*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);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+DEF_GM( return new StringArtGM; )
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | samplecode/SampleStringArt.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698