Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
beziers.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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
8#include "gm/gm.h"
13#include "include/core/SkSize.h"
15#include "src/base/SkRandom.h"
16
17#define W 400
18#define H 400
19#define N 10
20
22
24 auto a = rand.nextRangeScalar(0,W),
25 b = rand.nextRangeScalar(0,H);
26
27 SkPathBuilder builder;
28 builder.moveTo(a, b);
29 for (int x = 0; x < 2; ++x) {
30 auto c = rand.nextRangeScalar(W/4, W),
31 d = rand.nextRangeScalar( 0, H),
32 e = rand.nextRangeScalar( 0, W),
33 f = rand.nextRangeScalar(H/4, H);
34 builder.quadTo(c,d,e,f);
35 }
36 paint->setColor(rand.nextU());
37 SkScalar width = rand.nextRangeScalar(1, 5);
38 width *= width;
39 paint->setStrokeWidth(width);
40 paint->setAlphaf(1.0f);
41 return builder.detach();
42}
43
45 auto a = rand.nextRangeScalar(0,W),
46 b = rand.nextRangeScalar(0,H);
47
48 SkPathBuilder builder;
49 builder.moveTo(a, b);
50 for (int x = 0; x < 2; ++x) {
51 auto c = rand.nextRangeScalar(W/4, W),
52 d = rand.nextRangeScalar( 0, H),
53 e = rand.nextRangeScalar( 0, W),
54 f = rand.nextRangeScalar(H/4, H),
55 g = rand.nextRangeScalar(W/4, W),
56 h = rand.nextRangeScalar(H/4, H);
57 builder.cubicTo(c,d,e,f,g,h);
58 }
59 paint->setColor(rand.nextU());
60 SkScalar width = rand.nextRangeScalar(1, 5);
61 width *= width;
62 paint->setStrokeWidth(width);
63 paint->setAlphaf(1.0f);
64 return builder.detach();
65}
66
67class BeziersGM : public skiagm::GM {
68public:
70
71protected:
72 SkString getName() const override { return SkString("beziers"); }
73
74 SkISize getISize() override { return SkISize::Make(W, H * 2); }
75
76 void onDraw(SkCanvas* canvas) override {
79 paint.setStrokeWidth(SkIntToScalar(9)/2);
80 paint.setAntiAlias(true);
81
82 SkRandom rand;
83 for (int i = 0; i < N; i++) {
84 canvas->drawPath(rnd_quad(&paint, rand), paint);
85 }
86 canvas->translate(0, SH);
87 for (int i = 0; i < N; i++) {
88 canvas->drawPath(rnd_cubic(&paint, rand), paint);
89 }
90 }
91
92private:
93 using INHERITED = skiagm::GM;
94};
95
96DEF_GM( return new BeziersGM; )
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define N
Definition beziers.cpp:19
static SkPath rnd_cubic(SkPaint *paint, SkRandom &rand)
Definition beziers.cpp:44
constexpr SkScalar SH
Definition beziers.cpp:21
#define W
Definition beziers.cpp:17
static SkPath rnd_quad(SkPaint *paint, SkRandom &rand)
Definition beziers.cpp:23
void onDraw(SkCanvas *canvas) override
Definition beziers.cpp:76
SkISize getISize() override
Definition beziers.cpp:74
SkString getName() const override
Definition beziers.cpp:72
void translate(SkScalar dx, SkScalar dy)
void drawPath(const SkPath &path, const SkPaint &paint)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
uint32_t nextU()
Definition SkRandom.h:42
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition SkRandom.h:106
const Paint & paint
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
float SkScalar
Definition extension.cpp:12
static bool b
struct MyStruct a[10]
#define DEF_GM(CODE)
Definition gm.h:40
double x
SkScalar h
int32_t width
Definition SkMD5.cpp:130
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20