Skip to content

Instantly share code, notes, and snippets.

@samueljackson92
Created November 29, 2016 11:34
Show Gist options
  • Save samueljackson92/746c3dec4f6c5ab25548ab3b5d65ff71 to your computer and use it in GitHub Desktop.
Save samueljackson92/746c3dec4f6c5ab25548ab3b5d65ff71 to your computer and use it in GitHub Desktop.
QPainterPath path;
std::sort(points.begin(), points.end(),
[](const QPointF& p1, const QPointF& p2) -> bool
{
return p1.x() < p2.x();
});
constexpr auto step = 100.0;
for (size_t i = 0; i < points.size()-1; ++i) {
auto x1 = points[i].x();
auto y1 = points[i].y();
auto x2 = points[i+1].x();
auto y2 = points[i+1].y();
auto diff = std::abs(x1 - x2);
for (int j = 0; j < step; ++j) {
auto mu = j / step;
auto mu2 = (1-cos(mu*M_PI))/2;
auto y = (y1*(1-mu2)+y2*mu2);
auto x = (diff / step) * j + x1;
QPointF pt(x, y);
poly.append(pt);
}
}
path.addPolygon(poly);
painter.drawPath(path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment