skia2/samplecode/SampleHairCurves.cpp
commit-bot@chromium.org 6485b0be74 Switch out random number generator for tests, benches, samples.
This change makes tests, benches and samples use the new SkMWCRandom PRNG. GMs will be saved for another time, as they'll require rebaselining.

R=reed@google.com, bsalomon@google.com

Author: jvanverth@google.com

Review URL: https://chromiumcodereview.appspot.com/23653018

git-svn-id: http://skia.googlecode.com/svn/trunk@11136 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-06 19:05:11 +00:00

134 lines
4.3 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkPath.h"
#include "SkRandom.h"
class HairCurvesView : public SampleView {
public:
HairCurvesView() {
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "HairCurves");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(0);
canvas->save();
canvas->scale(1000 * SK_Scalar1, 1000 * SK_Scalar1);
SkMWCRandom rand;
SkMWCRandom randW;
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]);
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]);
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:
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new HairCurvesView; }
static SkViewRegister reg(MyFactory);