Life should be fun. I saw a post in R-help list saying Merry Christmas to other useRs, and I followed up by some R code which can produce a naive animation like this:
Here is the code to generate the above Flash animation with shining Christmas:
library(animation)
saveSWF({
n = length(speed <- runif(angle <- runif(x <- strsplit("MERRY CHRISTMAS",
"")[[1]], 0, 360), 0, 15))
for (j in 1:300) {
angle = angle + speed
plot.new()
plot.window(c(1, n), c(0, 1))
for (i in 1:n) text(i, 0.5, x[i], srt = angle[i], cex = runif(1,
1, 4), col = sample(colors(), 1))
text(n, 0, "Yihui @ 2009-12-24 (http://yihui.org)",
adj = c(1, 0), col = "white", cex = 0.8)
}
}, interval = 0.04, dev = "pdf", outdir = getwd(), para = list(mar = rep(0,
4), bg = "black"), width = 8, height = 1)
## in animation package (>=1.1-0), see demo('Xmas')
There are other animation formats in the R package animation :
use saveMovie() to get a GIF animation (need ImageMagick)
ani.start() and ani.stop() can produce an HTML page with the animation in it
saveLatex() can embed an animation into a PDF document
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).
← Create Animations in PDF Documents Using R
Happy New Year with R →