2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
16 constexpr SkScalar SH = SkIntToScalar(H);
18 static void rnd_quad(SkPath* p, SkPaint* paint, SkRandom& rand) {
19 auto a = rand.nextRangeScalar(0,W),
20 b = rand.nextRangeScalar(0,H);
22 for (int x = 0; x < 2; ++x) {
23 auto c = rand.nextRangeScalar(W/4, W),
24 d = rand.nextRangeScalar( 0, H),
25 e = rand.nextRangeScalar( 0, W),
26 f = rand.nextRangeScalar(H/4, H);
29 paint->setColor(rand.nextU());
30 SkScalar width = rand.nextRangeScalar(1, 5);
32 paint->setStrokeWidth(width);
33 paint->setAlpha(0xFF);
36 static void rnd_cubic(SkPath* p, SkPaint* paint, SkRandom& rand) {
37 auto a = rand.nextRangeScalar(0,W),
38 b = rand.nextRangeScalar(0,H);
40 for (int x = 0; x < 2; ++x) {
41 auto c = rand.nextRangeScalar(W/4, W),
42 d = rand.nextRangeScalar( 0, H),
43 e = rand.nextRangeScalar( 0, W),
44 f = rand.nextRangeScalar(H/4, H),
45 g = rand.nextRangeScalar(W/4, W),
46 h = rand.nextRangeScalar(H/4, H);
47 p->cubicTo(c,d,e,f,g,h);
49 paint->setColor(rand.nextU());
50 SkScalar width = rand.nextRangeScalar(1, 5);
52 paint->setStrokeWidth(width);
53 paint->setAlpha(0xFF);
56 class BeziersGM : public skiagm::GM {
62 SkString onShortName() override {
63 return SkString("beziers");
66 SkISize onISize() override {
67 return SkISize::Make(W, H*2);
70 void onDraw(SkCanvas* canvas) override {
72 paint.setStyle(SkPaint::kStroke_Style);
73 paint.setStrokeWidth(SkIntToScalar(9)/2);
74 paint.setAntiAlias(true);
77 for (int i = 0; i < N; i++) {
79 rnd_quad(&p, &paint, rand);
80 canvas->drawPath(p, paint);
82 canvas->translate(0, SH);
83 for (int i = 0; i < N; i++) {
85 rnd_cubic(&p, &paint, rand);
86 canvas->drawPath(p, paint);
91 typedef skiagm::GM INHERITED;
94 DEF_GM( return new BeziersGM; )