#' Super Formula 2d
#'
#'
sf_2d <- function(m,n1,n2,n3){
u <- seq(0,2*pi, length.out = 300)
r <- abs(abs(cos(m*u/4))^n2 + abs(sin(m*u/4))^n3)^(-1/n1)
data.frame(
x = 0.5*r*cos(u)/max(r),
y = 0.5*r*sin(u)/max(r)
)
}
library(ggplot2)
library(tidyverse)
data <- sf_2d(20, 2, 5, 5)
noise1<- ambient::gen_worley(data$x, data$y,frequency = 100,seed = 42)
noise2<- ambient::gen_worley(data$x, data$y,frequency = 75,seed = 69)
noise3<- ambient::gen_worley(data$x, data$y,frequency = 1000,seed = 420)
df <- data.frame(y=c(data$y, data$y, data$y),
group = c(
rep(1,length(data$x)),
rep(2,length(data$x)),
rep(3,length(data$x))
),
noise = c(noise1,noise2, noise3)
)
df2 <- df
for (i in 1:500) {
set.seed(i)
type = sample(1:2, 1)
new_df <- df %>%
mutate(
y = case_when(
type == 1 ~ ambient::gen_perlin(y, frequency = .3, seed = i),
type == 2 ~ ambient::gen_simplex(y, frequency = .17, seed = i),
TRUE ~ ambient::gen_worley(y, frequency = 0.11, distance = "manhattan", gain = 0.48, value = "distance", distance_ind = c( 5, 6 ), jitter = 0.16, pertubation = 'none', pertubation_amplitude = 0.23, seed = i
))) %>%
mutate(
noise = sign(noise)*(1000000*i)+noise,
group = i/1000+group
)
df2 <- rbind(df2, new_df)
}
StatChull <- ggproto("StatChull", Stat,
compute_group = function(data, scales) {
data[chull(data$x, data$y), , drop = FALSE]
},
required_aes = c("x", "y")
)
stat_chull <- function(mapping = NULL, data = NULL, geom = "polygon",
position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE, ...) {
layer(
stat = StatChull, data = data, mapping = mapping, geom = geom,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...)
)
}
agg_png(file, width = 700, height = 500, units = 'px')
df2 %>%
mutate(group_detail = group,
) %>%
mutate(fill= case_when(
group == 1 ~"#721121",
group == 2 ~ "#5B3758",
TRUE ~ "#E64E8D"
),
fill2 =colorspace::lighten(col = fill, amount = .5* group_detail%% 1),
#noise= abs(noise),
y= abs(y),
size =1/(group_detail%% 1)
) %>%
ggplot()+
geom_point(color = "#5B3758", alpha=.020, shape = 46, aes(size = size*10))+
geom_point(color = "#5B3758", alpha=.015, shape = 46, aes(size = size*7.5))+
geom_point(color = "#5B3758", alpha=.010, shape = 46, aes(size = size*5))+
geom_point(color = "#5B3758", alpha=.005, shape = 46, aes(size = size*1))+
aes(
noise,
y,
fill = fill2,
group = as.factor(group))+
ggforce::geom_bspline_closed(
alpha = .01,
expand = unit(.025, 'cm')
)+
theme_canvas(background_fill = "black")+
scale_fill_identity()+
coord_polar(theta = "y")
ggsave("polygon_test_1500.png", plot, type = "cairo", dpi = 320, height = 12, width = 12)
ggsave("polygon_test_1500_2.png", plot, dpi = 320, height = 12, width = 12)
ggsave("polygon_test_1500_3.png", dpi = 320, height = 12, width = 12, device = ragg::agg_png,res = 300)
geom_bspline_closed(alpha = 0.5, )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.