本文整理汇总了C++中SkRandom::nextF方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRandom::nextF方法的具体用法?C++ SkRandom::nextF怎么用?C++ SkRandom::nextF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRandom
的用法示例。
在下文中一共展示了SkRandom::nextF方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SkTMax
void PathText::Glyph::reset(SkRandom& rand, int w, int h) {
int screensize = SkTMax(w, h);
const SkRect& bounds = fPath.getBounds();
SkScalar t;
fPosition = {rand.nextF() * w, rand.nextF() * h};
t = pow(rand.nextF(), 100);
fZoom = ((1 - t) * screensize / 50 + t * screensize / 3) /
SkTMax(bounds.width(), bounds.height());
fSpin = rand.nextF() * 360;
fMidpt = {bounds.centerX(), bounds.centerY()};
}
示例2: onDraw
void onDraw(SkCanvas* canvas) override {
if (nullptr == fImage) {
fImage = makebm(gSurfaceSize, gSurfaceSize);
}
const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
const int kMaxSrcRectSize = 1 << (SkNextLog2(gSurfaceSize) + 2);
constexpr int kPadX = 30;
constexpr int kPadY = 40;
int rowCount = 0;
canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY));
canvas->save();
SkRandom random;
SkPaint paint;
paint.setAntiAlias(fAA);
for (int w = 1; w <= kMaxSrcRectSize; w *= 3) {
for (int h = 1; h <= kMaxSrcRectSize; h *= 3) {
const SkIRect srcRect =
SkIRect::MakeXYWH((gSurfaceSize - w) / 2, (gSurfaceSize - h) / 2, w, h);
canvas->save();
switch (random.nextU() % 3) {
case 0:
canvas->rotate(random.nextF() * 10.f);
break;
case 1:
canvas->rotate(-random.nextF() * 10.f);
break;
case 2:
// rect stays rect
break;
}
canvas->drawImageRect(fImage.get(), srcRect, dstRect, &paint,
SkCanvas::kFast_SrcRectConstraint);
canvas->restore();
canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0);
++rowCount;
if ((dstRect.width() + 2 * kPadX) * rowCount > gSize) {
canvas->restore();
canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY);
canvas->save();
rowCount = 0;
}
}
}
canvas->restore();
}
示例3: INHERITED
// SkMatrix44::setConcat() has a fast path for matrices that are at most scale+translate.
SetConcatMatrix44Bench(bool fastPath)
: INHERITED(fastPath ? "setconcat_fast" : "setconcat_general")
{
if (fastPath) {
const SkMScalar v = SkDoubleToMScalar(1.5);
fM1.setScale(v,v,v);
fM2.setTranslate(v,v,v);
} else {
SkRandom rand;
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
fM1.setFloat(x,y, rand.nextF());
fM2.setFloat(x,y, rand.nextF());
}}
}
}
示例4: onDelayedSetup
void onDelayedSetup() override {
SkScalar w = SkIntToScalar(fShapesSize.width());
SkScalar h = SkIntToScalar(fShapesSize.height());
fRect.setRect(SkRect::MakeXYWH(-w / 2, -h / 2, w, h));
fOval.setOval(fRect.rect());
fRRect.setNinePatch(fRect.rect(), w / 8, h / 13, w / 11, h / 7);
if (kNone_ShapesType != fInnerShapesType) {
fRect.inset(w / 7, h / 11, &fInnerRect);
fInnerRect.offset(w / 28, h / 44);
fInnerOval.setOval(fInnerRect.rect());
fInnerRRect.setRectXY(fInnerRect.rect(), w / 13, w / 7);
}
SkRandom rand;
fShapes.push_back_n(fNumShapes);
for (int i = 0; i < fNumShapes; i++) {
float pad = sqrtf(static_cast<float>(fShapesSize.width() * fShapesSize.width()) +
static_cast<float>(fShapesSize.height() * fShapesSize.height()));
fShapes[i].fMatrix.setTranslate(0.5f * pad + rand.nextF() * (kBenchWidth - pad),
0.5f * pad + rand.nextF() * (kBenchHeight - pad));
fShapes[i].fMatrix.preRotate(rand.nextF() * 360.0f);
if (fPerspective) {
fShapes[i].fMatrix.setPerspX(0.00015f);
fShapes[i].fMatrix.setPerspY(-0.00015f);
}
fShapes[i].fColor = rand.nextU() | 0xff808080;
}
for (int i = 0; i < fNumShapes; i++) {
// Do this in a separate loop so mixed shapes get the same random numbers during
// placement as non-mixed do.
int shapeType = fShapesType;
if (kMixed_ShapesType == shapeType) {
shapeType = rand.nextRangeU(kRect_ShapesType, kRRect_ShapesType);
}
int innerShapeType = fInnerShapesType;
if (kMixed_ShapesType == innerShapeType) {
innerShapeType = rand.nextRangeU(kRect_ShapesType, kRRect_ShapesType);
}
if (kNone_ShapesType == innerShapeType) {
switch (shapeType) {
using namespace std;
using namespace std::placeholders;
case kRect_ShapesType:
fShapes[i].fDraw = bind(&SkCanvas::drawRect, _1, cref(fRect.rect()), _2);
break;
case kOval_ShapesType:
fShapes[i].fDraw = bind(&SkCanvas::drawOval, _1, cref(fOval.rect()), _2);
break;
case kRRect_ShapesType:
fShapes[i].fDraw = bind(&SkCanvas::drawRRect, _1, cref(fRRect), _2);
break;
}
} else {
const SkRRect* outer;
switch (shapeType) {
case kRect_ShapesType: outer = &fRect; break;
case kOval_ShapesType: outer = &fOval; break;
case kRRect_ShapesType: outer = &fRRect; break;
}
const SkRRect* inner;
switch (innerShapeType) {
case kRect_ShapesType: inner = &fInnerRect; break;
case kOval_ShapesType: inner = &fInnerOval; break;
case kRRect_ShapesType: inner = &fInnerRRect; break;
}
fShapes[i].fDraw = std::bind(&SkCanvas::drawDRRect, std::placeholders::_1,
std::cref(*outer), std::cref(*inner),
std::placeholders::_2);
}
}
}