Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
tylermorganwall / christmas_csg_realistic_camera.R
Created December 24, 2021 19:43
CSG Christmas Tree in R
library(rayrender)
#Generate CSG branches
branches0 = csg_cone(end=c(0,0.5,0)) %>%
csg_combine(csg_cone(start=c(0,0.25,0),end=c(0,0.75,0), radius=0.75), operation="blend", radius = 0.7)%>%
csg_scale(1.25)
branches1 = csg_cone(end=c(0,0.5,0)) %>%
csg_combine(csg_cone(start=c(0,0.25,0),end=c(0,0.75,0), radius=0.75), operation="blend", radius = 0.7)
@tylermorganwall
tylermorganwall / submarine_cable_map.R
Last active April 7, 2024 12:26
Submarine Cable Map Dataviz
library(geojsonsf)
library(sf)
library(rayrender)
#Data source: https://github.com/telegeography/www.submarinecablemap.com
cables = geojson_sf("cable-geo.json")
cablescene = list()
counter = 1
for(i in 1:length(cables$geometry)) {
@tylermorganwall
tylermorganwall / humanity_globe.R
Created August 17, 2021 14:37
3D Humanity Globe
library(rayshader)
library(rayrender)
popdata = raster::raster("gpw_v4_population_density_rev11_2020_15_min.tif")
population_mat = rayshader:::flipud(raster_to_matrix(popdata))
above1 = population_mat > 1
above5 = population_mat > 5
above10 = population_mat > 10
@tylermorganwall
tylermorganwall / star_wars_rayvertex.R
Created June 12, 2021 16:11
Star Wars Intro with Rayvertex
library(rayvertex)
text3d_mesh("A long time ago in a rayverse far,",color=c(75, 213, 238)/255) %>%
add_shape(text3d_mesh("far, away...",color=c(75, 213, 238)/255,position=c(-5,-1,0))) %>%
rasterize_scene(fov=120,lookat=c(0,-0.5,0),lookfrom=c(0,-0.5,5),
filename="start")
for(i in 1:(24*6)) {
png::readPNG(glue::glue("start.png")) %>%
png::writePNG(glue::glue("starwarsvertex{i}.png"))
@tylermorganwall
tylermorganwall / earth_halo.R
Created April 8, 2021 13:19
R: 3D Rayshader/Rayrender Dataviz 360° VR Video (Earth Halo)
#You can find the surface textures at the link below:
#http://www.shadedrelief.com/natural3/pages/extra.html
#The background is just starfield image—any will do.
#Note: this uses the latest version of rayrender (0.21.4) on github
library(rayrender)
for(i in 1:360) {
group_objects(cylinder(angle=c(90,90,0), material=diffuse(image_texture = "8081_earthmap10k.jpg",
bump_texture = "8081_earthbump10k.jpg", bump_intensity = 100),
radius=12, capped = FALSE, length = 6) %>%
@tylermorganwall
tylermorganwall / hadley_attractor.R
Last active April 9, 2021 19:06
3D Hadley Attractor
library(deSolve)
library(rayrender)
parameters = c(a = 0.2, b = 4, c = 8, d = 1)
state = c(X = 1, Y = 0, Z = 1)
Lorenz = function(t, state, parameters) {
with(as.list(c(state, parameters)), {
dX = -Y^2 - Z^2 - a*X + a*c
dY = X * Y - b * X * Z - Y + d
dZ = b * X * Y + X * Z - Z
@tylermorganwall
tylermorganwall / gist:1fd7adb32199e3d57d45768b6946f8fb
Last active November 10, 2020 22:34
ASCII rayshader + rayrender
library(rayshader)
library(crayon)
ivory <- make_style("ivory")
bgMaroon <- make_style(rgb(0.2,0.2,0.2,0), bg = TRUE)
fancy <- combine_styles(ivory, bgMaroon)
cat(fancy("This will have some fancy colors"), "\n")
@tylermorganwall
tylermorganwall / terminator_pig.R
Last active September 25, 2020 12:56
Terminator Pig, rendered in R
library(rayrender)
#CSG Pig Elements
leg_scene = list(csg_cylinder(start = c(1,-0.6,0.5), end = c(1,1.,0.5), radius=0.25+0.01),
csg_cylinder(start = c(-1,-0.6,0.5), end = c(-1,1.,0.5), radius=0.25+0.01),
csg_cylinder(start = c(1,-0.6,-0.5), end = c(1,1.,-0.5), radius=0.25+0.01),
csg_cylinder(start = c(-1,-0.6,-0.5), end = c(-1,1.,-0.5), radius=0.25+0.01))
eye_scene = list(csg_sphere(x = 2, y = 2.5, z = 0.3, radius=0.25+0.01),
csg_sphere(x = 2, y = 2.5, z = -0.3, radius=0.25+0.01+0.01),
csg_sphere(x = 2.2, y = 2.5, z = 0.3, radius=0.1+0.01),
@tylermorganwall
tylermorganwall / 3d_table.R
Last active April 19, 2023 11:54
"RStudio Table Contest" 3D Table Render
library(rayrender)
make_legs = function(x=0,y=0,z=0) {
csg_translate(y=-5,
csg_combine(
csg_rotate(
csg_pyramid(z=z,x=x,y=y, height = 10), pivot_point = c(x,5,y),up = c(0,-1,0)),
csg_box(x=x,z=z,y=2.5, width = c(1,5,1)), operation = "subtract"))
}
@tylermorganwall
tylermorganwall / palmer_penguin_3d.R
Created August 4, 2020 13:14
Palmer Penguin Dataset, 3D ggplot
library(rayshader)
library(ggplot2)
library(palmerpenguins)
library(tidyverse)
library(rayrender)
library(rayimage)
library(magick)
penguins