1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include "mainwindow.h"
#include <QDebug>
#include <cmath>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
Result = new QImage(QSize(ImageWidth,ImageHeight),QImage::Format_RGB32);
Result->fill(Qt::white);
Complex Pixel;
for(int y=0;y<=ImageHeight;y++){
Pixel.y = MaxIm - y*Im_factor;
real.y = y;
for(int x=0;x<=ImageWidth;x++){
Pixel.x = MaxRe - x*Re_factor;
real.x = x;
IsMandle(Pixel, 100);
}
}
//END
}
Complex MainWindow::SqrtComplex(Complex a, Complex b)
{
Complex result;
result.x = a.x*a.x - a.y*a.y;
result.y = 2*a.x*a.y;
return result;
}
void MainWindow::paintEvent(QPaintEvent *Event)
{
QPainter painter(this);
painter.drawImage(0,0,*Result);
}
double MainWindow::map(double x, double in_min, double in_max, double out_min, double out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void MainWindow::IsMandle(Complex Buffer, int max)
{
Complex a = Buffer;
bool isInside = true;
for(int n=0; n<MaxIterations;n++)
{
if((a.x*a.x + a.y*a.y) > 4)
{
isInside = false;
break;
}
a = SqrtComplex(a,a);
}
if(isInside) { Result->setPixel(real.x, real.y, Qt::blue);qDebug() << " test"; }
}
|