Hello, i am trying to code the mandelbrot/julia set challenge from codingtrain and now i am stuck. I wanted to split the screen into two sides. On the left side it should show the julia set and on the right side it should show the mandelbrot set. The thing is that i wanted that you can hover over the mandelbrot set on the right sied and see the corresponding julia set on the left side change with the movement of the mouse. Right now i can hover over the julia set on the left side and everything works perfect but when i hover over the mandelbrot on the right side it displays the julia set wrong ontop of it. How can i fix that?
public void settings() {
fullScreen();
}
public void draw() {
background(0);
loadPixels();
int maxiterations=100;
float ca=map(mouseX, 0, width/2, -2, 2);
float cb=map(mouseY, 0, height, 2, -2);
//Mandelbrot set
for (int x=width/2; x<width; x++) {
for (int y=0; y<height; y++) {
float a=map(x, width/2, width, -2, 2);
float b=map(y, 0, height, 2, -2);
int n=0;
while (n<maxiterations) {
float aa=a*a;
float bb=b*b;
float ab2=2*(a*b);
a=aa-bb+a;
b=ab2+b;
if (aa+bb>4) {
break;
}
n++;
}
if (n == maxiterations) {
pixels[x+y*width] = color(0);
} else {
float norm = map(n, 0, maxiterations, 0, 1);
pixels[x+y*width] = color(map(sqrt(norm), 0, 1, 0, 255));
}
}
}
//Julia set
if (mouseX<width/2) {
for (int x=0; x<width/2; x++) {
for (int y=0; y<height; y++) {
float a=map(x, 0, width/2, -2, 2);
float b=map(y, 0, height, 2, -2);
int n=0;
while (n<maxiterations) {
float aa=a*a;
float bb=b*b;
float ab2=2*(a*b);
a=aa-bb+ca;
b=ab2+cb;
if (aa+bb>4) {
break;
}
n++;
}
if (n == maxiterations) {
pixels[x+y*width] = color(0);
} else {
float norm = map(n, 0, maxiterations, 0, 1);
pixels[x+y*width] = color(map(sqrt(norm), 0, 1, 0, 255));
}
}
}
} else {
for (int x=width/2; x<width; x++) {
for (int y=0; y<height; y++) {
float a=map(x, width/2, width, -2, 2);
float b=map(y, 0, height, 2, -2);
int n=0;
while (n<maxiterations) {
float aa=a*a;
float bb=b*b;
float ab2=2*(a*b);
a=aa-bb+ca;
b=ab2+cb;
if (aa+bb>4) {
break;
}
n++;
}
if (n == maxiterations) {
pixels[x+y*width] = color(0);
} else {
float norm = map(n, 0, maxiterations, 0, 1);
pixels[x+y*width] = color(map(sqrt(norm), 0, 1, 0, 255));
}
}
}
}
updatePixels();
}