Skip to content

Instantly share code, notes, and snippets.

@djnavarro
Created October 6, 2018 04:24
Show Gist options
  • Save djnavarro/ec8c07d3dd6542bf2c5db5e0ca93d07d to your computer and use it in GitHub Desktop.
Save djnavarro/ec8c07d3dd6542bf2c5db5e0ca93d07d to your computer and use it in GitHub Desktop.
animated worley noise (or perlin noise)
library(ambient)
library(imager)
library(tidyverse)
library(gganimate)
make_noise_frame <- function(n=500, fr=1, type = "worley") {
if(type == "worley") {
noise <- noise_worley(
dim = c(n, n),
fractal = "billow",
pertubation = "normal",
pertubation_amplitude = 20,
frequency = .03
)
noise <- noise %>%
as.cimg() %>%
isoblur(sigma = 2)
}
if(type == "perlin") {
noise <- noise_perlin(
dim = c(n, n),
fractal = "billow",
pertubation = "normal",
frequency = .01
)
}
noise <- noise %>%
as.matrix() %>%
as.tibble()
noise$x <- 1:n
noise <- noise %>%
gather(key = y, value = value, -x) %>%
mutate(
y = y %>% str_remove("V") %>% as.numeric(),
fr = fr)
return(noise)
}
noisetype <- "worley"
#noisetype <- "perlin"
noise <- bind_rows(
make_noise_frame(n = 200, fr = 1, type = noisetype),
make_noise_frame(n = 200, fr = 2, type = noisetype),
make_noise_frame(n = 200, fr = 3, type = noisetype),
make_noise_frame(n = 200, fr = 4, type = noisetype)
)
pic <- noise %>%
ggplot(aes(x=x, y=y, colour=value)) +
geom_raster(
aes(fill=value),
interpolate = TRUE,
show.legend = FALSE) +
scale_fill_viridis_c() +
theme_void() +
coord_equal() +
transition_states(
states = fr,
transition_length = 1,
state_length = .3
) +
ease_aes("linear")
fname <- paste0("~/Desktop/", noisetype, ".gif")
animate(pic)
anim_save(fname)
@djnavarro
Copy link
Author

Worley noise with perturbation and Gaussian blur:
worley

Perlin noise:
perlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment