#Librerías necesarias
install.packages("rgl")
install.packages("magick")
#Datos
data(volcano)
#Codigo
library("rgl")
library("magick")
z <- 2 * volcano
x <- 10 * (1:nrow(z))
y <- 10 * (1:ncol(z))
zlim <- range(z)
zlen <- zlim[2] - zlim[1] + 1
colorlut <- terrain.colors(zlen)
col <- colorlut[ z - zlim[1] + 1 ]
open3d()
bg3d("white")
surface3d(x, y, z, color = col, back = "lines")
r <- max(y) - mean(y)
lightid <- spheres3d(1, 1, 1, alpha = 0)
frame <- function(time) {
a <- pi*(time - 1)
save <- par3d(skipRedraw = TRUE)
clear3d(type = "lights")
rgl.pop(id = lightid)
xyz <- matrix(c(r*sin(a) + mean(x), r*cos(a) + mean(y), max(z)), ncol = 3)
light3d(x = xyz, diffuse = "gray75",
specular = "gray75", viewpoint.rel = FALSE)
light3d(diffuse = "gray10", specular = "gray25")
lightid <<- spheres3d(xyz, emission = "white", radius = 4)
par3d(save)
Sys.sleep(0.02)
NULL
}
#Giro Automatico
play3d(frame, duration = 100)
# O Generar Gif
movie3d( spin3d( axis = c(0, 0, 1), rpm = 7),
duration = 10, dir = getwd(),
type = "gif", clean = TRUE )
###################################################
install.packages("rgl")
install.packages("magick")
library("rgl")
library("rgl")
library("magick")
data(volcano)
z <- 2 * volcano
x <- 10 * (1:nrow(z))
y <- 10 * (1:ncol(z))
zlim <- range(z)
zlen <- zlim[2] - zlim[1] + 1
colorlut <- terrain.colors(zlen)
col <- colorlut[ z - zlim[1] + 1 ]
open3d()
bg3d("white")
surface3d(x, y, z, color = col, back = "lines")
r <- max(y) - mean(y)
lightid <- spheres3d(1, 1, 1, alpha = 0)
frame <- function(time) {
a <- pi*(time - 1)
save <- par3d(skipRedraw = TRUE)
clear3d(type = "lights")
rgl.pop(id = lightid)
xyz <- matrix(c(r*sin(a) + mean(x), r*cos(a) + mean(y), max(z)), ncol = 3)
light3d(x = xyz, diffuse = "gray75",
specular = "gray75", viewpoint.rel = FALSE)
light3d(diffuse = "gray10", specular = "gray25")
lightid <<- spheres3d(xyz, emission = "white", radius = 4)
par3d(save)
Sys.sleep(0.02)
NULL
}
play3d(frame, duration = 100)
###################################################