| 1 |
// Copyright 2020 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(convex_overstroke_linear_approx_curve, 256, 256, false, 0) { |
| 5 |
#include <math.h> |
| 6 |
|
| 7 |
void draw(SkCanvas* canvas) { |
| 8 |
const float SCALE = 1; |
| 9 |
const int WIDTH = 150; |
| 10 |
|
| 11 |
const float PI = 3.1415926; |
| 12 |
|
| 13 |
canvas->scale(SCALE, SCALE); |
| 14 |
canvas->translate(50, 50); |
| 15 |
|
| 16 |
SkPoint p1 = SkPoint::Make(50, 50); |
| 17 |
SkPoint p2 = SkPoint::Make(80, 50); |
| 18 |
|
| 19 |
SkPoint points[10]; |
| 20 |
|
| 21 |
for (int i = 0; i < 10; i++) { |
| 22 |
points[i] = SkPoint::Make(65 + 15 * cos(i * PI / 10), 50 - 15 * sin(i * PI / 10)); |
| 23 |
} |
| 24 |
|
| 25 |
SkPathBuilder builder; |
| 26 |
builder.moveTo(p1); |
| 27 |
builder.lineTo(p2); |
| 28 |
|
| 29 |
for (int i = 0; i < 10; i++) { |
| 30 |
builder.lineTo(points[i]); |
| 31 |
} |
| 32 |
builder.lineTo(p1); |
| 33 |
// builder.close(); |
| 34 |
SkPath path = builder.detach(); |
| 35 |
|
| 36 |
SkPaint p; |
| 37 |
p.setColor(SK_ColorRED); |
| 38 |
p.setAntiAlias(true); |
| 39 |
p.setStyle(SkPaint::kStroke_Style); |
| 40 |
p.setStrokeWidth(WIDTH); |
| 41 |
|
| 42 |
canvas->drawPath(path, p); |
| 43 |
|
| 44 |
SkPath fillpath = skpathutils::FillPathWithPaint(path, p); |
| 45 |
|
| 46 |
SkPaint fillp; |
| 47 |
fillp.setColor(SK_ColorBLACK); |
| 48 |
fillp.setAntiAlias(true); |
| 49 |
fillp.setStyle(SkPaint::kStroke_Style); |
| 50 |
fillp.setStrokeWidth(1); |
| 51 |
|
| 52 |
canvas->drawPath(fillpath, fillp); |
| 53 |
} |
| 54 |
} // END FIDDLE |