Last active
August 2, 2020 14:17
-
-
Save tylermorganwall/8e3e4b7c4dcbba2ee71c1017eb588e7a to your computer and use it in GitHub Desktop.
Pulsating Alien Goo in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
rvals = rep(0,360) | |
for(t in 1:360) { | |
xvals[t] = perlinnoisex[500+499*sinpi(t/180),500+499*cospi(t/180)]/3 | |
yvals[t] = perlinnoisey[500+499*sinpi(t/180),500+499*cospi(t/180)]/3 | |
rvals[t] = perlinnoise_rad[500+499*sinpi(t/180),500+499*cospi(t/180)]/3 | |
} | |
#Camera lookat vector for shaky cam | |
plot(xvals,yvals) | |
#Pulsating radius value | |
plot(rvals+sinpi(1:360/180*6)/10) | |
final_r = rvals+sinpi(1:360/180*6)/10 | |
#Create the animation | |
r = 0.7 | |
theta_vals = seq(0,2*pi,length.out = 16)[-16] | |
phi_vals = seq(0,pi,length.out = 16)[-16][-1] | |
for(i in seq(1,360,by=1)) { | |
spike_list = list() | |
counter = 1 | |
for(theta in theta_vals) { | |
for(phi in phi_vals) { | |
#Add spikes facing outwards | |
rval = c(r*sin(phi)*cos(theta),r*cos(phi),r*sin(phi)*sin(theta)) | |
spike_list[[counter]] = cone(start=rval, direction = rval/sqrt(sum(rval*rval))^3 * | |
(0.75 + 0.25 * sin(theta - 4*pi/180* i)) * | |
(0.75 + 0.25 * cos(phi + 2*pi/180* i)), | |
radius=0.25,material = glossy(color="black")) | |
counter = counter + 1 | |
} | |
} | |
vector_field = do.call(rbind,spike_list) | |
#Render frame (get an environment image from hdrihaven.com) | |
sphere(radius = 1 + final_r[i]*1.25, material = glossy(color="black")) %>% | |
add_object(vector_field) %>% | |
render_scene(fov=25, samples=400,environment_light = "kiara_1_dawn_2k.hdr", | |
filename=glue::glue("spikyshaky{i}"), | |
width=800,height=800,lookat=c(xvals[i],yvals[i],0)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment