Created
July 16, 2020 09:08
-
-
Save djnavarro/4f6f34feb18aa5e92fba2351c6192586 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(ambient) | |
library(dplyr) | |
seaweed <- function(seed) { | |
set.seed(seed) | |
output <- here::here("images", paste0("seaweed_", seed, ".png")) | |
# generate a random palette | |
palette_name <- sample(scico::scico_palette_names(), 1) | |
palette <- scico::scico(1000, palette = palette_name) | |
# construct the transformed space | |
grid <- long_grid( | |
x = seq(-10, 10, length.out = 1000), | |
y = seq(-20, 0, length.out = 1000) | |
) | |
f <- runif(1, min = .3, max = .5) | |
curl <- curl_noise( | |
generator = gen_simplex, | |
x = grid$x, | |
y = grid$y, | |
seed = sample(1000, 1), | |
frequency = f | |
) | |
g <- runif(1, min = .1, max = .4) | |
c <- runif(1, min = .1, max = .4) | |
curl$x <- g * grid$x + c * curl$x | |
curl$y <- g * grid$y + c * curl$y | |
# frequency of waves (in transformed space) mixing the | |
# two noise components | |
f <- runif(1, min = .1, max = 1) | |
grid$mix <- gen_spheres( | |
x = curl$x, | |
y = curl$y, | |
frequency = f | |
) | |
grid$mix <- normalise(grid$mix) | |
# "a" governs the shading in the "high" regions | |
grid$a <- fracture( | |
noise = gen_worley, | |
fractal = fbm, | |
value = "distance", | |
octaves = 8, | |
x = curl$x, | |
y = curl$y, | |
seed = sample(1000, 1), | |
frequency = runif(1, min = .1, max = .9) | |
) %>% normalise() | |
# "b" governs the noise in the "low" regions | |
grid$b <- fracture( | |
noise = gen_worley, | |
fractal = fbm, | |
value = "distance", | |
octaves = 8, | |
x = curl$x, | |
y = curl$y, | |
seed = sample(1000, 1), | |
frequency = runif(1, min = 1, max = 2) | |
) %>% normalise() | |
# mix, normalise and shade the grid | |
grid$pattern <- normalise( | |
x = with(grid, (a * mix + (1-mix) * b)), | |
to = c(.00001, 1) | |
) | |
grid$pattern <- ceiling(grid$pattern * 1000) | |
grid$shade <- palette[grid$pattern] | |
# render and save the image file | |
png(output, 5000, 5000) | |
op <- par(mar = c(0,0,0,0)) | |
rast <- as.raster(grid, value = shade) | |
plot(rast) | |
dev.off() | |
par(op) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment