Julia Sets


Although they look complicated, the method of generating Julia Sets is actually pretty simple.

We begin with the concept of a complex number. Remember that a complex number is one that has a real part and an imaginary part, typically written in the form a + b*i, where a is the real part and b is the imaginary part.

Now let's look at a two-dimensional coordinate system, where real numbers (a) are along the x-axis and imaginary numbers (b) are along the y-axis. Thus, every point in this plane is a complex number with an x-value of a and a y-value of b. Let's say that both the x and y-axes go from -2 to 2. 

Okay, now let's take this coordinate system and make it a matrix. Basically, we are creating bins at a desired resolution to capture the two-dimensional coordinate system we just discussed. For example, if we set our binsize to be 1 (or our resolution to be 5), we'd get the matrix pictured below. From a practical perspective, we'll want a much greater resolution, say 500, for computing Julia Sets. 

Okay, so how does this basic math allow us to create interesting geometric works of art?

The basic Julia Set works like this: for each point in the matrix we just defined, you take the entry, square it, and add some number C. You repeat this process of squaring and adding C for a given number of iterations.

After each iteration, you essentially ask if the value diverges (simplistically, if the value is >10 or something like that). If it does, you note the index at which the divergence happened in an output matrix. After you finish iterating, you can view the output matrix as a heatmap. 

So how does this create complex patterns? Well, it turns out that simply varying the value of C is sufficient to create a huge array of interesting designs! Try running the code below and seeing what kind of designs you can create!


function juliaSet(r,w,inc,repeatColors)
% Draws a julia set with iterations r and resolution w. Inc determines
% the factor c you add to the julia set at each iteration. repeatColors
% should be set to 1 if you want the colors to cycle back through black
% partway through the drawing

    % Create the real and imaginary parts of each number in a temporary
    % variable
    for i=1:w
    % Set the initial values based on their real and imaginary components
    for i=1:w
        for j=1:w
    % Initialize the output

    % For each iteration, cycle through data and perform the desired
    % computatation
    for i=1:r 
        for m=1:w
            for k=1:w
                % Essentially, set output(m,k) equal to the current
                % iteration if the series diverges
                if abs(values(m,k))>10 && output(m,k)==0
    % Cycle the colors back through zero if repeatColors is set to 1
    if repeatColors==1
      for m=1:w
          for k=1:w
    % Create the figure
    axis off


Note that there are several input values for the juliaSet function. One thing you can change is the resolution. Here is a single juliaSet example at three different resolution levels. 

Another parameter you can change is the number of iterations. The greater the number of iterations, the more detailed your final image can be. For some Julia Sets you don't need a large number of iterations (say, 15 is sufficient), but for others you need to iterate hundreds of times to get the full structure. Here's one example of a Julia Set computed with different numbers of iterations. 


Here are some examples of Julia Sets!

Further Exploration

Note that there is no particular reason why you need to use z^2 + C as the way to compute your Julia Set; this is simply the typical way it is done. Try using other functions here, instead, and see how that changes the pictures you create. This can be achieved by altering the line of code that appears blue in the program section above. 

Here's one example: