Created
May 25, 2016 22:18
-
-
Save CapacitorSet/c06431b622561349ff9fea97b4eff77b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(caTools) # external package providing write.gif function | |
jet.colors = colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", | |
"yellow", "#FF7F00", "red", "#7F0000")) | |
m = 4000 # 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)) # initialize output 2D array | |
for (k in 1:20) { # loop with 20 iterations | |
Z = Z^2+C # the central difference equation | |
X[,] = exp(-abs(Z)) # capture results | |
write.gif(X, paste("Mandelbrot", k, ".gif"), col = jet.colors) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment