This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrotmodel.h
73 lines (61 loc) · 1.84 KB
/
mandelbrotmodel.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef MANDELBROTMODEL_H
#define MANDELBROTMODEL_H
#include <QObject>
#include <Qrgb>
#include <QDebug>
#include <complex>
#include <queue>
#include <cmath>
#include "fractaloptions.h"
#include "ColoringMode/coloringmode.h"
#include "ColoringMode/basiccoloringmode.h"
#include "ColoringMode/blackwhitecoloringmode.h"
#include "ColoringMode/grayscalecoloringmode.h"
#include "ColoringMode/smoothcoloringmode.h"
using Complex = std::complex<double>;
template<typename T> class ComplexPlane
{
public:
T minX, minY, maxX, maxY;
public:
ComplexPlane():minX(0), minY(0), maxX(0), maxY(0){}
ComplexPlane(T minX, T minY, T maxX, T maxY):minX(minX), minY(minY), maxX(maxX), maxY(maxY){}
T width(){ return maxX - minX; }
T height(){ return maxY - minY; }
inline void zoomTo(T x, T y, int zoomAmmount)
{
T halfWidth = width() / (zoomAmmount*2);
T halfHeight = height() / (zoomAmmount*2);
minX = x - halfWidth;
maxX = x + halfHeight;
minY = y - halfWidth;
maxY = y + halfHeight;
}
};
class MandelbrotModel : public QObject
{
Q_OBJECT
public:
MandelbrotModel();
void generate();
void zoomIn(float x, float y);
void onResize();
float progress() const { return _progress; }
void setProgress(float progress);
ColoringMode* coloringMode() const { return _coloringMode; }
void setColoringMode(ColoringMode* coloringMode);
FractalOptions* options;
std::vector<ColoringMode*> coloringModes;
ComplexPlane<double> defaultViewport;
ComplexPlane<double> viewport;
QRgb* pixels;
signals:
void progressChanged(float newProgress);
private:
float _progress;
ColoringMode* _coloringMode;
Complex transformToComplexPlane(int x, int y);
void workOnTasks(std::queue<int>* tasks);
void generatePixelRow(int py);
};
#endif // MANDELBROTMODEL_H