Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=935c8f8b9782d297a73d7186f6ef7945 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Canvas_drawTextRSXform, 256, 256, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | const int iterations = 26; |
| 8 | SkRSXform transforms[iterations]; |
| 9 | char alphabet[iterations]; |
| 10 | SkScalar angle = 0; |
| 11 | SkScalar scale = 1; |
| 12 | for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) { |
| 13 | const SkScalar s = SkScalarSin(angle) * scale; |
| 14 | const SkScalar c = SkScalarCos(angle) * scale; |
| 15 | transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16); |
Hal Canary | 3d42a05 | 2019-03-15 16:43:29 -0400 | [diff] [blame] | 16 | angle += .45f; |
| 17 | scale += .2f; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 18 | alphabet[i] = 'A' + i; |
| 19 | } |
| 20 | SkPaint paint; |
Hal Canary | 3d42a05 | 2019-03-15 16:43:29 -0400 | [diff] [blame] | 21 | SkFont font(nullptr, 20); |
| 22 | auto spiral = SkTextBlob::MakeFromRSXform(alphabet, sizeof(alphabet), transforms, font); |
| 23 | canvas->drawTextBlob(spiral, 110, 138, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 24 | } |
| 25 | } // END FIDDLE |