Skip to content

Instantly share code, notes, and snippets.

@schochastics
Created April 1, 2019 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schochastics/a6b8139a84aeff6fa34aa7ecd3bf3ccd to your computer and use it in GitHub Desktop.
Save schochastics/a6b8139a84aeff6fa34aa7ecd3bf3ccd to your computer and use it in GitHub Desktop.
the matrix with gganimate
library(tidyverse)
library(gganimate)
ascii <- c(";", ":", "!", "?", ".", "'", "\"", "(", ")", "[", "]", "{",
"}", "@", "*", "/", "\\", "&", "#", "%", "`", "^", "+", "<",
"=", ">", "|", "~", "$", "0", "1", "1", "10", "2", "2", "3",
"3", "4", "4", "5", "5", "6", "6", "7", "7", "8", "8", "9", "9",
"a", "a", "A", "b", "b", "B", "c", "c", "C", "d", "d", "D", "e",
"e", "E", "f", "f", "F", "g", "g", "G", "h", "h", "H", "i", "i",
"I", "j", "j", "J", "k", "k", "K", "l", "l", "L", "m", "m", "M",
"n", "n", "N", "o", "o", "O", "p", "p", "P", "q", "q", "Q", "r",
"r", "R", "s", "s", "S", "t", "t", "T", "u", "u", "U", "v", "v",
"V", "w", "w", "W", "x", "x", "X", "y", "y", "Y", "z", "z", "Z")
tbl <- map_dfr(seq(0,15,0.1),function(x){
l <- sample(30:99,1)
start <- sample(100:l,1)
end <- start-l+1
tibble(x=rep(x,l),y=start:end,val=sample(ascii,l,replace = T),alpha=runif(l),time=1:l)
})
tbl <- tbl %>%
bind_rows(tbl %>% mutate(time=time+50) %>% dplyr::filter(time<=100))
ggplot(tbl,aes(x,y))+
geom_text(aes(label=val),alpha=tbl$alpha,col=hsv(0.35, 1, 1))+
coord_cartesian(clip = "off")+
theme_void()+
theme(panel.background = element_rect(fill="black"),
plot.margin = margin(0, 0, 0, 0, "cm"))+
transition_time(time)+
shadow_wake(0.8) -> p
animate(p,nframes = 50)
anim_save("matrix.gif")
@schochastics
Copy link
Author

matrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment