[R] Fractals in R and having fun! (and more persp and color)

Martin Maechler maechler at stat.math.ethz.ch
Thu Sep 18 14:48:26 CEST 2003


>>>>> "Mario" == Mario ??? <ucgamdo at ucl.ac.uk>
>>>>>     on Wed, 17 Sep 2003 12:45:51 +0100 writes:


    Mario> Well, I started playing with fractals in R, and wrote
    Mario> a function to generate de Mandelbrot set, which might
    Mario> be of interest to some people

    Mario> ###################################################################
    Mario> # Mandelbrot set
    Mario> ###################################################################

    Mario> mandelbrot <- function(x = c(-3.0, 1.0),   # x coordinates
    Mario>                        y = c(-1.8, 1.8),   # y coordinates
    Mario>                        b = .05,            # by 'steps'
    Mario>                        iter = 20)          # maximum number of iterations

    Mario>     <..................>
    Mario>     <..................>
    Mario>     <..................>

Well, only a bit more than year ago I had posted my version of
mandelbrot() and a drawing function, see

   http://finzi.psych.upenn.edu/R/Rhelp02a/archive/5898.html

   [ I have a slightly updated version of the R code, that is now
     available as ftp://stat.ethz.ch/U/maechler/R/Mandelbrot.R
   ]

which is an order of magnitude more efficient than yours (22 x
faster for your "b = 0.01", *1), *2)
and with an iterImage() function for drawing its result in
several (simple) color schemes.
I agree that the proper solution would *definitely* use C code!

Your idea of using persp() -- while seen frequently in fractal books,
is new ``for R'' however, and nice!  Thank you.


Regards,
Martin

*1) mainly because I only have the iteration loop
    and do the rest vectorized, but also because I have a check
    for symmetry and make use of it when appropriate

*2) For speed comparison, note that I use 10 x more iterations
    and a much higher resolution by default

*3) When I do the comparison, I see that your function's result
    slightly differs from mine -- not for the Mandelbrot set
    itself, but for the very ``outer points'' (the dark orange
    ones in the image plot). Your result is
    asymmetric and hence can't be quite correct.




More information about the R-help mailing list