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 "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
11 | 11 |
12 #define W 400 | 12 #define W 400 |
13 #define H 400 | 13 #define H 400 |
14 #define N 10 | 14 #define N 10 |
15 | 15 |
16 constexpr SkScalar SH = SkIntToScalar(H); | 16 constexpr SkScalar SH = SkIntToScalar(H); |
17 | 17 |
18 static void rnd_quad(SkPath* p, SkPaint* paint, SkRandom& rand) { | 18 static void rnd_quad(SkPath* p, SkPaint* paint, SkRandom& rand) { |
19 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H)); | 19 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H)); |
20 for (int x = 0; x < 2; ++x) { | 20 for (int x = 0; x < 2; ++x) { |
21 p->quadTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H), | 21 auto a = rand.nextRangeScalar(W/4, W), |
22 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H)); | 22 b = rand.nextRangeScalar( 0, H), |
| 23 c = rand.nextRangeScalar( 0, W), |
| 24 d = rand.nextRangeScalar(H/4, H); |
| 25 p->quadTo(a,b,c,d); |
23 } | 26 } |
24 paint->setColor(rand.nextU()); | 27 paint->setColor(rand.nextU()); |
25 SkScalar width = rand.nextRangeScalar(1, 5); | 28 SkScalar width = rand.nextRangeScalar(1, 5); |
26 width *= width; | 29 width *= width; |
27 paint->setStrokeWidth(width); | 30 paint->setStrokeWidth(width); |
28 paint->setAlpha(0xFF); | 31 paint->setAlpha(0xFF); |
29 } | 32 } |
30 | 33 |
31 static void rnd_cubic(SkPath* p, SkPaint* paint, SkRandom& rand) { | 34 static void rnd_cubic(SkPath* p, SkPaint* paint, SkRandom& rand) { |
32 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H)); | 35 auto a = rand.nextRangeScalar(0,W), |
| 36 b = rand.nextRangeScalar(0,H); |
| 37 p->moveTo(a,b); |
33 for (int x = 0; x < 2; ++x) { | 38 for (int x = 0; x < 2; ++x) { |
34 p->cubicTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H), | 39 auto c = rand.nextRangeScalar(W/4, W), |
35 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H), | 40 d = rand.nextRangeScalar( 0, H), |
36 rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(H / 4, H)
); | 41 e = rand.nextRangeScalar( 0, W), |
| 42 f = rand.nextRangeScalar(H/4, H), |
| 43 g = rand.nextRangeScalar(W/4, W), |
| 44 h = rand.nextRangeScalar(H/4, H); |
| 45 p->cubicTo(c,d,e,f,g,h); |
37 } | 46 } |
38 paint->setColor(rand.nextU()); | 47 paint->setColor(rand.nextU()); |
39 SkScalar width = rand.nextRangeScalar(1, 5); | 48 SkScalar width = rand.nextRangeScalar(1, 5); |
40 width *= width; | 49 width *= width; |
41 paint->setStrokeWidth(width); | 50 paint->setStrokeWidth(width); |
42 paint->setAlpha(0xFF); | 51 paint->setAlpha(0xFF); |
43 } | 52 } |
44 | 53 |
45 class BeziersGM : public skiagm::GM { | 54 class BeziersGM : public skiagm::GM { |
46 public: | 55 public: |
(...skipping 27 matching lines...) Expand all Loading... |
74 rnd_cubic(&p, &paint, rand); | 83 rnd_cubic(&p, &paint, rand); |
75 canvas->drawPath(p, paint); | 84 canvas->drawPath(p, paint); |
76 } | 85 } |
77 } | 86 } |
78 | 87 |
79 private: | 88 private: |
80 typedef skiagm::GM INHERITED; | 89 typedef skiagm::GM INHERITED; |
81 }; | 90 }; |
82 | 91 |
83 DEF_GM( return new BeziersGM; ) | 92 DEF_GM( return new BeziersGM; ) |
OLD | NEW |