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.
7 #include "SampleCode.h"
10 // Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
12 // Renders a string art shape.
13 // The particular shape rendered can be controlled by clicking horizontally, thereby
14 // generating an angle from 0 to 1.
16 class StringArtView : public SampleView {
18 StringArtView() : fAngle(0.305f) {}
21 // overrides from SkEventSink
22 bool onQuery(SkEvent* evt) SK_OVERRIDE {
23 if (SampleCode::TitleQ(*evt)) {
24 SampleCode::TitleR(evt, "StringArt");
27 return this->INHERITED::onQuery(evt);
30 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
31 SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
33 SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf(this->height()));
35 SkScalar step = angle;
40 while (length < (SkScalarHalf(SkMinScalar(this->width(), this->height())) - 10.f))
42 SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
43 length*SkScalarSin(step) + center.fY);
45 length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
51 paint.setAntiAlias(true);
52 paint.setStyle(SkPaint::kStroke_Style);
53 paint.setColor(0xFF007700);
55 canvas->drawPath(path, paint);
58 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE {
66 typedef SampleView INHERITED;
69 //////////////////////////////////////////////////////////////////////////////
71 static SkView* MyFactory() { return new StringArtView; }
72 static SkViewRegister reg(MyFactory);