Skip to content

Instantly share code, notes, and snippets.

@marcosci
Created December 8, 2021 07:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save marcosci/7a72a0bcb1781367cf7382a0de799ab3 to your computer and use it in GitHub Desktop.
Save marcosci/7a72a0bcb1781367cf7382a0de799ab3 to your computer and use it in GitHub Desktop.
Rayrender Universe
library(rayrender)
library(glue)
y_dist = 8
circle <- function(x = 0, y = 0 + 20, rad = 1, nvert = 500, ...){
rads <- seq(0,2*pi,length.out = nvert)
xcoords <- cos(rads) * rad + x
ycoords <- sin(rads) * rad + y
cbind(x = xcoords, y = y_dist, z = ycoords)
}
# diameter_km = c(200000, 4878, 12104, 12756, 6787, 142796, 120660, 51118, 48600)
diameter = c(1, 0.04, 0.09, 0.1, 0.05, 1.12, 0.94, 0.4, 0.39)
distance_from_sun = c(0, 0.04, 0.09, 0.1, 0.05, 1.12, 0.94, 0.4, 0.39) / 10
# Set up orbit traces
trace_mercury = circle(rad = 4) # Mercury
trace_venus = circle(rad = 4.5) # Venus
trace_earth = circle(rad = 4.95) # Earth
trace_mars = circle(rad = 5.45) # Mars
trace_jupyter = circle(rad = 6.85) # Jupyter
trace_saturn = circle(rad = 8.75) # Saturn
trace_uranus = circle(rad = 9.9) # Uranus
trace_neptune = circle(rad = 10.7) # Neptune
mercury_i <- seq(1,500)
venus_i <- c(seq(50,500), seq(1,50))
earth_i <- c(seq(100,500), seq(1,100))
mars_i <- c(seq(150,500), seq(1,150))
jupyter_i <- c(seq(200,500), seq(1,200))
saturn_i <- c(seq(250,500), seq(1,250))
uranus_i <- c(seq(300,500), seq(1,300))
neptune_i <- seq(1,500)
for (i in seq(1, 500)){
generate_studio(depth = -1, material = diffuse(color = "#eeeded"), width = 850) %>%
add_object(path(points=trace_mercury,width=0.001,material=diffuse(color="#fde1de"))) %>%
add_object(path(points=trace_venus,width=0.001,material=diffuse(color="#fde1de"))) %>%
add_object(path(points=trace_earth,width=0.001,material=diffuse(color="#fde1de"))) %>%
add_object(path(points=trace_mars,width=0.001,material=diffuse(color="#fde1de"))) %>%
add_object(path(points=trace_jupyter,width=0.004,material=diffuse(color="#fde1de"))) %>%
add_object(path(points=trace_saturn,width=0.003,material=diffuse(color="#fde1de"))) %>%
add_object(path(points=trace_uranus,width=0.002,material=diffuse(color="#fde1de"))) %>%
add_object(path(points=trace_neptune,width=0.002,material=diffuse(color="#fde1de"))) %>%
add_object(sphere(x = 0, y = y_dist, z = 20, radius = 1, material = light(color = "#ffd34d", gradient_color = "#ffe69a", intensity = 120))) %>%
add_object(sphere(x = trace_mercury[mercury_i[i],1], y = y_dist, z = trace_mercury[mercury_i[i],3], radius = diameter[2], material = diffuse(color = "#F2D79E"))) %>%
add_object(sphere(x = trace_venus[venus_i[i],1], y = y_dist, z = trace_venus[venus_i[i],3], radius = diameter[3], material = diffuse(color = "#46CEB3"))) %>%
add_object(sphere(x = trace_earth[earth_i[i],1], y = y_dist, z = trace_earth[earth_i[i],3], radius = diameter[4], material = diffuse(color = "#C55835"))) %>%
add_object(sphere(x = trace_mars[mars_i[i], 1], y = y_dist, z = trace_mars[mars_i[i], 3], radius = diameter[5], material = diffuse(color = "#DAC495"))) %>%
add_object(sphere(x = trace_jupyter[jupyter_i[i], 1], y = y_dist, z = trace_jupyter[jupyter_i[i], 3], radius = diameter[6], material = diffuse(color = "#E9C756"))) %>%
add_object(sphere(x = trace_saturn[saturn_i[i], 1], y = y_dist, z = trace_saturn[saturn_i[i], 3], radius = diameter[7], material = diffuse(color = "#98C3C3"))) %>%
add_object(sphere(x = trace_uranus[uranus_i[i], 1], y = y_dist, z = trace_uranus[uranus_i[i], 3], radius = diameter[8], material = diffuse(color = "#C9C8C7"))) %>%
add_object(sphere(x = trace_neptune[neptune_i[i], 1], y = y_dist, z = trace_neptune[neptune_i[i], 3], radius = diameter[9], material = diffuse(color = "#517FDA"))) %>%
render_scene(
samples = 1000,
width = 1200,
height = 800,
aperture = 0,
fov = 60,
lookfrom = c(0,20,45),
clamp_value = 5,
min_variance = 0,
sample_method = "sobol",
parallel = TRUE,
filename = glue("universe/step_{i}.png")
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment