Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
Last active April 9, 2021 19:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylermorganwall/effc7dc651a584681c486ac7918d264a to your computer and use it in GitHub Desktop.
Save tylermorganwall/effc7dc651a584681c486ac7918d264a to your computer and use it in GitHub Desktop.
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
list(c(dX, dY, dZ))
})
}
times = seq(0, 150, by = 0.1)
vals = ode(y = state, times = times, func = Lorenz, parms = parameters)[,-1]
#scale and rearrange:
meanval = apply(apply(vals,2,range),2,mean)
vals[,1] = vals[,1] - meanval[1]
vals[,2] = vals[,2] - meanval[2]
vals[,3] = vals[,3] - meanval[3]
for(i in 1:360) {
generate_studio(depth = -2) %>%
add_object(path(points = vals,width=0.04,angle=c(0,i,0),
material=glossy(color="red", gradient_color = "dodgerblue4",
gradient_point_start = c(0,-1.5,0), gradient_point_end = c(0,2,0)))) %>%
add_object(sphere(y=5,z=2,material=light(intensity = 40))) %>%
render_scene(samples=400,fov=30,clamp_value = 10,width=800,height=800,
filename=sprintf("hadleyatt%i.png",i))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment