Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lots of circle placed in a larger circle with some noise
library(ggplot2)
circle_alpha <- 0.3
radius1 <- 25
radius2 <- 75
how_many <- 200
reverse_colors <- FALSE
circleFunc <-
function(center = c(0,0), radius = 1, npoints = 100, start = 0, end = 2*pi) {
tt <- seq(start, end, length.out = npoints)
data.frame(x = center[1] + radius * cos(tt),
y = center[2] + radius * sin(tt))
}
add.alpha <- function(col, alpha = 1) {
if(missing(col))
stop("Please provide a vector colors.")
apply(sapply(col, col2rgb)/255, 2, function(x)
rgb(x[1], x[2], x[3], alpha = alpha))
}
p <- ggplot()
p <- p + theme_void()
if (reverse_colors) {
p <- p + theme(panel.background = element_rect(fill='black'))
}
angle <- 0
angle_inc <- 2*pi/how_many
while (angle < 2*pi) {
circle <- circleFunc(center = radius2*c(cos(angle), sin(angle)),
radius = radius1)
if (reverse_colors) {
p <- p + geom_path(aes(x = x, y = y),data = circle + runif(100,1,sqrt(radius2)), color = "white")
} else {
p <- p + geom_path(alpha = 0.3, aes(x = x, y = y),data = circle + runif(100,1,sqrt(radius2)))
}
angle <- angle + angle_inc
}
p
ggsave(file = "noisyCircle.png", width = 4, height = 4, dpi = 300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.