Matrix-style screensaver in R

March 31, 2019
By

(This article was first published on R – Eran Raviv, and kindly contributed to R-bloggers)

This post shares short code snippet to make your own screen saver in R, The Matrix-style:

Matrix-style screen saver in R

The code takes a few seconds to complete.

nx = 100
ny = 80 
kk <- 110
x = sample(x = 1:nx, size = kk, replace = TRUE)
y = seq(-1, -ny, length = kk)
codes <- matrix(0:127, 8, 16, byrow = TRUE, dimnames = list(0:7, c(0:9, letters[1:6])))
library(magrittr)
ascii <- c(apply(codes, c(1, 2), intToUtf8), letters, 1:10) 
ascii <- sort(ascii)
ascii <- ascii[-c(1:37)]
# plot
op = par(bg = "black", mar = c(0, 0, 0, 0) )
plot(1:nx, seq(-1, -nx), type = "n", xlim = c(1, nx), ylim = c(-ny+10, 1), bty= "n", xaxt= "n", yaxt= "n")
for (i in seq_along(x) ) { 
aux = sample(1:ny, 1)
points( rep(x[i], aux), y[1:aux], 
pch = sample(ascii, aux, replace = TRUE), 
col = hsv(0.35, 1, 1, runif(aux, 0.1)), cex = runif(aux, 0.3) )
}

Because of randomness, once you ran the code, you will never see the exact screen saver elsewhere. Enjoy.

To leave a comment for the author, please follow the link and comment on their blog: R – Eran Raviv.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)