# How to change the resolution when drawing with R?

I recently began coding in R and stumbled upon this code, which draws a Mandelbrot fractal: library(caTools) # external package providing write.gif function jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) m <- 1200 # 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) I made a few tests and looked at the result. I found out the images had a too low resolution, so I tried this code to improve the resolution: essentially, it calculates the function twice the times (i.e. `f(1)`, `f(1.5)`, `f(2)`, `f(2.5)` instead of `f(1)`, `f(2)`), I think. library(caTools) # external package providing write.gif function jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) m <- 1200 # 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*2)) # initialize output 3D array for (n in 1:20) { # loop with 20 iterations for (m in 1:2) { # Loop twice k <- n+m/2 # Does the trick of adding .5 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) Although it calculates twice the amount of numbers, the resolution of `Mandelbrot.gif` seems to be the same, as well as the dimensions (1200x1200).
I didn't try further values for m, because it resulted in a too large variable.

### 觉得文章有用就打赏一下文章作者

#### 支付宝扫一扫打赏 #### 微信扫一扫打赏 