Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active September 13, 2020 09:58
Show Gist options
  • Save yutannihilation/5f3cc3251cb41cf5cf2126f5565ad73d to your computer and use it in GitHub Desktop.
Save yutannihilation/5f3cc3251cb41cf5cf2126f5565ad73d to your computer and use it in GitHub Desktop.
library(rayrender)
# generate path data by https://github.com/yutannihilation/rusttype-test
d <- readr::read_csv("/tmp/tmp.csv", col_names = c("x", "y", "id"))
l <- split(d, d$id)
colors <- scales::colour_ramp(c("#FF3499", "#FFECEC"))(seq(from = 0.4, to = 0.0, length.out = length(l)))
dir.create("/tmp/tokyor/")
x_avg <- mean(range(d$x))
for (i in seq(1, 180, by = 1)) {
scene <- generate_ground(material = metal(color = "grey20", fuzz = 0.05))
scene <- purrr::reduce2(l, colors, .init = scene, function(scene, x, color) {
m <- cbind(x = x$x, y = -1.2 + 3 * (1 - (1 - i / 180)^3), z = 10 - x$y)
p <- path(m, material = light(intensity = 20 * i / 180, color = color), straight = TRUE, width = 0.03)
add_object(scene, p)
})
scene %>%
render_scene(
lookfrom = c(x_avg * i / 180, 10 + 90 * i / 180, 20 * i / 180), lookat = c(x_avg, -10, 10 - 10 * i / 180), samples = 200,
aperture = 0, fov = 25, bloom = 10, tonemap = "reinhold",
width = 800, height = 800,
filename = sprintf("/tmp/tokyor/tokyor%03d", i),
parallel = TRUE
)
}
# ffmpeg -y -r 60 -i /tmp/tokyor/tokyor%03d.png -vcodec libx264 -pix_fmt yuv420p -an -r 30 -b:v 2000k out.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment