# Help visualizing the Mandelbrot set

**URL:** <https://discourse.processing.org/t/help-visualizing-the-mandelbrot-set/35974>\
**Category:** Coding Questions\
**Created:** [March 28, 2022, 6:15am UTC](https://discourse.processing.org/t/help-visualizing-the-mandelbrot-set/35974 "2022-03-28T06:15:29Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [March 28, 2022, 12:46pm UTC](https://discourse.processing.org/t/help-visualizing-the-mandelbrot-set/35974/4 "2022-03-28T12:46:21Z")

</div>

Are you essentially using the algorithm that is presented in pseudocode at [Wikipedia: Mandelbrot set: Computer drawings](https://en.wikipedia.org/wiki/Mandelbrot_set#Computer_drawings)?

The following is my take on that in p5.js:

```auto
// 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:

 ![mandelbrot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4c2bbbe798f5fe4b71137bdba5c9d78db5b6dbca.png)

_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.

---

_[View the full topic](https://discourse.processing.org/t/help-visualizing-the-mandelbrot-set/35974)._
