Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
tylermorganwall / earth_halo.R
Created Apr 8, 2021
R: 3D Rayshader/Rayrender Dataviz 360° VR Video (Earth Halo)
View earth_halo.R
#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) %>%
View hadley_attractor.R
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
View gist:1fd7adb32199e3d57d45768b6946f8fb
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 Sep 25, 2020
Terminator Pig, rendered in R
View terminator_pig.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 Oct 2, 2020
"RStudio Table Contest" 3D Table Render
View 3d_table.R
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 Aug 4, 2020
Palmer Penguin Dataset, 3D ggplot
View palmer_penguin_3d.R
library(rayshader)
library(ggplot2)
library(palmerpenguins)
library(tidyverse)
library(rayrender)
library(rayimage)
library(magick)
penguins
@tylermorganwall
tylermorganwall / aliengoo.R
Last active Aug 2, 2020
Pulsating Alien Goo in R
View aliengoo.R
library(rayrender)
#Generate a random series that loops
set.seed(5)
perlinnoisex = ambient::noise_perlin(c(1000,1000),frequency = 0.001)
perlinnoisey = ambient::noise_perlin(c(1000,1000),frequency = 0.001)
perlinnoise_rad = ambient::noise_perlin(c(1000,1000),frequency = 0.001)
xvals = rep(0,360)
yvals = rep(0,360)
@tylermorganwall
tylermorganwall / realistic_water_cube.R
Last active Jul 27, 2020
Rayshader Render Highquality with Realistic Water
View realistic_water_cube.R
library(rayrender)
library(rayshader)
sizetex = 4000
zval = 100*sinpi(1:360/180)
coordss = expand.grid(x=1:sizetex,y=1:sizetex)
snow_palette = "white"
snow_hs = height_shade(montereybay, texture = snow_palette)
@tylermorganwall
tylermorganwall / india_historical_map.R
Last active Apr 13, 2021
Historical Map of India with 3D elevation
View india_historical_map.R
library(raster)
library(rayshader)
#Load QGIS georeference image (see https://www.qgistutorials.com/en/docs/3/georeferencing_basics.html)
testindia = raster::stack("1870_southern-india_modified.tif")
#Set bounding box for final map (cut off edges without data, introduced via reprojection)
india_bb = raster::extent(c(68,92,1,20))
cropped_india = raster::crop(testindia, india_bb)
#Convert to RGB array
@tylermorganwall
tylermorganwall / covidcases3D.R
Created Jun 29, 2020
State New Cases COVID-19 3D Visualization in R
View covidcases3D.R
library(rayrender)
library(sf)
library(dplyr)
library(ggplot2)
library(lubridate)
library(magick)
#Extract state data
us_states = spData::us_states