| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkPath.h" | 11 #include "SkPath.h" |
| 12 | 12 |
| 13 // Reproduces https://code.google.com/p/chromium/issues/detail?id=279014 | 13 // Reproduces https://code.google.com/p/chromium/issues/detail?id=279014 |
| 14 | 14 |
| 15 static const int kWidth = 440; | 15 constexpr int kWidth = 440; |
| 16 static const int kHeight = 440; | 16 constexpr int kHeight = 440; |
| 17 static const SkScalar kAngle = 0.305f; | 17 constexpr SkScalar kAngle = 0.305f; |
| 18 static const int kMaxNumSteps = 140; | 18 constexpr int kMaxNumSteps = 140; |
| 19 | 19 |
| 20 // Renders a string art shape. | 20 // Renders a string art shape. |
| 21 // The particular shape rendered can be controlled by adjusting kAngle, from 0 t
o 1 | 21 // The particular shape rendered can be controlled by adjusting kAngle, from 0 t
o 1 |
| 22 | 22 |
| 23 class StringArtGM : public skiagm::GM { | 23 class StringArtGM : public skiagm::GM { |
| 24 public: | 24 public: |
| 25 StringArtGM() : fNumSteps(kMaxNumSteps) {} | 25 StringArtGM() : fNumSteps(kMaxNumSteps) {} |
| 26 | 26 |
| 27 protected: | 27 protected: |
| 28 | 28 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 54 | 54 |
| 55 SkPaint paint; | 55 SkPaint paint; |
| 56 paint.setAntiAlias(true); | 56 paint.setAntiAlias(true); |
| 57 paint.setStyle(SkPaint::kStroke_Style); | 57 paint.setStyle(SkPaint::kStroke_Style); |
| 58 paint.setColor(sk_tool_utils::color_to_565(0xFF007700)); | 58 paint.setColor(sk_tool_utils::color_to_565(0xFF007700)); |
| 59 | 59 |
| 60 canvas->drawPath(path, paint); | 60 canvas->drawPath(path, paint); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool onAnimate(const SkAnimTimer& timer) override { | 63 bool onAnimate(const SkAnimTimer& timer) override { |
| 64 static const SkScalar kDesiredDurationSecs = 3.0f; | 64 constexpr SkScalar kDesiredDurationSecs = 3.0f; |
| 65 | 65 |
| 66 // Make the animation ping-pong back and forth but start in the fully dr
awn state | 66 // Make the animation ping-pong back and forth but start in the fully dr
awn state |
| 67 SkScalar fraction = 1.0f - timer.scaled(2.0f/kDesiredDurationSecs, 2.0f)
; | 67 SkScalar fraction = 1.0f - timer.scaled(2.0f/kDesiredDurationSecs, 2.0f)
; |
| 68 if (fraction <= 0.0f) { | 68 if (fraction <= 0.0f) { |
| 69 fraction = -fraction; | 69 fraction = -fraction; |
| 70 } | 70 } |
| 71 | 71 |
| 72 SkASSERT(fraction >= 0.0f && fraction <= 1.0f); | 72 SkASSERT(fraction >= 0.0f && fraction <= 1.0f); |
| 73 | 73 |
| 74 fNumSteps = (int) (fraction * kMaxNumSteps); | 74 fNumSteps = (int) (fraction * kMaxNumSteps); |
| 75 return true; | 75 return true; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 int fNumSteps; | 79 int fNumSteps; |
| 80 | 80 |
| 81 typedef GM INHERITED; | 81 typedef GM INHERITED; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 DEF_GM( return new StringArtGM; ) | 84 DEF_GM( return new StringArtGM; ) |
| OLD | NEW |