double Perlin::noise3(double x, double y, double z) { int fX, fY, fZ; double dX, dY, dZ; double u, v, w; int a, aa, ab, b, ba, bb; // Determine the bounds of the unit cube this point is inside fX = ((int)x) % _size; fY = ((int)y) % _size; fZ = ((int)z) % _size; // Determine the difference of this point from the origin of the unit cube dX = x - (int)x; dY = y - (int)y; dZ = z - (int)z; // Determine fade values for each dimension using our location inside the unit cube u = fade(dX); v = fade(dY); w = fade(dZ); // Find pseudo-random gradients by operating on the dimensional indices of the unit cube // The important part here is that these pseudo-random gradients are always the same for a given point a = _p[fX] + fY; aa = _p[a] + fZ; ab = _p[a + 1] + fZ; b = _p[fX + 1] + fY; ba = _p[b] + fZ; bb = _p[b+1] + fZ; // Here we take the gradients at each of the 8 corners of the unit cube and linearly interpolate for each dimension (first x, then y, then z) using the fade values return lerp(w, lerp(v, lerp(u, gradient3(_p[aa], dX, dY, dZ ), gradient3(_p[ba], dX-1, dY, dZ ) ), lerp(u, gradient3(_p[ab], dX, dY-1, dZ ), gradient3(_p[bb], dX-1, dY-1, dZ ) ) ), lerp(v, lerp(u, gradient3(_p[aa+1], dX, dY, dZ-1), gradient3(_p[ba+1], dX-1, dY, dZ-1) ), lerp(u, gradient3(_p[ab+1], dX, dY-1, dZ-1), gradient3(_p[bb+1], dX-1, dY-1, dZ-1) ) ) ); }
void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->setPen(Qt::NoPen); QPolygonF polygon; QLinearGradient gradient1(QPointF(A1.x(), 0), QPointF(A2.x(), 0)); gradient1.setColorAt(0, edgeFillColor()); gradient1.setColorAt(1, middleFillColor()); painter->setBrush(gradient1); polygon << A1 << A2 << B2 << B1; painter->drawPolygon(polygon); polygon.clear(); QLinearGradient gradient2(QPointF(0, B1.y()), QPointF(0, B2.y())); gradient2.setColorAt(0, edgeFillColor()); gradient2.setColorAt(1, middleFillColor()); painter->setBrush(gradient2); polygon << B1 << B2 << C2 << C1; painter->drawPolygon(polygon); polygon.clear(); QLinearGradient gradient3(CC, C2); gradient3.setColorAt(0, edgeFillColor()); gradient3.setColorAt(1, middleFillColor()); painter->setBrush(gradient3); polygon << C1 << C2 << A2 << A1; painter->drawPolygon(polygon); polygon.clear(); painter->setBrush(Qt::NoBrush); painter->setPen(drawColor()); polygon << A1 << B1 << C1; painter->drawPolygon(polygon); polygon.clear(); polygon << A2 << B2 << C2; painter->drawPolygon(polygon); paintGraduations(painter); mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); QTransform antiScaleTransform; antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio); mCloseSvgItem->setTransform(antiScaleTransform); mHFlipSvgItem->setTransform(antiScaleTransform); mVFlipSvgItem->setTransform(antiScaleTransform); mRotateSvgItem->setTransform(antiScaleTransform); mCloseSvgItem->setPos(closeButtonRect().topLeft()); mHFlipSvgItem->setPos(hFlipRect().topLeft()); mVFlipSvgItem->setPos(vFlipRect().topLeft()); mRotateSvgItem->setPos(rotateRect().topLeft()); if (mShowButtons || mResizing1 || mResizing2) { painter->setBrush(QColor(0, 0, 0)); if (mShowButtons || mResizing1) painter->drawPolygon(resize1Polygon()); if (mShowButtons || mResizing2) painter->drawPolygon(resize2Polygon()); } }