本文整理汇总了C++中KisPaintInformation::randomSource方法的典型用法代码示例。如果您正苦于以下问题:C++ KisPaintInformation::randomSource方法的具体用法?C++ KisPaintInformation::randomSource怎么用?C++ KisPaintInformation::randomSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KisPaintInformation
的用法示例。
在下文中一共展示了KisPaintInformation::randomSource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintLine
void HairyBrush::paintLine(KisPaintDeviceSP dab, KisPaintDeviceSP layer, const KisPaintInformation &pi1, const KisPaintInformation &pi2, qreal scale, qreal rotation)
{
m_counter++;
qreal x1 = pi1.pos().x();
qreal y1 = pi1.pos().y();
qreal x2 = pi2.pos().x();
qreal y2 = pi2.pos().y();
qreal dx = x2 - x1;
qreal dy = y2 - y1;
// TODO:this angle is different from the drawing angle in sensor (info.angle()). The bug is caused probably due to
// not computing the drag vector properly in paintBezierLine when smoothing is used
//qreal angle = atan2(dy, dx);
qreal angle = rotation;
qreal mousePressure = 1.0;
if (m_properties->useMousePressure) { // want pressure from mouse movement
qreal distance = sqrt(dx * dx + dy * dy);
mousePressure = (1.0 - computeMousePressure(distance));
scale *= mousePressure;
}
// this pressure controls shear and ink depletion
qreal pressure = mousePressure * (pi2.pressure() * 2);
Bristle *bristle = 0;
KoColor bristleColor(dab->colorSpace());
m_dabAccessor = dab->createRandomAccessorNG((int)x1, (int)y1);
m_dab = dab;
// initialization block
if (firstStroke()) {
initAndCache();
}
// if this is first time the brush touches the canvas and we use soak the ink from canvas
if (firstStroke() && m_properties->useSoakInk) {
if (layer) {
colorifyBristles(layer, pi1.pos());
}
else {
dbgKrita << "Can't soak the ink from the layer";
}
}
KisRandomSourceSP randomSource = pi2.randomSource();
qreal fx1, fy1, fx2, fy2;
qreal randomX, randomY;
qreal shear;
float inkDeplation = 0.0;
int inkDepletionSize = m_properties->inkDepletionCurve.size();
int bristleCount = m_bristles.size();
int bristlePathSize;
qreal treshold = 1.0 - pi2.pressure();
for (int i = 0; i < bristleCount; i++) {
if (!m_bristles.at(i)->enabled()) continue;
bristle = m_bristles[i];
randomX = (randomSource->generateNormalized() * 2 - 1.0) * m_properties->randomFactor;
randomY = (randomSource->generateNormalized() * 2 - 1.0) * m_properties->randomFactor;
shear = pressure * m_properties->shearFactor;
m_transform.reset();
m_transform.rotateRadians(-angle);
m_transform.scale(scale, scale);
m_transform.translate(randomX, randomY);
m_transform.shear(shear, shear);
if (firstStroke() || (!m_properties->connectedPath)) {
// transform start dab
m_transform.map(bristle->x(), bristle->y(), &fx1, &fy1);
// transform end dab
m_transform.map(bristle->x(), bristle->y(), &fx2, &fy2);
}
else {
// continue the path of the bristle from the previous position
fx1 = bristle->prevX();
fy1 = bristle->prevY();
m_transform.map(bristle->x(), bristle->y(), &fx2, &fy2);
}
// remember the end point
bristle->setPrevX(fx2);
bristle->setPrevY(fy2);
// all coords relative to device position
fx1 += x1;
fy1 += y1;
fx2 += x2;
fy2 += y2;
if (m_properties->threshold && (bristle->length() < treshold)) continue;
//.........这里部分代码省略.........
示例2: paint
void SprayBrush::paint(KisPaintDeviceSP dab, KisPaintDeviceSP source,
const KisPaintInformation& info,
qreal rotation, qreal scale,
qreal additionalScale,
const KoColor &color, const KoColor &bgColor)
{
KisRandomSourceSP randomSource = info.randomSource();
// initializing painter
if (!m_painter) {
m_painter = new KisPainter(dab);
m_painter->setFillStyle(KisPainter::FillStyleForegroundColor);
m_painter->setMaskImageSize(m_shapeProperties->width, m_shapeProperties->height);
m_dabPixelSize = dab->colorSpace()->pixelSize();
if (m_colorProperties->useRandomHSV) {
m_transfo = dab->colorSpace()->createColorTransformation("hsv_adjustment", QHash<QString, QVariant>());
}
m_brushQImage = m_shapeProperties->image;
if (!m_brushQImage.isNull()) {
m_brushQImage = m_brushQImage.scaled(m_shapeProperties->width, m_shapeProperties->height);
}
m_imageDevice = new KisPaintDevice(dab->colorSpace());
}
qreal x = info.pos().x();
qreal y = info.pos().y();
KisRandomAccessorSP accessor = dab->createRandomAccessorNG(qRound(x), qRound(y));
Q_ASSERT(color.colorSpace()->pixelSize() == dab->pixelSize());
m_inkColor = color;
KisCrossDeviceColorPicker colorPicker(source, m_inkColor);
// apply size sensor
m_radius = m_properties->radius() * scale * additionalScale;
// jitter movement
if (m_properties->jitterMovement) {
x = x + ((2 * m_radius * randomSource->generateNormalized()) - m_radius) * m_properties->amount;
y = y + ((2 * m_radius * randomSource->generateNormalized()) - m_radius) * m_properties->amount;
}
// this is wrong for every shape except pixel and anti-aliased pixel
if (m_properties->useDensity) {
m_particlesCount = (m_properties->coverage * (M_PI * pow2(m_radius)) / pow2(additionalScale));
}
else {
m_particlesCount = m_properties->particleCount;
}
QHash<QString, QVariant> params;
qreal nx, ny;
int ix, iy;
qreal angle;
qreal length;
qreal rotationZ = 0.0;
qreal particleScale = 1.0;
bool shouldColor = true;
if (m_colorProperties->fillBackground) {
m_painter->setPaintColor(bgColor);
paintCircle(m_painter, x, y, m_radius);
}
QTransform m;
m.reset();
m.rotateRadians(-rotation + deg2rad(m_properties->brushRotation));
m.scale(m_properties->scale, m_properties->scale);
for (quint32 i = 0; i < m_particlesCount; i++) {
// generate random angle
angle = randomSource->generateNormalized() * M_PI * 2;
// generate random length
if (m_properties->gaussian) {
length = randomSource->generateGaussian(0.0, 0.5);
}
else {
length = randomSource->generateNormalized();
}
if (m_shapeDynamicsProperties->enabled) {
// rotation
rotationZ = rotationAngle(randomSource);
if (m_shapeDynamicsProperties->followCursor) {
rotationZ = linearInterpolation(rotationZ, angle, m_shapeDynamicsProperties->followCursorWeigth);
}
if (m_shapeDynamicsProperties->followDrawingAngle) {
rotationZ = linearInterpolation(rotationZ, info.drawingAngle(), m_shapeDynamicsProperties->followDrawingAngleWeight);
}
//.........这里部分代码省略.........
示例3: paintLine
//.........这里部分代码省略.........
qreal distance;
QPoint positionInMask;
QPointF diff;
int size = m_points.size();
// MAIN LOOP
for (int i = 0; i < size; i++) {
diff = m_points.at(i) - mousePosition;
distance = diff.x() * diff.x() + diff.y() * diff.y();
// circle test
bool makeConnection = false;
if (m_sketchProperties.simpleMode) {
if (distance < thresholdDistance) {
makeConnection = true;
}
// mask test
}
else {
if (m_brushBoundingBox.contains(m_points.at(i))) {
positionInMask = (diff + m_hotSpot).toPoint();
uint pos = ((positionInMask.y() * w + positionInMask.x()) * m_maskDab->pixelSize());
if (pos < m_maskDab->allocatedPixels() * m_maskDab->pixelSize()) {
pixel = m_maskDab->data() + pos;
opacityU8 = m_maskDab->colorSpace()->opacityU8(pixel);
if (opacityU8 != 0) {
makeConnection = true;
}
}
}
}
if (!makeConnection) {
// check next point
continue;
}
if (m_sketchProperties.distanceDensity) {
probability = distance / density;
}
KisRandomSourceSP randomSource = pi2.randomSource();
// density check
if (randomSource->generateNormalized() >= probability) {
QPointF offsetPt = diff * currentOffsetScale;
if (m_sketchProperties.randomRGB) {
/**
* Since the order of calculation of function
* parameters is not defined by C++ standard, we
* should generate values in an external code snippet
* which has a definite order of execution.
*/
qreal r1 = randomSource->generateNormalized();
qreal r2 = randomSource->generateNormalized();
qreal r3 = randomSource->generateNormalized();
// some color transformation per line goes here
randomColor.setRgbF(r1 * painterColor.redF(),
r2 * painterColor.greenF(),
r3 * painterColor.blueF());
color.fromQColor(randomColor);
m_painter->setPaintColor(color);
}
// distance based opacity
quint8 opacity = OPACITY_OPAQUE_U8;
if (m_sketchProperties.distanceOpacity) {
opacity *= qRound((1.0 - (distance / thresholdDistance)));
}
if (m_sketchProperties.randomOpacity) {
opacity *= randomSource->generateNormalized();
}
m_painter->setOpacity(opacity);
if (m_sketchProperties.magnetify) {
drawConnection(mousePosition + offsetPt, m_points.at(i) - offsetPt, currentLineWidth);
}
else {
drawConnection(mousePosition + offsetPt, mousePosition - offsetPt, currentLineWidth);
}
}
}// end of MAIN LOOP
m_count++;
QRect rc = m_dab->extent();
quint8 origOpacity = m_opacityOption.apply(painter(), pi2);
painter()->bitBlt(rc.x(), rc.y(), m_dab, rc.x(), rc.y(), rc.width(), rc.height());
painter()->renderMirrorMask(rc, m_dab);
painter()->setOpacity(origOpacity);
}