xref: /aosp_15_r20/external/skia/docs/examples/Path_ConvertConicToQuads.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Path_ConvertConicToQuads, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6       SkPaint conicPaint;
7       conicPaint.setAntiAlias(true);
8       conicPaint.setStyle(SkPaint::kStroke_Style);
9       SkPaint quadPaint(conicPaint);
10       quadPaint.setColor(SK_ColorRED);
11       SkPoint conic[] = { {20, 170}, {80, 170}, {80, 230} };
12       for (auto weight : { .25f, .5f, .707f, .85f, 1.f } ) {
13           SkPoint quads[5];
14           SkPath::ConvertConicToQuads(conic[0], conic[1], conic[2], weight, quads, 1);
15           SkPath path;
16           path.moveTo(conic[0]);
17           path.conicTo(conic[1], conic[2], weight);
18           canvas->drawPath(path, conicPaint);
19           path.rewind();
20           path.moveTo(quads[0]);
21           path.quadTo(quads[1], quads[2]);
22           path.quadTo(quads[3], quads[4]);
23           canvas->drawPath(path, quadPaint);
24           canvas->translate(50, -50);
25       }
26 }
27 }  // END FIDDLE
28