the Julia Set with Base Tools in R

4 minute read

I will let you in a secret, most of the popular fractals you see out there, are all part of and were derived from the Mandelbrot Set. They all share same equation F= {x^2 + c| c is a constant, x is an iterated number}. The variability in design comes from whether we are going to keep constant or substitute it with a new value per iteration.

Again, if you would like to see my source code, you can find it here!

So with that little secret spilt, let me introduce you with one of the popular fractals from the Mandelbrot family. It is called the Julia Set. I think “Sets” is perhaps the best term because these are a series of fractals which were discovered by Dr. Gaston Julia.

To begin with, let’s talk about how Julia Sets differ from the Mandelbrot Set. For Mandelbrot Set we substitute Cs in equation F= {x^2 + c} for the numbers in the complex plane. Then each result replaces the x in each iteration. If we sense that the number is keep growing, our chosen point is not considered as a part of the set. And then that point we picked gets coloured depending on how fast it grows. A number that is bounded and doesn’t grow on the other hand, is considered part of the set hence they get coloured black. We repeatedly do it letting every point take a chance on becoming that c and with that, a shape of a Mandelbrot is born.

Now the Julia sets are made the same ways, but instead substituting all Cs with each number on the complex plane, we only substitute it with the number we began with, Z0 = n. In other words, in Julia we keep Cs bounded at each iteration and change Z0 at each iteration with the number + complex (meaning that bounded c) for next iterations. And we again repeatedly do this letting each point take a stab on becoming Z0.

See through my R code here-

# Complex parameter, connected to coordinate of the Mandelbrot set in a complex plane
a <- -0.4
b <- -0.6

#coloring code....

#fixed numbers of steps
steps <- seq(fixed_limits[1], fixed_limits[2], by= 0.01)

#We keep each point in the array/matrix
points_matrix <- array(0, dim= c(length(steps) * length(steps), 3))

a1 <- 0

for(x in steps) {
  for(y in steps) {
    n <- 0
    distance <- 0
    # Copy original x and y
    x1 <- x
    y1 <- y 
      
      #This distance limit specific
      while(n < max_iteration & distance<4) {
        newx <- x1^2 - y1^2 + a
        newy <- 2 * x1 * y1 + b
        distance <- newx^2 + newy^2
        x1 <- newx
        y1 <- newy
        n <- n+1
      }
    
    if(distance < 4){
      #We pick the color for the number not in the step
      pick_color <- 24
    }
    else{
      #We pick the color for the number not in the step
      pick_color <- n*10 
    }
    
    a1 <- a1 + 1 #Next number
    points_matrix[a1, ]= c(x,y, pick_color)
    
  }
}

# plot() codes....

As a result, we get something like below with the constant Zn= x^2 +(-0.4+(-0.6i)) -

The great thing about Julia Set fractal is that it varies based on different values of Cs. For example, take a look at these; if I pick Zn= x^2 +(0+0.8i), then the result is this-

Similarly, if I pick Zn= x^2 +(-0.34+ (-0.9i)), we would get something like this-

And last but not the least, this is the result for Zn= x^2 +(0.355+ 0.355i) -

So, with all these variations we can see that by choosing different values of c, vast varieties of fractals can be made. And every one of these fractals is considered to be a Julia Set. More on, how does the Julia Sets relate to Mandelbrot Set? If you’ve read my post on the Mandelbrot Set, you would see that each endpoint of black region is a different value of c and essentially, that means that we can take those different endpoints and use them to generate a new Julia Set.

What I am trying to say is, the very shape (and EVERY shape) of Julia set is depicted in the Mandelbrot Set in some ways in Mandelbrot’s endpoint. Both are part of the same family, and Julia sets are inter-related to Mandelbrot Set even though they both look different. Metaphorically, this phenomena is akin to nature of the reality….maybe things are more interconnected than they may appear to be, smaller things being intertwined what fundamentally exists as a larger hole.

That’s all for this post, and for the visual people who want to see how Julia gets form around Mandelbrot, please check out the link here.

And if you want to learn/explore more about this fractal or other fractals in this set, please go here. This site, in particular, has pretty much all of the fractals from this set. And obviously, they all look better than what I have done. Nonetheless, pretty happy with my result too.

NOTE: Thank you very much for reading! If you discover any mistakes or want to offer any feedback, please feel free to email me.