本文整理汇总了C++中SkRandom::nextRangeScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRandom::nextRangeScalar方法的具体用法?C++ SkRandom::nextRangeScalar怎么用?C++ SkRandom::nextRangeScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRandom
的用法示例。
在下文中一共展示了SkRandom::nextRangeScalar方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDraw
void onDraw(const int loops, SkCanvas* canvas) override {
const char* text = "Hamburgefons";
size_t len = strlen(text);
SkISize size = canvas->getDeviceSize();
SkRandom random;
for (int i = 0; i < loops; ++i) {
SkPaint paint;
paint.setXfermode(fXfermode.get());
paint.setColor(random.nextU());
if (fAA) {
// Draw text to exercise AA code paths.
paint.setAntiAlias(true);
paint.setTextSize(random.nextRangeScalar(12, 96));
SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth),
y = random.nextRangeScalar(0, (SkScalar)size.fHeight);
for (int j = 0; j < 1000; ++j) {
canvas->drawText(text, len, x, y, paint);
}
} else {
// Draw rects to exercise non-AA code paths.
SkScalar w = random.nextRangeScalar(50, 100);
SkScalar h = random.nextRangeScalar(50, 100);
SkRect rect = SkRect::MakeXYWH(
random.nextUScalar1() * (size.fWidth - w),
random.nextUScalar1() * (size.fHeight - h),
w,
h
);
for (int j = 0; j < 1000; ++j) {
canvas->drawRect(rect, paint);
}
}
}
}
示例2: rand_rect
static void rand_rect(SkRect* rect, SkRandom& rand, SkScalar W, SkScalar H) {
rect->fLeft = rand.nextRangeScalar(-W, 2*W);
rect->fTop = rand.nextRangeScalar(-H, 2*H);
rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W);
rect->fBottom = rect->fTop + rand.nextRangeScalar(0, H);
// we integralize rect to make our tests more predictable, since Gather is
// a little sloppy.
SkIRect ir;
rect->round(&ir);
rect->set(ir);
}
示例3: onPreDraw
virtual void onPreDraw() {
const SkScalar min = -100;
const SkScalar max = 100;
SkRandom rand;
for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
SkScalar x = rand.nextRangeScalar(min, max);
SkScalar y = rand.nextRangeScalar(min, max);
SkScalar w = rand.nextRangeScalar(min, max);
SkScalar h = rand.nextRangeScalar(min, max);
fRects[i].setXYWH(x, y, w, h);
}
}
示例4: gen_data
// Generates y values for the chart plots.
static void gen_data(SkScalar yAvg, SkScalar ySpread, int count, SkTDArray<SkScalar>* dataPts) {
dataPts->setCount(count);
static SkRandom gRandom;
for (int i = 0; i < count; ++i) {
(*dataPts)[i] = gRandom.nextRangeScalar(yAvg - SkScalarHalf(ySpread),
yAvg + SkScalarHalf(ySpread));
}
}
示例5: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkRandom Random;
for (int i = 0; i < loops; i++) {
SkScalar blurSigma = Random.nextRangeScalar(1.5f, 25.0f);
SkScalar size = Random.nextRangeScalar(20*blurSigma, 50*blurSigma);
SkScalar x = Random.nextRangeScalar(0.0f, W - size);
SkScalar y = Random.nextRangeScalar(0.0f, H - size);
SkRect inner = { x, y, x + size, y + size };
SkRect outer(inner);
// outer is always outset either 2x or 4x the blur radius (we go with 2x)
outer.outset(2*blurSigma, 2*blurSigma);
SkPath p;
p.addRect(outer);
p.addRect(inner);
p.setFillType(SkPath::kEvenOdd_FillType);
// This will be used to translate the normal draw outside the
// clip rect and translate the blurred version back inside
SkScalar translate = 2.0f * size;
SkPaint paint;
paint.setLooper(this->createLooper(-translate, blurSigma));
paint.setColor(0xff000000 | Random.nextU());
paint.setAntiAlias(true);
canvas->save();
// clip always equals inner rect so we get the inside blur
canvas->clipRect(inner);
canvas->translate(translate, 0);
canvas->drawPath(p, paint);
canvas->restore();
}
}
示例6: onDraw
void onDraw(SkCanvas* canvas) override {
SkPaint paint;
paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref();
canvas->saveLayer(NULL, &paint);
const char* str = "The quick brown fox jumped over the lazy dog.";
SkRandom rand;
SkPaint textPaint;
textPaint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface_always(&textPaint);
for (int i = 0; i < 25; ++i) {
int x = rand.nextULessThan(WIDTH);
int y = rand.nextULessThan(HEIGHT);
textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
textPaint.setTextSize(rand.nextRangeScalar(0, 300));
canvas->drawText(str, strlen(str), SkIntToScalar(x),
SkIntToScalar(y), textPaint);
}
canvas->restore();
}
示例7: SkIntToScalar
DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
SkPaint filterPaint;
filterPaint.setImageFilter(
SkMagnifierImageFilter::Make(
SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
SkIntToScalar(WIDTH / 2),
SkIntToScalar(HEIGHT / 2)),
100, nullptr));
canvas->saveLayer(nullptr, &filterPaint);
const char* str = "The quick brown fox jumped over the lazy dog.";
SkRandom rand;
for (int i = 0; i < 25; ++i) {
int x = rand.nextULessThan(WIDTH);
int y = rand.nextULessThan(HEIGHT);
SkPaint paint;
sk_tool_utils::set_portable_typeface(&paint);
paint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
paint.setTextSize(rand.nextRangeScalar(0, 300));
paint.setAntiAlias(true);
canvas->drawText(str, strlen(str), SkIntToScalar(x),
SkIntToScalar(y), paint);
}
canvas->restore();
}
示例8: onDraw
void onDraw(SkCanvas* canvas) override {
SkPaint filterPaint;
filterPaint.setImageFilter(
SkMagnifierImageFilter::Create(
SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
SkIntToScalar(WIDTH / 2),
SkIntToScalar(HEIGHT / 2)),
100))->unref();
canvas->saveLayer(NULL, &filterPaint);
const char* str = "The quick brown fox jumped over the lazy dog.";
SkRandom rand;
for (int i = 0; i < 25; ++i) {
int x = rand.nextULessThan(WIDTH);
int y = rand.nextULessThan(HEIGHT);
SkPaint paint;
sk_tool_utils::set_portable_typeface(&paint);
paint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
paint.setTextSize(rand.nextRangeScalar(0, 300));
paint.setAntiAlias(true);
canvas->drawText(str, strlen(str), SkIntToScalar(x),
SkIntToScalar(y), paint);
}
canvas->restore();
}
示例9: onOnceBeforeDraw
void onOnceBeforeDraw() override {
fPaint.setAntiAlias(true);
fPaint.setLCDRenderText(fLCD);
SkISize size = this->getISize();
SkScalar w = SkIntToScalar(size.fWidth);
SkScalar h = SkIntToScalar(size.fHeight);
static_assert(4 == SK_ARRAY_COUNT(fTypefaces), "typeface_cnt");
fTypefaces[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle());
fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",
SkFontStyle::FromOldStyle(SkTypeface::kBold));
fTypefaces[2] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle());
fTypefaces[3] = sk_tool_utils::create_portable_typeface("serif",
SkFontStyle::FromOldStyle(SkTypeface::kBold));
SkRandom random;
for (int i = 0; i < kCnt; ++i) {
int length = random.nextRangeU(kMinLength, kMaxLength);
char text[kMaxLength];
for (int j = 0; j < length; ++j) {
text[j] = (char)random.nextRangeU('!', 'z');
}
fStrings[i].set(text, length);
fColors[i] = random.nextU();
fColors[i] |= 0xFF000000;
fColors[i] = sk_tool_utils::color_to_565(fColors[i]);
static const SkScalar kMinPtSize = 8.f;
static const SkScalar kMaxPtSize = 32.f;
fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize);
fTypefaceIndices[i] = random.nextULessThan(SK_ARRAY_COUNT(fTypefaces));
SkRect r;
fPaint.setColor(fColors[i]);
fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]);
fPaint.setTextSize(fPtSizes[i]);
fPaint.measureText(fStrings[i].c_str(), fStrings[i].size(), &r);
// safeRect is set of x,y positions where we can draw the string without hitting
// the GM's border.
SkRect safeRect = SkRect::MakeLTRB(-r.fLeft, -r.fTop, w - r.fRight, h - r.fBottom);
if (safeRect.isEmpty()) {
// If we don't fit then just don't worry about how we get cliped to the device
// border.
safeRect = SkRect::MakeWH(w, h);
}
fPositions[i].fX = random.nextRangeScalar(safeRect.fLeft, safeRect.fRight);
fPositions[i].fY = random.nextRangeScalar(safeRect.fTop, safeRect.fBottom);
fClipRects[i] = r;
fClipRects[i].offset(fPositions[i].fX, fPositions[i].fY);
fClipRects[i].outset(2.f, 2.f);
if (fEffectiveClip) {
fClipRects[i].fRight -= 0.25f * fClipRects[i].width();
}
}
}
示例10: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkRandom scaleRand;
SkRandom transRand;
SkRandom rotRand;
int width, height;
if (fUseAtlas) {
width = kAtlasCellWidth;
height = kAtlasCellHeight;
} else {
width = kCheckerboardWidth;
height = kCheckerboardHeight;
}
SkPaint clearPaint;
clearPaint.setColor(0xFF000000);
clearPaint.setAntiAlias(true);
SkISize size = canvas->getDeviceSize();
SkScalar maxTransX, maxTransY;
if (kScale_Type == fType) {
maxTransX = size.fWidth - (1.5f * width);
maxTransY = size.fHeight - (1.5f * height);
} else if (kTranslate_Type == fType) {
maxTransX = SkIntToScalar(size.fWidth - width);
maxTransY = SkIntToScalar(size.fHeight - height);
} else {
SkASSERT(kRotate_Type == fType);
// Yes, some rotations will be off the top and left sides
maxTransX = size.fWidth - SK_ScalarSqrt2 * height;
maxTransY = size.fHeight - SK_ScalarSqrt2 * height;
}
SkMatrix mat;
SkRect dst = { 0, 0, SkIntToScalar(width), SkIntToScalar(height) };
SkRect clearRect = { -1.0f, -1.0f, width+1.0f, height+1.0f };
SkPoint verts[4] = { // for drawVertices path
{ 0, 0 },
{ 0, SkIntToScalar(height) },
{ SkIntToScalar(width), SkIntToScalar(height) },
{ SkIntToScalar(width), 0 }
};
uint16_t indices[6] = { 0, 1, 2, 0, 2, 3 };
SkPaint p;
p.setColor(0xFF000000);
p.setFilterQuality(kLow_SkFilterQuality);
SkPaint p2; // for drawVertices path
p2.setColor(0xFF000000);
p2.setFilterQuality(kLow_SkFilterQuality);
p2.setShader(SkShader::MakeBitmapShader(fAtlas,
SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode));
for (int i = 0; i < loops; ++i, ++fNumSaved) {
if (0 == i % kNumBeforeClear) {
if (kPartial_Clear == fClear) {
for (int j = 0; j < fNumSaved; ++j) {
canvas->setMatrix(SkMatrix::I());
mat.setTranslate(fSaved[j][0], fSaved[j][1]);
if (kScale_Type == fType) {
mat.preScale(fSaved[j][2], fSaved[j][2]);
} else if (kRotate_Type == fType) {
mat.preRotate(fSaved[j][2]);
}
canvas->concat(mat);
canvas->drawRect(clearRect, clearPaint);
}
} else {
canvas->clear(0xFF000000);
}
fNumSaved = 0;
}
SkASSERT(fNumSaved < kNumBeforeClear);
canvas->setMatrix(SkMatrix::I());
fSaved[fNumSaved][0] = transRand.nextRangeScalar(0.0f, maxTransX);
fSaved[fNumSaved][1] = transRand.nextRangeScalar(0.0f, maxTransY);
if (fAligned) {
// make the translations integer aligned
fSaved[fNumSaved][0] = SkScalarFloorToScalar(fSaved[fNumSaved][0]);
fSaved[fNumSaved][1] = SkScalarFloorToScalar(fSaved[fNumSaved][1]);
}
mat.setTranslate(fSaved[fNumSaved][0], fSaved[fNumSaved][1]);
if (kScale_Type == fType) {
fSaved[fNumSaved][2] = scaleRand.nextRangeScalar(0.5f, 1.5f);
mat.preScale(fSaved[fNumSaved][2], fSaved[fNumSaved][2]);
} else if (kRotate_Type == fType) {
fSaved[fNumSaved][2] = rotRand.nextRangeScalar(0.0f, 360.0f);
mat.preRotate(fSaved[fNumSaved][2]);
//.........这里部分代码省略.........