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; ) |