Flutter Engine
The Flutter Engine
Functions
SkPath_quadTo_example_parametric.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (SkPath_quadTo_example_parametric, 512, 512, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( SkPath_quadTo_example_parametric  ,
512  ,
512  ,
false  ,
 
)

Definition at line 4 of file SkPath_quadTo_example_parametric.cpp.

4 {
5SkPoint quad(SkPoint p0, SkPoint p1, SkPoint p2, float t) {
6 float s = 1 - t;
7 return {(s * s * p0.x()) + (2 * s * t * p1.x()) + (t * t * p2.x()),
8 (s * s * p0.y()) + (2 * s * t * p1.y()) + (t * t * p2.y())};
9}
10
11/*
12
13 If the starting point is (x0, y0), then this curve is defined as the
14 paramentric curve as `t` goes from 0 to 1:
15
16 s := 1 - t
17 x := (s * s * x0) + (2 * s * t * x1) + (t * t * x2)
18 y := (s * s * y0) + (2 * s * t * y1) + (t * t * y2)
19
20*/
21
22void draw(SkCanvas* canvas) {
23 canvas->clear(SkColorSetARGB(255, 255, 255, 255));
24
26 paint.setAntiAlias(true);
28 paint.setStrokeWidth(5);
29
30 SkPoint a{100, 100};
31 SkPoint b{200, 400};
32 SkPoint c{300, 100};
33
34 SkPath twoSegments;
35 twoSegments.moveTo(a);
36 twoSegments.lineTo(b);
37 twoSegments.lineTo(c);
38
39 canvas->drawPath(twoSegments, paint);
40
41 paint.setColor(SkColorSetARGB(255, 0, 0, 255));
42 SkPath quadraticCurve;
43 quadraticCurve.moveTo(a);
44 quadraticCurve.quadTo(b, c);
45 canvas->drawPath(quadraticCurve, paint);
46
47 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 32);
48 SkPaint textPaint;
49 textPaint.setAntiAlias(true);
50 canvas->drawString("a", a.x(), a.y(), font, textPaint);
51 canvas->drawString("b", b.x() + 20, b.y() + 20, font, textPaint);
52 canvas->drawString("c", c.x(), c.y(), font, textPaint);
53
54 SkPaint pointPaint;
55 pointPaint.setAntiAlias(true);
56 pointPaint.setStrokeWidth(8);
58 pointPaint.setColor(SkColorSetARGB(255, 0, 255, 0));
59 int N = 15;
60 for (int i = 0; i <= N; ++i) {
61 SkPoint p = quad(a, b, c, (float)i / N);
62 canvas->drawPoint(p.x(), p.y(), pointPaint);
63 }
64}
65} // END FIDDLE
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
#define N
Definition: beziers.cpp:19
void drawPoint(SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2695
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Definition: SkPath.cpp:746
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
static bool b
struct MyStruct s
struct MyStruct a[10]
font
Font Metadata and Metrics.
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181