Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
tylermorganwall / beeswarm.R
Created January 4, 2025 20:12
3D beeswarm
#Function to generate random 3D points within a defined space
initialize_swarm = function(n=100, range=10) {
swarm = matrix(runif(n * 3, -range, range), ncol=3)
velocities = matrix(runif(n * 3, -0.1, 0.1), ncol=3)
list(swarm=swarm, velocities=velocities)
}
spinning_vector_field = function(swarm, spin_strength=0.05) {
#Swirl around the Z-axis
@tylermorganwall
tylermorganwall / advent_gh_issues.js
Created December 3, 2024 03:32
Advent of Github Issues
javascript:(function(){const%20issues=document.querySelectorAll('.js-issue-row');if(!issues.length){alert('No%20issues%20found!');return;}document.body.innerHTML='';document.body.style.margin='0';document.body.style.padding='0';document.body.style.backgroundColor='#000';document.body.style.overflow='hidden';document.body.style.position='relative';document.documentElement.style.height='100%';document.body.style.height='100%';const%20createSnowflake=()=>{const%20flake=document.createElement('div');flake.style.position='absolute';flake.style.top='-10px';flake.style.left=Math.random()*100+'vw';const%20size=Math.random()*5+5;flake.style.width=size+'px';flake.style.height=size+'px';flake.style.backgroundColor='white';flake.style.borderRadius='50%';flake.style.opacity=Math.random()*0.5+0.5;flake.style.filter='blur(2px)';flake.style.zIndex='1000';const%20duration=Math.random()*5+5;flake.style.animation=`fall%20${duration}s%20linear%200s%20forwards`;document.body.appendChild(flake);setTimeout(()=>{flake.remove();},dur
@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")