| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkRandom.h" | 9 #include "SkRandom.h" |
| 10 | 10 |
| 11 #define W 400 | 11 #define W 400 |
| 12 #define H 400 | 12 #define H 400 |
| 13 #define N 10 | 13 #define N 10 |
| 14 | 14 |
| 15 static const SkScalar SH = SkIntToScalar(H); | 15 static const SkScalar SH = SkIntToScalar(H); |
| 16 | 16 |
| 17 static void rnd_quad(SkPath* p, SkPaint* paint, SkLCGRandom& rand) { | 17 static void rnd_quad(SkPath* p, SkPaint* paint, SkRandom& rand) { |
| 18 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H)); | 18 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H)); |
| 19 for (int x = 0; x < 2; ++x) { | 19 for (int x = 0; x < 2; ++x) { |
| 20 p->quadTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H), | 20 p->quadTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H), |
| 21 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H)); | 21 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H)); |
| 22 } | 22 } |
| 23 paint->setColor(rand.nextU()); | 23 paint->setColor(rand.nextU()); |
| 24 SkScalar width = rand.nextRangeScalar(1, 5); | 24 SkScalar width = rand.nextRangeScalar(1, 5); |
| 25 width *= width; | 25 width *= width; |
| 26 paint->setStrokeWidth(width); | 26 paint->setStrokeWidth(width); |
| 27 paint->setAlpha(0xFF); | 27 paint->setAlpha(0xFF); |
| 28 } | 28 } |
| 29 | 29 |
| 30 static void rnd_cubic(SkPath* p, SkPaint* paint, SkLCGRandom& rand) { | 30 static void rnd_cubic(SkPath* p, SkPaint* paint, SkRandom& rand) { |
| 31 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H)); | 31 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H)); |
| 32 for (int x = 0; x < 2; ++x) { | 32 for (int x = 0; x < 2; ++x) { |
| 33 p->cubicTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H), | 33 p->cubicTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H), |
| 34 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H), | 34 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H), |
| 35 rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(H / 4, H)
); | 35 rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(H / 4, H)
); |
| 36 } | 36 } |
| 37 paint->setColor(rand.nextU()); | 37 paint->setColor(rand.nextU()); |
| 38 SkScalar width = rand.nextRangeScalar(1, 5); | 38 SkScalar width = rand.nextRangeScalar(1, 5); |
| 39 width *= width; | 39 width *= width; |
| 40 paint->setStrokeWidth(width); | 40 paint->setStrokeWidth(width); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 virtual SkISize onISize() { | 57 virtual SkISize onISize() { |
| 58 return SkISize::Make(W, H*2); | 58 return SkISize::Make(W, H*2); |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual void onDraw(SkCanvas* canvas) { | 61 virtual void onDraw(SkCanvas* canvas) { |
| 62 SkPaint paint; | 62 SkPaint paint; |
| 63 paint.setStyle(SkPaint::kStroke_Style); | 63 paint.setStyle(SkPaint::kStroke_Style); |
| 64 paint.setStrokeWidth(SkIntToScalar(9)/2); | 64 paint.setStrokeWidth(SkIntToScalar(9)/2); |
| 65 paint.setAntiAlias(true); | 65 paint.setAntiAlias(true); |
| 66 | 66 |
| 67 SkLCGRandom rand; | 67 SkRandom rand; |
| 68 for (int i = 0; i < N; i++) { | 68 for (int i = 0; i < N; i++) { |
| 69 SkPath p; | 69 SkPath p; |
| 70 rnd_quad(&p, &paint, rand); | 70 rnd_quad(&p, &paint, rand); |
| 71 canvas->drawPath(p, paint); | 71 canvas->drawPath(p, paint); |
| 72 } | 72 } |
| 73 canvas->translate(0, SH); | 73 canvas->translate(0, SH); |
| 74 for (int i = 0; i < N; i++) { | 74 for (int i = 0; i < N; i++) { |
| 75 SkPath p; | 75 SkPath p; |
| 76 rnd_cubic(&p, &paint, rand); | 76 rnd_cubic(&p, &paint, rand); |
| 77 canvas->drawPath(p, paint); | 77 canvas->drawPath(p, paint); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 typedef skiagm::GM INHERITED; | 82 typedef skiagm::GM INHERITED; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 static skiagm::GM* F0(void*) { return new BeziersGM; } | 85 static skiagm::GM* F0(void*) { return new BeziersGM; } |
| 86 static skiagm::GMRegistry R0(F0); | 86 static skiagm::GMRegistry R0(F0); |
| OLD | NEW |