Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: samplecode/SampleStringArt.cpp

Issue 23609037: Add string art GM and sample. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« gm/stringart.cpp ('K') | « gyp/gmslides.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SampleCode.h"
8 #include "SkCanvas.h"
9
robertphillips 2013/09/12 15:19:56 // comment?
jvanverth1 2013/09/12 16:55:44 Done.
10 class StringArtView : public SampleView {
11 public:
12 StringArtView() : fAngle(0.305f) {}
13
14 protected:
15 // overrides from SkEventSink
16 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
17 if (SampleCode::TitleQ(*evt)) {
18 SampleCode::TitleR(evt, "StringArt");
19 return true;
20 }
21 return this->INHERITED::onQuery(evt);
22 }
23
24 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
25 SkScalar angle = fAngle * SK_ScalarPI + SK_ScalarPI*SK_ScalarHalf;
26
robertphillips 2013/09/12 15:19:56 this->width()? this->height()?
jvanverth1 2013/09/12 16:55:44 Done.
27 SkPoint center = SkPoint::Make( width()*SK_ScalarHalf, height()*SK_Scala rHalf );
28 SkScalar length = 5;
29 SkScalar step = angle;
30
31 SkPath path;
32 path.moveTo(center);
33
34 while (length < (SkMin32(width(), height())*SK_ScalarHalf - 10.f))
35 {
36 SkPoint rp = SkPoint::Make(length * SkScalarCos(step) + center.fX,
37 length * SkScalarSin(step) + center.fY);
38 path.lineTo(rp);
39 length += angle/(SK_ScalarPI*SK_ScalarHalf);
40 step += angle;
41 }
42 path.close();
43
44 SkPaint paint;
45 paint.setAntiAlias(true);
46 paint.setStyle(SkPaint::kStroke_Style);
47 paint.setColor(0xFF007700);
48
49 canvas->drawPath(path, paint);
50 }
51
52 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE {
53 fAngle = x/width();
54 this->inval(NULL);
55 return NULL;
56 }
57 private:
58
59 SkScalar fAngle;
60 typedef SampleView INHERITED;
61 };
62
63 //////////////////////////////////////////////////////////////////////////////
64
65 static SkView* MyFactory() { return new StringArtView; }
66 static SkViewRegister reg(MyFactory);
OLDNEW
« gm/stringart.cpp ('K') | « gyp/gmslides.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698