Skip to content

Instantly share code, notes, and snippets.

@loukesio
Last active June 25, 2023 16:30
Show Gist options
  • Select an option

  • Save loukesio/80ab931f55f8a0cb31da41e6abc9ab88 to your computer and use it in GitHub Desktop.

Select an option

Save loukesio/80ab931f55f8a0cb31da41e6abc9ab88 to your computer and use it in GitHub Desktop.
library(showtext)
library(ggplot2)
## Loading Google fonts (https://fonts.google.com/)
font_add_google("Exo 2", "Exo")
## Automatically use showtext to render text
showtext_auto()
generate_lines_within_circle <- function(center_x, center_y, radius, num_lines) {
start_angles <- runif(num_lines, 0, 2 * pi)
end_angles <- start_angles + runif(num_lines, 0, 2 * pi)
start_x <- center_x + radius * cos(start_angles)
start_y <- center_y + radius * sin(start_angles)
end_x <- center_x + radius * cos(end_angles)
end_y <- center_y + radius * sin(end_angles)
tibble(
start_x = start_x,
start_y = start_y,
end_x = end_x,
end_y = end_y
)
}
# Circle parameters
center_x <- 0.5
center_y <- 0.5
radius <- 0.4
# Number of lines to generate within the circle
num_lines <- 300
# Generate random lines within the circle
lines_within_circle <- generate_lines_within_circle(center_x, center_y, radius, num_lines)
# Create a ggplot with a circle and lines within
ggplot() +
geom_circle(aes(x0 = center_x, y0 = center_y, r = radius), fill = NA, color = "#333333") +
purrr::pmap(
.l = lines_within_circle,
.f = function(start_x, start_y, end_x, end_y) {
geom_segment(
aes(x = start_x, y = start_y, xend = end_x, yend = end_y),
color = 'gray',
size = 0.1
)
}
) +
coord_fixed() +
labs(title="Futuristic Evenings") +
theme_void() +
theme(legend.position = "none",
plot.title=element_text(family="Exo", size=28, hjust=0.5, color="#8d96a3"),
panel.background = element_rect(fill = "#333333", color=NA),
plot.background = element_rect(fill = "#333333", color=NA),
panel.grid = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment