Created
March 14, 2026 20:25
-
-
Save tukachev/c6c9ab8807b63602ae074a7bf67a21d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(showtext) | |
| # Шрифты | |
| font_add_google("Noto Serif", "noto") | |
| showtext_auto() | |
| showtext_opts(dpi = 300) | |
| # Загрузка и подготовка данных | |
| url <- "https://files.pilookup.com/pi/1000.txt" | |
| pi_raw <- read_file(url) | |
| # pi_raw | |
| digits_vec <- str_extract_all(pi_raw, "\\d")[[1]][1:1000] | |
| digits_vec <- factor(digits_vec, levels = 0:9) | |
| # digits_vec | |
| # Математика спирали Ферма | |
| phi <- 1.618034 # (sqrt(5) + 1) / 2 | |
| golden_angle <- 2 * pi / (phi^2) | |
| df <- tibble( | |
| i = 1:length(digits_vec), | |
| digit = digits_vec) %>% | |
| mutate( | |
| theta = i * golden_angle, | |
| r = sqrt(i), | |
| x = r * cos(theta), | |
| y = r * sin(theta) | |
| ) | |
| # Визуализация | |
| p <- ggplot(df, aes(x, y, fill = digit)) + | |
| geom_point(size = 3.5, shape = 21, color = "gray50", | |
| stroke = 0.1, alpha = 0.85) + | |
| scale_x_continuous(expand = expansion(mult = 0.2)) + | |
| scale_y_continuous(expand = expansion(mult = 0.2)) + | |
| coord_equal() + | |
| scale_fill_viridis_d(option = "magma") + | |
| theme_void() + | |
| labs( | |
| title = expression(pi), | |
| subtitle = "The First 1 000 Digits", | |
| caption = "March 14 • Pi Day" | |
| ) + | |
| guides(fill = guide_legend(nrow = 1, label.position = "bottom")) + | |
| theme( | |
| legend.position = "bottom", | |
| legend.title = element_blank(), | |
| legend.text = element_text(size = 10, color = "grey60"), | |
| plot.background = element_rect(fill = "black", color = "black"), | |
| panel.background = element_rect(fill = "black", color = "black"), | |
| text = element_text(family = "noto", color = "white"), | |
| plot.title = element_text(size = 90, hjust = 0.5, | |
| margin = margin(t = 50, b = -10)), | |
| plot.subtitle = element_text(size = 22, | |
| color = "grey70", hjust = 0.5), | |
| plot.caption = element_text(size = 13, color = "grey40", hjust = 0.5, | |
| margin = margin(t = 30, b = 30)), | |
| plot.margin = margin(0, 0, 0, 0) | |
| ) | |
| ggsave("pi_poster_A4.png", p, | |
| width = 8.27, height = 11.69, | |
| dpi = 300, bg = "black" | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment