Skip to content

Instantly share code, notes, and snippets.

@djnavarro
Created March 17, 2021 23:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djnavarro/fff64fafea9ca27687acef0e3ced0e04 to your computer and use it in GitHub Desktop.
Save djnavarro/fff64fafea9ca27687acef0e3ced0e04 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(scales)
library(ambient)
heart_x <- function(angle) {
x <- (16 * sin(angle)^3)/17
return(x - mean(x))
}
heart_y <- function(angle) {
y <- (13 * cos(angle) - 5 * cos(2 * angle) - 2 * cos(3 * angle) -
cos(4 * angle))/17
return(y - mean(y))
}
perlin_heart <- function(cx = 0, cy = 0, n = 1000, noise_max = 0.5,
octaves = 2, r_min = 0.5, r_max = 1, rot = 0,
w_min = 0, w_max = 1) {
tibble(
angle = seq(0, 2*pi, length.out = n),
xoff = cos(angle) %>% rescale(from = c(-1, 1), to = c(0, noise_max)),
yoff = sin(angle) %>% rescale(from = c(-1, 1), to = c(0, noise_max)),
r = gen_simplex %>%
fracture(fractal = fbm, x = xoff, y = yoff, octaves = octaves) %>%
rescale(from = c(-0.5, 0.5), to = c(r_min, r_max)),
x0 = r * heart_x(angle),
y0 = r * heart_y(angle),
x = x0 * cos(rot) - y0 * sin(rot) + cx,
y = x0 * sin(rot) + y0 * cos(rot) + cy,
width = gen_simplex %>%
fracture(fractal = fbm, x = xoff, y = yoff, octaves = octaves) %>%
rescale(to = c(w_min, w_max))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment