#include "Painty.h" #include Painty::Painty() { } void Painty::setXY(int idx, float x, float y) { if (points.size() < idx+1) {points.resize(idx+1);} points[idx] = QPointF(x,y); emit update(); } void Painty::setSigma(double s) { this->sigma = s; emit update(); } #include void Painty::paint(QPainter* p) { p->setPen(Qt::blue); p->drawLine(0,0,100,100); const double s = sigma; static QImage img(width(), height(), QImage::Format_ARGB32); std::vector vec; if (points.size() < 3) {return;} double max = 0; for (int y = 0; y < height(); ++y) { for (int x = 0; x < width(); ++x) { double sum = 0; for (const QPointF p : points) { const double dx = x-p.x(); const double dy = y-p.y(); const double dist = std::sqrt(dx*dx+dy*dy); sum += 1.0 / std::sqrt(2*M_PI*s*s) * std::exp(- (dist*dist)/(2*s*s) ); } vec.push_back(sum); if (sum > max) {max = sum;} } } for (size_t idx = 0; idx < vec.size(); ++idx) { int x = idx % (int) width(); int y = idx / width(); double h = 1.0 - vec[idx]/max; QColor c = QColor::fromHsvF(h, 0.5, 1); img.setPixelColor(x, y, c); } p->drawImage(0, 0, img); }