# NOT RUN {
#Generate a large checkered sphere as the ground
scene = generate_ground(depth=-0.5, material = diffuse(color="white", checkercolor="darkgreen"))
# }
# NOT RUN {
render_scene(scene,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Add a sphere to the center
scene = scene %>%
add_object(sphere(x=0,y=0,z=0,radius=0.5,material = diffuse(color=c(1,0,1))))
# }
# NOT RUN {
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Add a marbled cube
scene = scene %>%
add_object(cube(x=1.1,y=0,z=0,material = diffuse(noise=3)))
# }
# NOT RUN {
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Add a metallic gold sphere
scene = scene %>%
add_object(sphere(x=-1.1,y=0,z=0,radius=0.5,material = metal(color="gold",fuzz=0.1)))
# }
# NOT RUN {
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Lower the number of samples to render more quickly (here, we also use only one core).
render_scene(scene, samples=4)
#Add a floating R plot using the iris dataset as a png onto a floating 2D rectangle
# }
# NOT RUN {
tempfileplot = tempfile()
png(filename=tempfileplot,height=400,width=800)
plot(iris$Petal.Length,iris$Sepal.Width,col=iris$Species,pch=18,cex=4)
dev.off()
image_array = aperm(png::readPNG(tempfileplot),c(2,1,3))
scene = scene %>%
add_object(xy_rect(x=0,y=1.1,z=0,xwidth=2,angle = c(0,180,0),
material = diffuse(image = image_array)))
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Move the camera
# }
# NOT RUN {
render_scene(scene,lookfrom = c(7,1.5,10),lookat = c(0,0.5,0),fov=15,parallel=TRUE)
# }
# NOT RUN {
#Change the background gradient to a night time ambiance
# }
# NOT RUN {
render_scene(scene,lookfrom = c(7,1.5,10),lookat = c(0,0.5,0),fov=15,
backgroundhigh = "#282375", backgroundlow = "#7e77ea", parallel=TRUE,
samples=500)
# }
# NOT RUN {
#Increase the aperture to blur objects that are further from the focal plane.
# }
# NOT RUN {
render_scene(scene,lookfrom = c(7,1.5,10),lookat = c(0,0.5,0),fov=15,
aperture = 0.5,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Spin the camera around the scene, decreasing the number of samples to render faster. To make
#an animation, specify the a filename in `render_scene` for each frame and use the `av` package
#or ffmpeg to combine them all into a movie.
t=1:30
xpos = 10 * sin(t*12*pi/180+pi/2)
zpos = 10 * cos(t*12*pi/180+pi/2)
# }
# NOT RUN {
#Save old par() settings
old.par = par(no.readonly = TRUE)
on.exit(par(old.par))
par(mfrow=c(5,6))
for(i in 1:30) {
render_scene(scene, samples=5,
lookfrom = c(xpos[i],1.5,zpos[i]),lookat = c(0,0.5,0), parallel=TRUE)
}
# }
Run the code above in your browser using DataLab