Debian Codegraph @

gm/drawlines_with_local_matrix.cpp

raw
1 /*
2 * Copyright 2022 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPaint.h"
11 #include "include/effects/SkGradient.h"
12
13 DEF_SIMPLE_GM(drawlines_with_local_matrix, canvas, 500, 500) {
14 canvas->clipRect({0,0,500,500});
15 SkPaint grad;
16 grad.setAntiAlias(true);
17 grad.setStrokeCap(SkPaint::kSquare_Cap);
18 float pos[6] = {0, 2/6.f, 3/6.f, 4/6.f, 5/6.f, 1};
19 const SkColor4f indigo = SkColor4f::FromColor(SkColorSetARGB(0xFF, 0x4b, 0x00, 0x82));
20 const SkColor4f violet = SkColor4f::FromColor(SkColorSetARGB(0xFF, 0xee, 0x82, 0xee));
21 const SkColor4f colors[6] = {
22 SkColors::kRed, SkColors::kYellow, SkColors::kGreen, SkColors::kBlue, indigo, violet};
23 grad.setShader(SkShaders::RadialGradient({250,250}, 280,
24 {{colors, pos, SkTileMode::kClamp}, {}}));
25 canvas->drawPaint(grad);
26
27 SkPaint white;
28 white.setAntiAlias(true);
29 white.setStrokeCap(SkPaint::kSquare_Cap);
30 white.setColor(SK_ColorWHITE);
31
32 auto drawLine = [&](float x0, float y0, float x1, float y1, float w) {
33 SkPoint p[2] = {{x0, y0}, {x1, y1}};
34 white.setStrokeWidth(w);
35 canvas->drawPoints(SkCanvas::kLines_PointMode, p, white);
36 grad.setStrokeWidth(w - 4);
37 canvas->drawPoints(SkCanvas::kLines_PointMode, p, grad);
38 };
39
40 drawLine(20, 20, 200, 120, 20);
41 drawLine(20, 200, 20, 100, 20);
42 drawLine(480, 20, 400, 400, 20);
43 drawLine(50, 480, 260, 100, 20);
44 drawLine(270, 20, 380, 210, 20);
45 drawLine(280, 280, 400, 480, 20);
46 drawLine(160, 375, 280, 375, 20);
47 drawLine(220, 410, 220, 470, 20);
48 drawLine(250, 250, 250, 250, 20);
49 }