Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=3ba94448a4ba48f926e643baeb5b1016 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Path_ConvertConicToQuads, 256, 256, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | SkPaint conicPaint; |
| 8 | conicPaint.setAntiAlias(true); |
| 9 | conicPaint.setStyle(SkPaint::kStroke_Style); |
| 10 | SkPaint quadPaint(conicPaint); |
| 11 | quadPaint.setColor(SK_ColorRED); |
| 12 | SkPoint conic[] = { {20, 170}, {80, 170}, {80, 230} }; |
| 13 | for (auto weight : { .25f, .5f, .707f, .85f, 1.f } ) { |
| 14 | SkPoint quads[5]; |
| 15 | SkPath::ConvertConicToQuads(conic[0], conic[1], conic[2], weight, quads, 1); |
| 16 | SkPath path; |
| 17 | path.moveTo(conic[0]); |
| 18 | path.conicTo(conic[1], conic[2], weight); |
| 19 | canvas->drawPath(path, conicPaint); |
| 20 | path.rewind(); |
| 21 | path.moveTo(quads[0]); |
| 22 | path.quadTo(quads[1], quads[2]); |
| 23 | path.quadTo(quads[3], quads[4]); |
| 24 | canvas->drawPath(path, quadPaint); |
| 25 | canvas->translate(50, -50); |
| 26 | } |
| 27 | } |
| 28 | } // END FIDDLE |