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

Unified Diff: gm/stringart.cpp

Issue 23609037: Add string art GM and sample. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixes for nits 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') | no next file with comments »
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..1dc86efef7296177e855043fc36fba165290a09f
--- /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; )
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698