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(mapradius, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     SkPaint paint;
7     paint.setAntiAlias(true);
8     paint.setStyle(SkPaint::kStroke_Style);
9     SkMatrix matrix;
10     const SkPoint center = {128, 103};
11     matrix.setScale(2, .5f, center.fX, center.fY);
12     matrix.postRotate(45, center.fX, center.fY);
13     const SkScalar circleRadius = 60;
14     SkScalar mappedRadius = matrix.mapRadius(circleRadius);
15     SkVector minorAxis, majorAxis;
16     matrix.mapVector(0, circleRadius, &minorAxis);
17     matrix.mapVector(circleRadius, 0, &majorAxis);
18     paint.setColor(SK_ColorRED);
19     canvas->drawLine(40, 240, 40 + minorAxis.length(), 240, paint);
20     canvas->drawLine(42 + minorAxis.length(), 240, 42 + minorAxis.length() + majorAxis.length(),
21                      240, paint);
22     paint.setColor(SK_ColorBLACK);
23     canvas->drawLine(center.fX, center.fY, center.fX + mappedRadius, center.fY, paint);
24     canvas->drawLine(center.fX, center.fY, center.fX, center.fY + mappedRadius, paint);
25     canvas->drawLine(40, 220, 40 + mappedRadius, 220, paint);
26     canvas->drawLine(42 + mappedRadius, 220, 42 + mappedRadius * 2, 220, paint);
27     canvas->concat(matrix);
28     canvas->drawCircle(center.fX, center.fY, circleRadius, paint);
29     paint.setColor(SK_ColorRED);
30     canvas->drawLine(center.fX, center.fY, center.fX + circleRadius, center.fY, paint);
31     canvas->drawLine(center.fX, center.fY, center.fX, center.fY + circleRadius, paint);
32 }
33 }  // END FIDDLE
34