Julia Sets are another set of images that can be created by iterating a dynamic equation. If you want all of the ugly mathematics, see the Wikipedia entry on Julia Set. If you take the time to understand all of it, you are a better person than me. For a better explanation, I suggest seeing Julia and Mandelbrot Sets, and Understanding Julia and Mandelbrot Sets.

That’s all fine and good, but how do we create a Julia Set mathematically? Certainly not by attempting to follow the Wikipedia entry! For a Julia Set that corresponds to the Mandelbrot set, we use the same equation, but generate the plot for a different plane. Remember the equation:

**z**_{n+1} = z_{n}^{p} + c

For the Mandelbrot Set, **z**_{0} = 0 + 0i and **p = 2**. We set **c** to be each point in the section of the complex plane that we were looking at. For the Julia Set, we set **c** to a single value in the complex plane, then set **z**_{0} to each point in the section of the complex plane we are looking at, and iterate. For every point, **c**, inside the Mandelbrot Set, there is a connected Julia Set; for each point outside of the Mandelbrot Set, the Julia Set is disconnected.

The most interesting images are generated from points outside the Mandelbrot Set or just inside it. This image is generated for a point near the centre of the secondary bulb:

and this is image is generated for a point inside one of the small bulbs off the main bulb:

This image is generated for a point just outside the Mandelbrot set and slightly about the x-axis:

Here are a couple of images created from the tendrils of the Mandelbrot Set:

and finally, an image from a short distance outside the Mandelbrot Set:

Each value, **c**, produces a different image. To generate an image for a point in the Mandelbrot Set using the ChaosExplorer program, place the mouse cursor over the point, click the right mouse button, and select the *Julia Set* menu item. The image is generated in a panel in a new notebook tab. You can also zoom in on the image by selecting an area to zoom, and then selecting the *Draw From Selection* menu item. The source code and a wiki are available on GitHub.

This is the fragment shader for generating these Julia Sets:

std::string fragmentSource =
"#version 330 core\n"
"uniform vec2 c;"
"uniform vec2 p;"
"uniform vec2 ul;"
"uniform vec2 lr;"
"uniform vec2 viewDimensions;"
"uniform vec4 color[50];"
"out vec4 OutColor;"
"vec2 iPower(vec2 vec, vec2 p)"
"{"
" float r = sqrt(vec.x * vec.x + vec.y * vec.y);"
" if(r == 0.0f) {"
" return vec2(0.0f, 0.0f);"
" }"
" float theta = vec.y != 0 ? atan(vec.y, vec.x) : (vec.x < 0 ? 3.14159265f : 0.0f);"
" float imt = -p.y * theta;"
" float rpowr = pow(r, p.x);"
" float angle = p.x * theta + p.y * log(r);"
" vec2 powr;"
" powr.x = rpowr * exp(imt) * cos(angle);"
" powr.y = rpowr * exp(imt) * sin(angle);"
" return powr;"
"}"
""
"void main()"
"{"
" float x = ul.x + (lr.x - ul.x) * gl_FragCoord.x / (viewDimensions.x - 1);"
" float y = lr.y + (ul.y - lr.y) * gl_FragCoord.y / (viewDimensions.y - 1);"
" vec2 z = vec2(x, y);"
" int i = 0;"
" while(z.x * z.x + z.y * z.y < 4.0f && i < 200) {"
" z = iPower(z, p) + c;"
" ++i;"
" }"
" OutColor = i == 200 ? vec4(0.0f, 0.0f, 0.0f, 1.0f) : "
" color[i%50 - 1];"
"}";

If you compare this to the fragment shader for the Multibrot Sets included in the post Mandelbrot Set, you will see few changes.

## Summary

This post discussed Julia Sets and showed images of some Julia Sets generated from several points inside and outside the Mandelbrot Set. The fragment shader that is used to generate the images was also shown.