Skip to content

Commit 3663e34

Browse files
committed
.
1 parent 555638e commit 3663e34

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

Fractal Images/Mandelbrot.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include<complex>
2-
#include "Mandelbrot.h"
2+
#include"Mandelbrot.h"
33

44
using namespace std;
55

@@ -16,9 +16,23 @@ namespace fractal{
1616

1717
int Mandelbrot::getIteration(double x, double y) {
1818

19+
complex<double> z = 0;
20+
complex<double> c(x, y);
21+
22+
int iterations = 0;
1923

24+
while (iterations < MAX_ITERATIONS) {
25+
z = z * z + c;
26+
27+
if (abs(z) > 2) {
28+
break;
29+
}
30+
31+
iterations++;
32+
33+
}
2034

21-
return 0;
35+
return iterations;
2236
}
2337

2438
}

Fractal Images/main.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include<iostream>
55
#include"Bitmap.h"
6+
#include"Mandelbrot.h"
7+
#include<cstdint>
68

79
using namespace std;
810
using namespace fractal;
@@ -24,8 +26,16 @@ int main() {
2426
double xFractal{ (x - WIDTH/2) * (2.0/WIDTH) };
2527
double yFractal{ (y - HEIGHT / 2) * (2.0 / HEIGHT) };
2628

27-
if (xFractal < min) min = xFractal;
28-
if (xFractal > max) max = xFractal;
29+
int iterations = Mandelbrot::getIteration(xFractal, yFractal);
30+
31+
uint8_t red = (uint8_t)(256 * (double)iterations / Mandelbrot::MAX_ITERATIONS);
32+
33+
34+
35+
bitmap.setPixel(x, y, red, red, red);
36+
37+
if (red < min) min = red;
38+
if (red > max) max = red;
2939

3040
}
3141
}

test.bmp

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)