Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
tylermorganwall / glowing_contours.R
Created February 24, 2023 02:29
Glowing Contours in R
library(rayshader)
volcano |>
height_shade() |>
plot_3d(volcano,zscale=3)
render_contours(volcano, clear_previous = T, offset=1,color="purple",
zscale=3, nlevels = 20)
for(i in 1:360) {
@tylermorganwall
tylermorganwall / heliocube.R
Last active February 4, 2023 18:41
Heliocentric Cube (genart)
library(rayrender)
library(RColorBrewer)
colors = brewer.pal(n = 8, name = "Dark2")
set.seed(1)
spherelist = list()
for(i in 1:1000) {
spherelist[[i]] = sphere(x=runif(1)*535+10,y=runif(1)*535+10,z=runif(1)*535+10,
radius=10,
material=glossy(color = sample(colors,1)))
}
@tylermorganwall
tylermorganwall / render_hq_materials.R
Created January 21, 2023 01:32
render_highquality() glass path
moss_landing_coord = c(36.806807, -121.793332)
t = seq(0,2*pi,length.out=1000)
circle_coords_lat = moss_landing_coord[1] + 0.5 * t/8 * sin(t*6)
circle_coords_long = moss_landing_coord[2] + 0.5 * t/8 * cos(t*6)
montereybay %>%
sphere_shade() %>%
plot_3d(montereybay,zscale=50,water=TRUE,
shadowcolor="#40310a", watercolor="#233aa1", background = "tan",
theta=210, phi=22, zoom=0.20, fov=55)
@tylermorganwall
tylermorganwall / national_mall_3d.R
Created November 11, 2022 14:15
3D National Mall with Trees and Buildings in Rayshader
#Load all the libraries needed
library(sf)
library(dplyr)
library(rayrender)
library(elevatr)
library(rayshader)
library(geojsonsf)
library(raster)
library(lidR)
testapply = list()
testvapply = list()
# First, we generate a 10001 x 10001 matrix of random numbers pulled from a gaussian distribution. Our goal is to sum each of the columns and return a vector of each sum. Here, we have two strategies:
# 1) Loop through each column, calculate the sum, and assign into a vector.
# 2) apply() the sum function to each column.
numbers = matrix(rnorm(10001^2,0,1),nrow=10001,ncol=10001)
iter=1
@tylermorganwall
tylermorganwall / helicopter.R
Created September 30, 2022 21:03
Recreating Wapo Judiciary Square Helicopter Dataviz
#Load all the libraries needed
library(sf)
library(dplyr)
library(rayrender)
library(elevatr)
library(rayshader)
library(geojsonsf)
library(raster)
#To recreate the wapo visualization, we need to visualize a few things in 3D: the buildings,
@tylermorganwall
tylermorganwall / spacex.R
Created June 27, 2022 01:46
Starlink Visualization
library(rayrender)
starlink_traj = list()
earthrad = 3958.8
orbit_alt = 340
t=seq(0,360,length.out=31)[-31]
xpos = (earthrad + orbit_alt) * cospi(t/180)
zpos = (earthrad + orbit_alt) * sinpi(t/180)
@tylermorganwall
tylermorganwall / interactive_tutorial.R
Last active November 27, 2023 05:39
3D Interactive R Tutorial
library(rayshader)
library(rayrender)
library(ggplot2)
ggdiamonds = ggplot(diamonds) +
stat_density_2d(aes(x = x, y = depth, fill = stat(nlevel)),
geom = "polygon", n = 200, bins = 50,contour = TRUE) +
facet_wrap(clarity~.) +
scale_fill_viridis_c(option = "A")
@tylermorganwall
tylermorganwall / jwst_ao.R
Created February 7, 2022 22:53
JWST rendered with ambient occlusion in R with rayrender
#JWST OBJ file located at www.tylermw.com/webb.zip
#Parse OBJ MTL file to read and write red color for highlighted component
mtl_file = readLines("jwebb.mtl")
kd_entries = (grepl("Kd",mtl_file,fixed=T))
kd_ind = which(grepl("Kd",mtl_file,fixed=T))
#Set all to white
mtl_file[kd_entries] = "Kd 1.000000 1.000000 1.000000"
@tylermorganwall
tylermorganwall / cloud_animate.R
Created February 1, 2022 04:34
Cloud animate
library(rayshader)
montereybay2 = montereybay
montereybay2[montereybay2<0] = 0
for(i in 1:720) {
montereybay2 %>%
sphere_shade() %>%
add_water(detect_water(montereybay2), color="lightblue") |>
add_shadow(cloud_shade(montereybay2,zscale=50, sun_altitude = 90, seed=10, attenuation_coef = 1, time=i,