2011-08-30 18:13:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2011-08-30 18:13:44 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class HairCurvesView : public Sample {
|
2011-08-30 18:13:44 +00:00
|
|
|
public:
|
|
|
|
HairCurvesView() {
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-08-30 18:13:44 +00:00
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("HairCurves"); }
|
2011-08-30 18:13:44 +00:00
|
|
|
|
2019-07-03 14:55:44 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2011-08-30 18:13:44 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2013-07-17 19:30:41 +00:00
|
|
|
paint.setStrokeWidth(0);
|
2011-08-30 18:13:44 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->scale(1000 * SK_Scalar1, 1000 * SK_Scalar1);
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
|
|
|
SkRandom randW;
|
2011-08-30 18:13:44 +00:00
|
|
|
SkPath curves;
|
|
|
|
SkPath hulls;
|
|
|
|
SkPath ctrlPts;
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
SkScalar pts[] = {
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1()
|
|
|
|
};
|
|
|
|
curves.moveTo(pts[0], pts[1]);
|
|
|
|
curves.cubicTo(pts[2], pts[3],
|
|
|
|
pts[4], pts[5],
|
|
|
|
pts[6], pts[7]);
|
|
|
|
|
|
|
|
hulls.moveTo(pts[0], pts[1]);
|
|
|
|
hulls.lineTo(pts[2], pts[3]);
|
|
|
|
hulls.lineTo(pts[4], pts[5]);
|
|
|
|
hulls.lineTo(pts[6], pts[7]);
|
|
|
|
|
|
|
|
ctrlPts.addCircle(pts[0], pts[1], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[2], pts[3], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[4], pts[5], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[6], pts[7], SK_Scalar1 / 200);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
SkScalar pts[] = {
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
};
|
|
|
|
curves.moveTo(pts[0], pts[1]);
|
|
|
|
curves.quadTo(pts[2], pts[3],
|
|
|
|
pts[4], pts[5]);
|
|
|
|
|
|
|
|
hulls.moveTo(pts[0], pts[1]);
|
|
|
|
hulls.lineTo(pts[2], pts[3]);
|
|
|
|
hulls.lineTo(pts[4], pts[5]);
|
|
|
|
|
2013-08-01 17:09:11 +00:00
|
|
|
ctrlPts.addCircle(pts[0], pts[1], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[2], pts[3], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[4], pts[5], SK_Scalar1 / 200);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
SkScalar pts[] = {
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
};
|
|
|
|
SkScalar weight = randW.nextUScalar1() * 2.0f;
|
|
|
|
|
|
|
|
curves.moveTo(pts[0], pts[1]);
|
|
|
|
curves.conicTo(pts[2], pts[3],
|
|
|
|
pts[4], pts[5],
|
|
|
|
weight);
|
|
|
|
|
|
|
|
hulls.moveTo(pts[0], pts[1]);
|
|
|
|
hulls.lineTo(pts[2], pts[3]);
|
|
|
|
hulls.lineTo(pts[4], pts[5]);
|
|
|
|
|
2011-08-30 18:13:44 +00:00
|
|
|
ctrlPts.addCircle(pts[0], pts[1], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[2], pts[3], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[4], pts[5], SK_Scalar1 / 200);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
SkScalar pts[] = {
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
rand.nextUScalar1(), rand.nextUScalar1(),
|
|
|
|
};
|
|
|
|
curves.moveTo(pts[0], pts[1]);
|
|
|
|
curves.lineTo(pts[2], pts[3]);
|
|
|
|
|
|
|
|
ctrlPts.addCircle(pts[0], pts[1], SK_Scalar1 / 200);
|
|
|
|
ctrlPts.addCircle(pts[2], pts[3], SK_Scalar1 / 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
canvas->drawPath(curves, paint);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
//canvas->drawPath(hulls, paint);
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
//canvas->drawPath(ctrlPts, paint);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-08-30 18:13:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new HairCurvesView(); )
|