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.
3 #include "tools/fiddle/examples.h"
4 // HASH=935c8f8b9782d297a73d7186f6ef7945
5 REG_FIDDLE(Canvas_drawTextRSXform, 256, 256, false, 0) {
draw(SkCanvas * canvas)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);
16 angle += .45f;
17 scale += .2f;
18 alphabet[i] = 'A' + i;
19 }
20 SkPaint paint;
21 SkFont font(nullptr, 20);
22 auto spiral = SkTextBlob::MakeFromRSXform(alphabet, sizeof(alphabet), transforms, font);
23 canvas->drawTextBlob(spiral, 110, 138, paint);
24 }
25 } // END FIDDLE
26