Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
tylermorganwall / aliengoo.R
Last active August 2, 2020 14:17
Pulsating Alien Goo in 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 July 27, 2020 13:39
Rayshader Render Highquality with Realistic Water
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 February 25, 2024 18:22
Historical Map of India with 3D elevation
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 June 29, 2020 03:18
State New Cases COVID-19 3D Visualization in R
library(rayrender)
library(sf)
library(dplyr)
library(ggplot2)
library(lubridate)
library(magick)
#Extract state data
us_states = spData::us_states
@tylermorganwall
tylermorganwall / advanced_3d_pie_chart.R
Created June 28, 2020 14:48
The Most Beautiful 3D Pie Charts You've Ever Seen
library(rayrender)
pielist = list()
counter = 1
for(i in seq(60-90,360-90,by=60)) {
angles = seq(i-60,i,by=1)
xx = 2*sinpi(angles/180)
yy = 2*cospi(angles/180)
pielist[[counter]] = data.frame(x=c(0,xx),y=c(0,yy))
counter = counter + 1
@tylermorganwall
tylermorganwall / 3d_jealous_girlfriend.R
Last active April 25, 2020 20:25
3D jealous girlfriend ggplot made with R + rayshader
library(tidyverse)
dbf = data.frame(color=character(0), x=numeric(0), y=numeric(0), stringsAsFactors = F)
## Distractive woman
# Left arm
dbf = bind_rows(dbf, crossing(color='skin', x=seq(4,5), y=seq(1,9),z=3))
dbf = bind_rows(dbf, data.frame(color='skin', x=5, y=10,z=3))
@tylermorganwall
tylermorganwall / pillars.R
Created February 13, 2020 12:48
3D pathtraced oscillating pillars in R
library(rayshader)
library(rayrender)
for(t in 1:90) {
sliced = matrix(10, 99, 99)
sliced2 = sliced
for(i in 1:nrow(sliced)) {
for(j in 1:ncol(sliced)) {
sliced2[i,j] = 10+1*cos(-t/90*2*pi + 8*i/nrow(sliced))
if(i %% 3 == 0 || j %% 3 == 0) {
@tylermorganwall
tylermorganwall / spiral.R
Created December 6, 2019 14:02
Rendering a light traveling through a spiral
library(rayrender)
drawspiral = function(n, x = 0, material=diffuse(color="white")) {
segments = list()
for(i in seq_len(n)) {
if(i %% 2 != 0) {
segments[[i]] = cylinder(z=0.5,x=x, length=0.5, radius=0.5*i, material = material, phi_min = 90, phi_max = 270)
} else {
segments[[i]] = cylinder(z=0,x=x, length=0.5, radius=0.5*i, material = material, phi_min = 90, phi_max = 270, angle=c(0,180,0))
}
@tylermorganwall
tylermorganwall / shanghai_ring_hdr.R
Last active December 4, 2019 13:46
A simple animation with a scene lit by an HDR environment image (from hrdihaven.com)
library(rayrender)
vecx = 10 * sinpi(1:360/180)
vecz = 10 * cospi(1:360/180)
anglevec = -10 * cospi(1:360/90)
for(i in seq(1,360,by=1)) {
generate_ground(material = dielectric()) %>%
add_object(sphere(material = metal())) %>%
add_object(disk(radius=3, inner_radius = 2, angle = c(anglevec[i],-i,0))) %>%
@tylermorganwall
tylermorganwall / pennsylvania_rayshader_example.R
Last active March 26, 2024 13:54
30 Day Map Challenge, Day 30: Home (Pennsylvania)
library(rayshader)
library(raster)
library(stringr)
library(sp)
library(maptools)
library(dplyr)
library(rgdal)
library(sf)
readShapePoly("eastern-states")