Skip to content

Commit 1ff84c7

Browse files
committed
Update main.cpp
1 parent 772557a commit 1ff84c7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Fractal Images/main.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main() {
2222
double min = 99999;
2323
double max = -99999;
2424

25-
unique_ptr<int[]> histogram(new int[Mandelbrot::MAX_ITERATIONS + 1]());
25+
unique_ptr<int[]> histogram(new int[Mandelbrot::MAX_ITERATIONS]());
2626

2727
for (int y = 0; y < HEIGHT; y++) {
2828
for (int x = 0; x < WIDTH; x++) {
@@ -31,8 +31,13 @@ int main() {
3131

3232
int iterations = Mandelbrot::getIteration(xFractal, yFractal);
3333

34-
histogram[iterations]++;
34+
35+
if (iterations != Mandelbrot::MAX_ITERATIONS) {
36+
37+
histogram[iterations]++;
38+
}
3539

40+
3641
uint8_t color = (uint8_t)(256 * (double)iterations / Mandelbrot::MAX_ITERATIONS);
3742

3843
color = color * color * color; // it will range from 0 to 255 because uint8_t has the range from 0 to 255 only
@@ -48,7 +53,7 @@ int main() {
4853
cout << endl;
4954

5055
int count = 0;
51-
for (int i = 0; i <= Mandelbrot::MAX_ITERATIONS; i++) {
56+
for (int i = 0; i < Mandelbrot::MAX_ITERATIONS; i++) {
5257
cout << histogram[i] << " " << flush;
5358
count += histogram[i];
5459
}

0 commit comments

Comments
 (0)