R/perlin_circles.R

Defines functions perlin_circles

#' Create noisy circles
#' Stolen from Will. R Chase.
#'
#' @param cx the x position of the center of the shape
#' @param cy the y position of the center of the shape
#' @param n the number of points to generate
#' @param noise_max the maximum noise variation
#' @param octaves the number of noise layers used to create the noise
#' @param r_min g
#' @param r_max g
#' @param seed control the random seed.
perlin_circles <- function(cx, cy, n, noise_max, octaves, r_min, r_max, seed){
  if(is.null(seed)){
    seed <- ambient:::random_seed()
  }

  tibble(
    angle = seq(0, 2*pi, length.out = n),
    xoff = scales::rescale(cos(angle), from = c(-1, 1), to = c(0, noise_max)),
    yoff = scales::rescale(sin(angle), from = c(-1, 1), to = c(0, noise_max)),
    r = scales::rescale(ambient::fracture(gen_simplex, fbm, x = xoff, y = yoff, octaves = 2, seed=seed),
                from = c(-0.5, 0.5), to = c(r_min, r_max)),
    x = r * cos(angle)+ cx,
    y = r * sin(angle)+ cy
    )
}

library(ambient)
library(tidyverse)
library(patchwork)
library(ragg)
d1 <- perlin_circles(cx=c(1,  .1), cy=c(1, .1), n= 10000, 10, 10, 1, 1.25, seed=42)
d2 <- perlin_circles(cx=c(-1,  .1), cy=c(-1, .1), n= 10000, 10, 10, 1, 1.25, seed=42)
d3 <- perlin_circles(cx=c(4,  3.1), cy=c(4, 3.1), n= 10000, 10, 10, 1, 1.25, seed=42)


ggplot()+
  aes(x, y)+
  geom_polygon(data= d1, fill = "#2660A4", alpha = .5)+
  geom_polygon(data= d2, fill = "#721121", alpha = .5)+
  #geom_point()
  theme_canvas()+
  coord_polar(theta = "y")

ggplot()+
  aes(x, y)+
  geom_polygon(data= d1, fill = "white", alpha = .5,
               position = position_jitter(0.005, 0.005))+
  geom_polygon(data= d2, fill = "black", alpha = .25,
               position = position_jitter(0, 0.005))+
  geom_polygon(data= d1, fill = "#83B692", alpha = .5)+
  geom_polygon(data= d2, fill = "#5B3758", alpha = .75)+
  theme_canvas("grey7")+
  coord_polar(theta = "x")
ggsave("majick_01.png", device = agg_png(),  dpi = 320)
delabj/genArt documentation built on March 25, 2021, 11:56 p.m.