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.

以上就是How to change the resolution when drawing with R?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

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

支付宝扫一扫打赏

微信扫一扫打赏