blob: 051aab4851c216ccddcc4bacc1bcc79729373a1e [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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 Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=d84fce292d86c7d9ef37ae2d179c03c7
Hal Canary66d11442019-03-19 15:54:16 -04005REG_FIDDLE(Point_normalize_2, 256, 256, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 SkPaint paint;
8 paint.setAntiAlias(true);
9 const SkPoint lines[][2] = { {{ 30, 110 }, { 190, 30 }},
10 {{ 120, 140 }, { 30, 220 }}};
11 for (auto line : lines) {
12 canvas->drawLine(line[0], line[1], paint);
13 SkVector vector = line[1] - line[0];
14 if (vector.normalize()) {
15 SkVector rotate90 = { -vector.fY, vector.fX };
16 rotate90 *= 10.f;
17 canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint);
18 canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint);
19 }
20 }
21}
22} // END FIDDLE