Created
February 24, 2019 17:15
-
-
Save andrewnguyen42/760e01ad72e7fcb32ed771e0967032ef to your computer and use it in GitHub Desktop.
Visualize the first million digits of pi as a phone background
This file contains 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(dplyr) | |
library(ggplot2) | |
library(httr) | |
library(stringr) | |
my_pi <- GET(url = 'https://www.angio.net/pi/digits/pi1000000.txt') %>% | |
content(as="text") | |
n <- 1000000 | |
str_split(my_pi, "") %>% | |
.[[1]] %>% | |
tibble(digit = .) %>% | |
slice(-2) %>% #remove the annoying decimal | |
filter(row_number() < n) %>% | |
mutate(digit = as.numeric(digit) | |
, n = row_number() | |
, radians = .5 - ((360/10) * digit)/180 | |
, x = cospi(radians) | |
, y = sinpi(radians)) %>% | |
bind_rows(data.frame(digit = NA, n = 0, radians = 0, x = 0, y = 0) | |
, .) %>% | |
mutate(x_cum = cumsum(x) | |
, y_cum = cumsum(y)) %>% | |
ggplot(aes(x = x_cum, y = y_cum, colour = n)) + | |
scale_color_gradient(low = 'grey90', high = 'dodgerblue4') + | |
geom_path() + | |
theme_void() + | |
theme(legend.position = "none") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment