| 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(shader, 256, 256, false, 0) { |
| 5 |
SkPath star() { |
| 6 |
const SkScalar R = 60.0f, C = 128.0f; |
| 7 |
SkPathBuilder path; |
| 8 |
path.moveTo(C + R, C); |
| 9 |
for (int i = 1; i < 15; ++i) { |
| 10 |
SkScalar a = 0.44879895f * i; |
| 11 |
SkScalar r = R + R * (i % 2); |
| 12 |
path.lineTo(C + r * cos(a), C + r * sin(a)); |
| 13 |
} |
| 14 |
return path.detach(); |
| 15 |
} |
| 16 |
void draw(SkCanvas* canvas) { |
| 17 |
SkPaint paint; |
| 18 |
paint.setPathEffect(SkDiscretePathEffect::Make(10.0f, 4.0f)); |
| 19 |
SkPoint points[2] = {SkPoint::Make(0.0f, 0.0f), SkPoint::Make(256.0f, 256.0f)}; |
| 20 |
SkColor4f colors[2] = { |
| 21 |
SkColor4f::FromColor(SkColorSetRGB(66, 133, 244)), |
| 22 |
SkColor4f::FromColor(SkColorSetRGB(15, 157, 88)) |
| 23 |
}; |
| 24 |
paint.setShader(SkShaders::LinearGradient( |
| 25 |
points, {{colors, {}, SkTileMode::kClamp}, {}})); |
| 26 |
paint.setAntiAlias(true); |
| 27 |
canvas->clear(SK_ColorWHITE); |
| 28 |
SkPath path(star()); |
| 29 |
canvas->drawPath(path, paint); |
| 30 |
} |
| 31 |
} // END FIDDLE |