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/SkGradientShader.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 constexpr SkColor indigo = SkColorSetARGB(0xFF, 0x4b, 0x00, 0x82); 20 constexpr SkColor violet = SkColorSetARGB(0xFF, 0xee, 0x82, 0xee); 21 SkColor colors[6] = {SK_ColorRED, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorBLUE, indigo, violet}; 22 grad.setShader(SkGradientShader::MakeRadial({250,250}, 280, colors, pos, 6,SkTileMode::kClamp)); 23 canvas->drawPaint(grad); 24 25 SkPaint white; 26 white.setAntiAlias(true); 27 white.setStrokeCap(SkPaint::kSquare_Cap); 28 white.setColor(SK_ColorWHITE); 29 __anonc7af0b340102(float x0, float y0, float x1, float y1, float w) 30 auto drawLine = [&](float x0, float y0, float x1, float y1, float w) { 31 SkPoint p[2] = {{x0, y0}, {x1, y1}}; 32 white.setStrokeWidth(w); 33 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, p, white); 34 grad.setStrokeWidth(w - 4); 35 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, p, grad); 36 }; 37 38 drawLine(20, 20, 200, 120, 20); 39 drawLine(20, 200, 20, 100, 20); 40 drawLine(480, 20, 400, 400, 20); 41 drawLine(50, 480, 260, 100, 20); 42 drawLine(270, 20, 380, 210, 20); 43 drawLine(280, 280, 400, 480, 20); 44 drawLine(160, 375, 280, 375, 20); 45 drawLine(220, 410, 220, 470, 20); 46 drawLine(250, 250, 250, 250, 20); 47 } 48