Are you essentially using the algorithm that is presented in pseudocode at Wikipedia: Mandelbrot set: Computer drawings?
The following is my take on that in p5.js:
// algorithm from https://en.wikipedia.org/wiki/Mandelbrot_set#Computer_drawings
function setup() {
createCanvas(400, 400);
noLoop();
background(255);
}
function draw() {
for (let px = 0; px < width; px += 1) {
for (let py = 0; py < height; py += 1) {
let x0 = map(px, 0, width, -2.0, 0.47);
let y0 = map(py, 0, height, -1.12, 1.12);
let x = 0.0;
let y = 0.0;
let iteration = 0;
let max_iteration = 255;
while ((x * x + y * y <= 2 * 2) && (iteration < max_iteration)) {
let xtemp = x * x - y * y + x0;
y = 2 * x * y + y0;
x = xtemp;
iteration = iteration + 1;
}
stroke(iteration);
point(px, py);
}
}
}
Image:
EDIT (March 28, 2022):
Is there a particular section of the Wikipedia article that served as a basis for the criteria used in your check_if_in_mandlebrot_set
function? If you provide a link to that section, we can compare it to your function and experiment with it.