Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "gm.h" | |
| 9 #include "SkCanvas.h" | |
| 10 #include "SkPath.h" | |
| 11 | |
| 12 // Based on http://www.saccade.com/rtor/ | |
| 13 | |
|
robertphillips
2013/09/12 15:19:56
Does it need to be this big?
jvanverth1
2013/09/12 16:55:44
Done.
| |
| 14 static const int kWidth = 1909; | |
| 15 static const int kHeight = 1105; | |
| 16 static const SkScalar kAngle = 0.305f; | |
| 17 | |
|
robertphillips
2013/09/12 15:19:56
// description?
jvanverth1
2013/09/12 16:55:44
Done.
| |
| 18 class StringArtGM : public skiagm::GM { | |
| 19 public: | |
| 20 StringArtGM() {} | |
| 21 | |
| 22 protected: | |
| 23 virtual SkString onShortName() { | |
| 24 return SkString("stringart"); | |
| 25 } | |
| 26 | |
| 27 virtual SkISize onISize() { | |
| 28 return SkISize::Make(kWidth, kHeight); | |
| 29 } | |
| 30 | |
| 31 virtual void onDraw(SkCanvas* canvas) { | |
|
robertphillips
2013/09/12 15:19:56
There is also SkScalarHalf()
jvanverth1
2013/09/12 16:55:44
Done.
| |
| 32 SkScalar angle = kAngle * SK_ScalarPI + SK_ScalarPI*SK_ScalarHalf; | |
| 33 SkScalar size = SkMin32( kWidth, kHeight ); | |
| 34 SkPoint center = SkPoint::Make( kWidth*SK_ScalarHalf, kHeight*SK_ScalarH alf ); | |
| 35 SkScalar length = 5; | |
| 36 SkScalar step = angle; | |
| 37 | |
| 38 SkPath path; | |
| 39 path.moveTo(center); | |
| 40 | |
| 41 while (length < (size*SK_ScalarHalf - 10.f)) | |
| 42 { | |
| 43 SkPoint rp = SkPoint::Make(length * SkScalarCos(step) + center.fX, | |
| 44 length * SkScalarSin(step) + center.fY); | |
| 45 path.lineTo(rp); | |
| 46 length += angle/(SK_ScalarPI*SK_ScalarHalf); | |
| 47 step += angle; | |
| 48 } | |
| 49 path.close(); | |
| 50 | |
| 51 SkPaint paint; | |
| 52 paint.setAntiAlias(true); | |
| 53 paint.setStyle(SkPaint::kStroke_Style); | |
| 54 paint.setColor(0xFF007700); | |
| 55 | |
| 56 canvas->drawPath(path, paint); | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 typedef GM INHERITED; | |
| 61 }; | |
| 62 | |
| 63 DEF_GM( return new StringArtGM; ) | |
| OLD | NEW |