#Generate the default curve:
if(run_documentation()) {
generate_studio(depth=-0.2) %>%
add_object(bezier_curve(material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,radius=0.3,
material=light(intensity=200, spotlight_focus = c(0,0.5,0)))) %>%
render_scene(clamp_value = 10, lookat = c(0,0.5,0), fov=13,
samples=16)
}
if(run_documentation()) {
#Change the control points to change the direction of the curve. Here, we place spheres
#at the control point locations.
generate_studio(depth=-0.2) %>%
add_object(bezier_curve(material=diffuse(color="red"))) %>%
add_object(sphere(radius=0.075,material=glossy(color="green"))) %>%
add_object(sphere(radius=0.075,x=-1,y=0.33,material=glossy(color="green"))) %>%
add_object(sphere(radius=0.075,x=1,y=0.66,material=glossy(color="green"))) %>%
add_object(sphere(radius=0.075,y=1,material=glossy(color="green"))) %>%
add_object(sphere(y=3,z=5,x=2,radius=0.3,
material=light(intensity=200, spotlight_focus = c(0,0.5,0)))) %>%
render_scene(clamp_value = 10, lookat = c(0,0.5,0), fov=15,
samples=16)
}
if(run_documentation()) {
#We can make the curve flat (always facing the camera) by setting the type to `flat`
generate_studio(depth=-0.2) %>%
add_object(bezier_curve(type="flat", material=glossy(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,radius=0.3,
material=light(intensity=200, spotlight_focus = c(0,0.5,0)))) %>%
render_scene(clamp_value = 10, lookat = c(0,0.5,0), fov=13,
samples=16)
}
if(run_documentation()) {
#We can also plot a ribbon, which is further specified by a start and end orientation with
#two surface normals.
generate_studio(depth=-0.2) %>%
add_object(bezier_curve(type="ribbon", width=0.2,
p1 = c(0,0,0), p2 = c(0,0.33,0), p3 = c(0,0.66,0), p4 = c(0.3,1,0),
normal_end = c(0,0,1),
material=glossy(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,radius=0.3,
material=light(intensity=200, spotlight_focus = c(0,0.5,0)))) %>%
render_scene(clamp_value = 10, lookat = c(0,0.5,0), fov=13,
samples=16)
}
if(run_documentation()) {
#Create a single curve and copy and rotate it around the y-axis to create a wavy fountain effect:
scene_curves = list()
for(i in 1:90) {
scene_curves[[i]] = bezier_curve(p1 = c(0,0,0),p2 = c(0,5-sinpi(i*16/180),2),
p3 = c(0,5-0.5 * sinpi(i*16/180),4),p4 = c(0,0,6),
angle=c(0,i*4,0), type="cylinder",
width = 0.1, width_end =0.1,material=glossy(color="red"))
}
all_curves = do.call(rbind, scene_curves)
generate_ground(depth=0,material=diffuse(checkercolor="grey20")) %>%
add_object(all_curves) %>%
add_object(sphere(y=7,z=0,x=0,material=light(intensity=100))) %>%
render_scene(lookfrom = c(12,20,50),samples=100,
lookat=c(0,1,0), fov=15, clamp_value = 10)
}
Run the code above in your browser using DataLab