2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
12 // Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
14 static const int kWidth = 640;
15 static const int kHeight = 480;
16 static const SkScalar kAngle = 0.305f;
18 // Renders a string art shape.
19 // The particular shape rendered can be controlled by adjusting kAngle, from 0 to 1
21 class StringArtGM : public skiagm::GM {
27 SkString onShortName() SK_OVERRIDE {
28 return SkString("stringart");
31 SkISize onISize() SK_OVERRIDE {
32 return SkISize::Make(kWidth, kHeight);
35 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
36 SkScalar angle = kAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
37 SkScalar size = SkIntToScalar(SkMin32(kWidth, kHeight));
38 SkPoint center = SkPoint::Make(SkScalarHalf(kWidth), SkScalarHalf(kHeight));
40 SkScalar step = angle;
45 while (length < (SkScalarHalf(size) - 10.f))
47 SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
48 length*SkScalarSin(step) + center.fY);
50 length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
56 paint.setAntiAlias(true);
57 paint.setStyle(SkPaint::kStroke_Style);
58 paint.setColor(0xFF007700);
60 canvas->drawPath(path, paint);
67 DEF_GM( return new StringArtGM; )