コード例 #1
0
void SprayBrush::paintRectangle(KisPainter& painter, qreal x, qreal y, int width, int height, qreal angle, int steps) {
    QVector <QPointF> points;
    QTransform transform;

    qreal halfWidth = width / 2.0;
    qreal halfHeight = height / 2.0;
    qreal tx, ty;

    transform.reset();
    transform.rotateRadians( angle );
    // top left
    transform.map( - halfWidth,  - halfHeight, &tx, &ty);
    points.append(QPointF(tx + x,ty + y));
    // top right
    transform.map( + halfWidth,  - halfHeight, &tx, &ty);
    points.append(QPointF(tx + x,ty + y));
    // bottom right
    transform.map( + halfWidth,  + halfHeight, &tx, &ty);
    points.append(QPointF(tx + x,ty + y));
    // botom left 
    transform.map( - halfWidth,  + halfHeight, &tx, &ty);
    points.append(QPointF(tx + x,ty + y));


    painter.setOpacity( int( ( 255 * drand48() ) + 0.5 ) );
    painter.setFillStyle(KisPainter::FillStyleForegroundColor);
    painter.paintPolygon( points );

}
コード例 #2
0
void SprayBrush::paintEllipse(KisPainter& painter, qreal x, qreal y, int a, int b, qreal angle, int steps) {
    QVector <QPointF> points;
    qreal beta = -angle;
    qreal sinbeta = sin(beta);
    qreal cosbeta = cos(beta);

    for (int i = 0; i < 360; i += 360.0 / steps)
    {
        qreal alpha = i * (M_PI / 180) ;
        qreal sinalpha = sin(alpha);
        qreal cosalpha = cos(alpha);
 
        qreal X = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta);
        qreal Y = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta);
 
        points.append( QPointF(X, Y) );
   }
    painter.setOpacity( int( ( 255 * drand48() ) + 0.5 ) );
    painter.setFillStyle(KisPainter::FillStyleForegroundColor);
    painter.paintPolygon( points );
}
コード例 #3
0
void SprayBrush::paintCircle(KisPainter& painter, qreal x, qreal y, int radius, int steps) {
    QVector<QPointF> points;
    // circle x, circle y
    qreal cx, cy;

    qreal length = 2.0 * M_PI;
    qreal step = 1.0 / steps;
    for (int i = 0; i < steps; i++){
        cx = cos(i * step * length);
        cy = sin(i * step * length);

        cx *= radius;
        cy *= radius;

        cx += x;
        cy += y;

        points.append( QPointF(cx, cy) );
    }
    painter.setOpacity( qRound(  OPACITY_OPAQUE * drand48()  ) );
    painter.setFillStyle( KisPainter::FillStyleForegroundColor );
    painter.paintPolygon( points );
}