Mandlebrot Is Only a Circle, whats the problem?

hi, its 2:24 am, and im sad and tired, i gave up, here's code (I use Qt for drawing)

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"; }
}


i know its so stupid and dirty but anyway

here are my .h vars !

1
2
3
4
5
6
7
8
9
10
11
private:
        //Variables
    double MinRe = -2.0;
    double MaxRe = 2.0;
    double MinIm = -2.0;
    double MaxIm = MinIm+(MaxRe-MinRe)*ImageHeight/ImageWidth;
    double Re_factor = (MaxRe-MinRe)/(ImageWidth-1);
    double Im_factor = (MaxIm-MinIm)/(ImageHeight-1);
    int MaxIterations = 100;
    Complex real;
    QImage *Result;


it gives me a circle, not a Mandelbrot but circle, a perfectly shaped circle !
Last edited on
line 56: Try using either qRgb(0,0,255) or QColor(Qt::blue).rgb()

From the Qt docs:
If the image's format is either monochrome or 8-bit, the given index_or_rgb value must be an index in the image's color table, otherwise the parameter must be a QRgb value.
thanks norm, that fixed the color,

but my main thing is that Cricle in middle, Why is that a circle, i want a mandelbrot set, i dont want cricle

I want mandelbort ! :D
Looks like you need to add a couple of terms to your equations in SqrtComplex():
1
2
    result.x = a.x*a.x - a.y*a.y + b.x;
    result.y = 2*a.x*a.y + b.y;

Then in isMandle() pass Buffer as the second parameter: a = SqrtComplex(a, Buffer);
thanks norm, but today while waiting for answer i decided to remake the app and it worked this time :D i will try what you said on my old code (still have it)

it looks so cool :P

edit: it works yay ! :D thanks its awesome :)
Last edited on
Topic archived. No new replies allowed.