Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rickhenderson/c70ece1e26a27451dfe7 to your computer and use it in GitHub Desktop.
Save rickhenderson/c70ece1e26a27451dfe7 to your computer and use it in GitHub Desktop.
# mandelbrot_vectorized.R
# Myles Harrison
# http://www.everydayanalytics.ca
# parameters
cols <- colorRampPalette(c("blue","yellow","red","black"))(11)
xmin = -2
xmax = 2
nx = 500
ymin = -1.5
ymax = 1.5
ny = 500
n=200
# 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) {
print(rep)
index <- which(Mod(z) < 2)
z[index] <- z[index]^2 + c[index]
k[index] <- k[index] + 1
}
image(x,y,k, col=cols)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment