How are Mandelbrot Animations Made?

401 Views Asked by At

I have always been interested in learning about how computers are able to animate the "Mandelbrot Set" (https://en.wikipedia.org/wiki/Mandelbrot_set).

I tried to learn about how pictures of the Mandelbrot Set are made , it seems like that you choose different values of "x" and see if they meet a certain criteria (which decides if a given value of "x" belongs to the Mandelbrot Set) - if this criteria is met for a certain value of "x", that value of "x" is plotted: In the end, all values of "x" that met this criteria are plotted.

I found this website (https://www.dandelbrot.com/post/the-mandelbrot-set-in-r/) that shows how to create Mandelbrot Set (R Code):

mandelbrot_generator <- function(
    p = 2, 
    q = 1,
    xmin = -2.1, # minimum x value
    xmax = 0.8,  # maximum x value
    nx = 500, 
    ymin = -1.3, # minimum y value
    ymax = 1.3,  # maximum y value
    ny = 500,
    n = 100, 
    showplot = TRUE, # If TRUE then display image,
    showvals = FALSE,
    cols = colorRampPalette(c("black","cyan","cyan3","black"))(11)) 
{
    
# variables
x <- seq(xmin, xmax, length.out=nx)
y <- seq(ymin, ymax, length.out=ny)
c <- outer(x,y*1i,FUN="+")
z <- matrix(0.0, nrow=length(x), ncol=length(y))
k <- matrix(0.0, nrow=length(x), ncol=length(y))

for (rep in 1:n) { 
    index <- which(Mod(z) < 2)
    z[index] <- z[index]^p + c[index]*q
    k[index] <- k[index] + 1
}

if (showplot==TRUE) { image(x,y,k,col=cols, xlab="Re(c)", ylab="Im(c)")}
if (showvals==TRUE) {return(k)}

}

Here is the plot:

mandelbrot_generator(p=2, q=1)

enter image description here

Does anyone know how to make an "animation" using the above code, so that it looks like this?

(https://en.wikipedia.org/wiki/Mandelbrot_set#/media/File:Mandelbrot_sequence_new.gif)

I always wondered : how are these animations made? I understand that a single picture of the Mandelbrot Set can be made, but how do these "zooming" animations work? Is this simply done by changing the "axis" (i.e. scale) of the picture?

The above picture is made from x = (-2.1, 0.8) and y = (-1.3, 1.3) - my understanding is that if we wanted to make a "zooming animation", we would "shrink" these ranges (i.e. make more increments between numbers as the animation frames go on) at each frame (and then find out which points at each frame are in the Mandlebrot Set) ?

For example:

  • Frame 1: x = (-2.1, 0.8) and y = (-1.3, 1.3)
  • Frame 2 : x = (-1.9, 0.6) and y = (-1.1, 1.1)
  • Frame 3 : x = (-1.4, 0.3) and y = (0.7, 0.7)
  • etc.

Is this correct?

Thank you!

1

There are 1 best solutions below

0
On

An animation is just a sequence of images played fast enough to give the illusion of motion. Your basic idea of reducing ranges incrementally is correct. Given a fixed center of zoom $c \in \mathbb{C}$, just animate the viewport radius $r \in \mathbb{R}^+$. Then if necessary translate to endpoints of ranges by $x = \Re(c) \pm r \frac{w}{h}$, $y = \Im(c) \pm r$ (where $w, h$ are the dimensions of the image in pixels). For constant perceptual zoom speed, $r$ should vary exponentially with time, for example $r = 10^{-t / 10}$ with time $t$ measured in seconds, to zoom in by a factor of $10$ every $10$ seconds.