[R] A little complex puzzle

Bill.Venables at csiro.au Bill.Venables at csiro.au
Sun Sep 26 04:03:52 CEST 2010


I was looking for an example of complex variables in R.  This one is trivial, but rather cute (though World War II aficionados may 'come over all funny').

See if you can guess the image before you try the function.  It's not difficult.

jif <- function(res = 100) {
  z <- sample(do.call(complex, subset(expand.grid(real =
                                                  seq(-3, 4, len = 7*res + 1), 
                                                  imaginary =
                                                  seq(-2, 2, len = 4*res + 1)),
                                      real > -2.439 & real < 3.717)))
  del <- 2*base::pi/32
  plot(z, type = "n", asp = 1, ann = FALSE, axes = FALSE)
  points(z[((Arg(z) + del/2) %/% del) %% 2 == 0
           | Mod(z) < 1.15], col = "red", pch = ".")
}

Njoi.

Bill Venables.


More information about the R-help mailing list