Stack Overflow Asked on November 22, 2021
If anyone’s had experience with this and can tell me where I’m going massively wrong that would be greatly appretiated.
So far I am doing the "Advanced C++ Programming" course on Udemy by John Purcel and I’m currently doing the fractal project close to the end of the entire course.
My main code that I have so far looks like:
#include <iostream>
#include <stdint.h>
#include <memory>
#include <math.h>
#include "Mandelbrot.h"
#include "Bitmap.h"
using namespace std;
using namespace graphics;
int main() {
int const WIDTH = 800;
int const HEIGHT = 600;
Bitmap bitmap(WIDTH, HEIGHT);
double min = 999999;
double max = -999999;
unique_ptr<int[]> histogram(new int[Mandelbrot::MAX_ITERATIONS] { }); //If you want to validate this, make a for loop that outputs the number of iterations of the histogram.
unique_ptr<int[]> fractal(new int[WIDTH * HEIGHT] { });
for (int yaxis = 0; yaxis < HEIGHT; yaxis++) {
for (int xaxis = 0; xaxis < WIDTH; xaxis++) {
double xFractal { (xaxis - WIDTH / 2 - 200) * 2.0 / WIDTH };
double yFractal { (yaxis - HEIGHT / 2) * 2.0 / HEIGHT };
int iterations = Mandelbrot::getIterations(xFractal, yFractal);
fractal[yaxis * WIDTH + xaxis] = iterations;
if (iterations == Mandelbrot::MAX_ITERATIONS) {
histogram[iterations]++;
}
}
}
int total = 0;
for (int i = 0; i < Mandelbrot::MAX_ITERATIONS; i++) {
total += histogram[i];
}
for (int yaxis = 0; yaxis < HEIGHT; yaxis++) {
for (int xaxis = 0; xaxis < WIDTH; xaxis++) {
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
int iterations = fractal[yaxis * WIDTH * xaxis];
if (iterations != Mandelbrot::MAX_ITERATIONS) {
double hue = 0.0;
for (int i = 0; i <= iterations; i++) {
hue += ((double) histogram[i]) / total;
}
green = pow(255, hue);
}
bitmap.setPixel(xaxis, yaxis, red, green, blue);
}
}
bitmap.write("test.bmp");
cout << "File has been Built." << endl;
return 0;
}
What should happen after building and running this is that the cout statement should be printed in the terminal and I should get the "test.bmp" file appearing in the project file. But every time that I’m running this, the program terminates. For no apparent reason. All the other header files and cpp files have been left alone for quite some time since I was able to follow the course and get them working 100% of the time but suddenly it doesn’t want to.
When building I get 2 warnings for unused variables but that shouldn’t be of worry. The MAX_ITERATIONS number can be anything. I’ve tried 1000, 2000, 4000 and even 100. But after all the iterations have been complete the terminal…well…terminates and then nothing is output.
I am using the Eclipse IDE, GNU Compiler and I do have the flag set so I’m able to use C++11 code.
Hopefully this is enough information.
Hope to hear back soon from any of you.
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP