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.
8 #include "include/core/SkCanvas.h"
9 #include "include/core/SkPath.h"
10 #include "samplecode/Sample.h"
12 // Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
14 // Renders a string art shape.
15 // The particular shape rendered can be controlled by clicking horizontally, thereby
16 // generating an angle from 0 to 1.
18 class StringArtView : public Sample {
20 StringArtView() : fAngle(0.305f) {}
23 SkString name() override { return SkString("StringArt"); }
25 void onDrawContent(SkCanvas* canvas) override {
26 SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
28 SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf(this->height()));
30 SkScalar step = angle;
35 while (length < (SkScalarHalf(std::min(this->width(), this->height())) - 10.f))
37 SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
38 length*SkScalarSin(step) + center.fY);
40 length += angle / SkScalarHalf(SK_ScalarPI);
46 paint.setAntiAlias(true);
47 paint.setStyle(SkPaint::kStroke_Style);
48 paint.setColor(0xFF007700);
50 canvas->drawPath(path, paint);
53 Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
60 using INHERITED = Sample;
63 //////////////////////////////////////////////////////////////////////////////
65 DEF_SAMPLE( return new StringArtView(); )