I was working on a Mandelbrot set at first, then added a Julia set to the same window. The problem is I don't know the formula for my exact situation. Also, the Julia set slid to the bottom-left side. The issue is that it's not taking into account the zoom factor and the x, y offsets, and (for some reason) only accounting the bottom left square like 50 by 100 pixels. Here's my code and formula:
fractal image with the julia set missplaced:
zx = ((mouse.x / 800.0 - 0.5) / (1 / mandelbrot.get_zoom_scale())) * 6 - mandelbrot.get_x_offset() - 3.5;
zy = ((mouse.y / 600.0 - 0.5) / (1 / mandelbrot.get_zoom_scale())) * 6 - mandelbrot.get_y_offset() - 2.5;
The constructor of the class that handles all the fractals has these parameters:
FractalBase<Derived>::FractalBase()
: max_iterations(300), basic_zoom_x(240.0f), basic_zoom_y(240.0f),
zoom_x(basic_zoom_x), zoom_y(basic_zoom_y),
x_offset(3.5f), y_offset(2.5f),
zoom_factor(1.0f), zoom_speed(0.1f),
pixels(new unsigned char[width * height * 4]), paletteSize(palette.size()),
zoom_scale(1.0f), width(400), height(300)
So, the main problem is that it miscalculates the zx
and zy
parameters, not including the zoom_factor
, and not accounting for the offsets. I tried a lot of different functions but just couldn't find the one that will actually work. I would like assistance with the formula.
so after a lot of trial and error and hours spent, here is the correct formula, so many hours spent on a simple formula, but it gave me so much dofamine when it started working
zx = -(mandelbrot.get_x_offset() - (mouse.x / mandelbrot.get_zoom_x()));
zy = -(mandelbrot.get_y_offset() - (mouse.y / mandelbrot.get_zoom_y()));