Skip to content

Instantly share code, notes, and snippets.

@CapacitorSet
Created May 25, 2016 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CapacitorSet/2150af7185590ef3f108fd172b7d56c3 to your computer and use it in GitHub Desktop.
Save CapacitorSet/2150af7185590ef3f108fd172b7d56c3 to your computer and use it in GitHub Desktop.
library(caTools) # external package providing write.gif function
jet.colors = colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F",
"yellow", "#FF7F00", "red", "#7F0000"))
m = 600 # define size
C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ),
imag=rep(seq(-1.2,1.2, length.out=m), m ) )
C = matrix(C,m,m) # reshape as square matrix of complex numbers
Z = 0 # initialize Z to zero
X = array(0, c(m,m,20)) # initialize output 3D array
for (k in 1:20) { # loop with 20 iterations
Z = Z^2+C # the central difference equation
X[,,k] = exp(-abs(Z)) # capture results
}
write.gif(X, "Mandelbrot.gif", col=jet.colors, delay=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment