Skip to content

Instantly share code, notes, and snippets.

@djnavarro
Created February 9, 2021 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djnavarro/a90265b0eed8dae9bad7052e7e3183d9 to your computer and use it in GitHub Desktop.
Save djnavarro/a90265b0eed8dae9bad7052e7e3183d9 to your computer and use it in GitHub Desktop.
perlin_circle <- function(
cx = 0, cy = 0, n = 100, noise_max = 0.5, octaves = 2, r_min = 0.5, r_max = 1
) {
tibble::tibble(
angle = seq(0, 2*pi, length.out = n),
xoff = scales::rescale(x = cos(angle), from = c(-1, 1), to = c(0, noise_max)),
yoff = scales::rescale(x = sin(angle), from = c(-1, 1), to = c(0, noise_max)),
r = scales::rescale(
x = ambient::fracture(
noise = ambient::gen_simplex,
fractal = ambient::fbm,
x = xoff,
y = yoff,
octaves = octaves
),
from = c(-0.5, 0.5),
to = c(r_min, r_max)
),
x = r * cos(angle) + cx,
y = r * sin(angle) + cy
)
}
pic <- ggplot2::ggplot(
data = perlin_circle(),
mapping = ggplot2::aes(x = x, y = y)
) +
ggplot2::geom_path() +
ggplot2::coord_equal()
plot(pic)
@djnavarro
Copy link
Author

djnavarro commented Feb 9, 2021

credit for the core idea goes to @will-r-chase

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