Flutter Engine
The Flutter Engine
StringArtSlide.cpp
Go to the documentation of this file.
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
11
12// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
13
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.
17
19public:
20 StringArtSlide() : fAngle(0.305f) { fName = "StringArt"; }
21
22 void load(SkScalar w, SkScalar h) override { fSize = {w, h}; }
23
24 void resize(SkScalar w, SkScalar h) override { fSize = {w, h}; }
25
26 void draw(SkCanvas* canvas) override {
28
29 SkPoint center = SkPoint::Make(fSize.width()/2, fSize.height()/2);
30 SkScalar length = 5;
31 SkScalar step = angle;
32
34 path.moveTo(center);
35
36 while (length < (std::min(fSize.width(), fSize.height())/2 - 10.f))
37 {
40 path.lineTo(rp);
42 step += angle;
43 }
44 path.close();
45
47 paint.setAntiAlias(true);
49 paint.setColor(0xFF007700);
50
51 canvas->drawPath(path, paint);
52 }
53
54protected:
56 fAngle = x/fSize.width();
57 return nullptr;
58 }
59
60 bool onClick(ClickHandlerSlide::Click *) override { return false; }
61
62private:
63 SkScalar fAngle;
64 SkSize fSize;
65};
66
67//////////////////////////////////////////////////////////////////////////////
68
69DEF_SLIDE( return new StringArtSlide(); )
static int step(int x, SkScalar min, SkScalar max)
Definition: BlurTest.cpp:215
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarHalf(a)
Definition: SkScalar.h:75
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
#define DEF_SLIDE(code)
Definition: Slide.h:25
static SkScalar center(float pos0, float pos1)
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
SkString fName
Definition: Slide.h:54
Click * onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override
void resize(SkScalar w, SkScalar h) override
void draw(SkCanvas *canvas) override
void load(SkScalar w, SkScalar h) override
bool onClick(ClickHandlerSlide::Click *) override
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
static float min(float r, float g, float b)
Definition: hsl.cpp:48
size_t length
double y
double x
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
ModifierKey
Definition: ModifierKey.h:9
SkScalar w
SkScalar h
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
Definition: SkSize.h:52
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77