Hal Canary | 6c8422c | 2020-01-10 15:22:09 -0500 | [diff] [blame] | 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(radial_gradient_test, 256, 256, false, 0) { |
| 5 | void draw(SkCanvas* canvas) { |
| 6 | #define SIZE 121 |
| 7 | SkScalar half = SIZE * 0.5f; |
| 8 | const SkColor preColor = 0xFFFF0000; // clamp color before start |
| 9 | const SkColor postColor = 0xFF0000FF; // clamp color after end |
| 10 | const SkColor color0 = 0xFF000000; |
| 11 | const SkColor color1 = 0xFF00FF00; |
| 12 | |
| 13 | SkColor cs[] = {preColor, color0, color1, postColor}; |
| 14 | SkScalar pos[] = {0, 0, 1, 1}; |
| 15 | |
| 16 | auto s = SkGradientShader::MakeRadial({half, half}, half - 10, cs, pos, 4, |
| 17 | SkTileMode::kClamp); |
| 18 | |
| 19 | SkPaint p; |
| 20 | const SkRect rect = SkRect::MakeWH(SIZE, SIZE); |
| 21 | p.setShader(s); |
| 22 | canvas->drawRect(rect, p); |
| 23 | } |
| 24 | } // END FIDDLE |