Hello, i wanted to do the mandelbrot/julia set challenge from codingtrain that these two fractals are in one window and you can hover over the mandelbrot set and see the corresponding julia set next to it change (like he said in the video but sadly never did as far as i know). I used an own approach to map the coordinates with map(); and now i wanted to have the mandelbrot set on the left side and the julia set on the right side. But somehow i cant figure out how to change the coordinates of the julia set to be shown at the right side. (Also i know the mandelbrot set isn’t shown/ calculated right but that isnt so bad right now for me, i care more about splitting these two)
Here is my code so far:
public void settings() {
fullScreen();
}
public void draw() {
background(255);
loadPixels();
int maxit=100;
float ca=map(mouseX, 0, width/2, -2, 2);
float cb=map(mouseY, 0, height, -2, 2);
//Mandelbrot set
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<maxit) {
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 == maxit) {
pixels[x+y*width] = color(0);
} else {
float norm = map(n, 0, maxit, 0, 1);
pixels[x+y*width] = color(map(sqrt(norm), 0, 1, 0, 255));
}
}
}
//Julia set
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<maxit) {
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 == maxit) {
pixels[x+y*width] = color(0);
} else {
float norm = map(n, 0, maxit, 0, 1);
pixels[x+y*width] = color(map(sqrt(norm), 0, 1, 0, 255));
}
}
}
updatePixels();
}