On 09/24/2010 10:41 PM, xin wei wrote:
>
> I am trying to reproduce the nice looking of Mandelbrot demonstrated by R
> wiki page by the following code:
>
> 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)
Hmm, I couldn't be bothered with the caTools, but it looks fine for me with
image(X[,,20],col=jet.colors(100))
Perhaps you need jet.colors(n) as well?
> however, the gif file created by this looks much worse than what is shown on
> R wiki page, see the comparison as follows (left one is what i created)
>
> http://r.789695.n4.nabble.com/file/n2591429/Picture1.png
Save for the odd color scheme, the one on the left looks like a
Mandelbrot set, the one on the right appears to be iteration 4. I
couldn't find your original source for this on wiki.r-project.org?
--
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: [email protected] Priv: [email protected]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.