Hello all I am playing with R for to make a animated GIF. any suggestions, improvements are welcome :-) case somebody could help me, i thanks! Cleber N. Borges ( klebyn ) my objective: (steps TODO) ------------------- 1) to save PNG files; -----> i don't know the best way to make this; 2) transform the PNG files into GIF files (easy! no problem! ... i think ...) 3) reload the GiF files in R and use the caTools package to make a animated GIF. ------------------ ############################ the code ######## reverse the STRING strReverse <- function(x) sapply(lapply(strsplit(x, NULL), rev), paste, collapse="") ######## logotype to animate yourLogo = "Is Nice to play with R-package " logoWidth = 1.5 logoHeight = 2.5 L = nchar(yourLogo) TrigSplit = 360 / L yourLogo = strReverse(yourLogo) posx = numeric(L) posy = numeric(L) for( i in 0:L){ posx[i] = logoHeight * sin(i * TrigSplit * pi / 180) posy[i] = logoWidth * cos(i * TrigSplit * pi / 180) } max_x = max(posx)*1.1 max_y = max(posy)*3 min_x = min(posx)*1.1 min_y = min(posy)*3 cex = 2/(posy + 2) idx = 1:L for(j in 1:L-1) { ###################file = paste("CQM_",j,".png",sep="") ###################png(filename=file, bg="transparent") plot(0,t='n', xlim=c(min_x,max_x), ylim=c(min_y,max_y), axes=FALSE, ann=FALSE, font=3 ) for( i in 1:L){text(x=posx[i], y=posy[i], labels=substr(yourLogo,idx[i],idx[i]), col='blue', cex=cex[i] ) } idx = (append(idx[L],idx))[1:L] Sys.sleep(0.2) ###################dev.off() } ############## final code
klebyn a ??crit :> my objective: > 1) to save PNG files; > -----> i don't know the best way to make this;?png (also bmp(), jpg() available) hih
you could first make the frames to put together in R, then outside of R glue the frames into a gif. eg: frames<-10 for(i in 1:frames) { jpeg(paste("ani_", i, ".jpg", sep = "")) plot(1:10,1:10, col = i) dev.off() } then use an image editing program to glue the jpgs together -- eg free and crossplatform imagemagick (www.imagemagick.org). under linux and once imagemagick is installed, the command $ convert -delay 10 ani_*.jpg animation.gif makes a looping animated gif `animation.gif' with 10/100 sec. between frame flips. ---- Katharine Mullen Department of Physics and Astronomy Faculty of Sciences Vrije Universiteit de Boelelaan 1081 1081 HV Amsterdam The Netherlands room: T.1.06 tel: +31 205987870 fax: +31 205987992 e-mail: kate at nat.vu.nl http://www.nat.vu.nl/~kate/
Tuszynski, Jaroslaw W.
2005-Oct-06 12:23 UTC
[R] playing with R: make a animated GIF file...
See write.gif function in caTools. Jarek -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of klebyn Sent: Wednesday, October 05, 2005 8:05 PM To: r-help at stat.math.ethz.ch Subject: [R] playing with R: make a animated GIF file... Hello all I am playing with R for to make a animated GIF. any suggestions, improvements are welcome :-) case somebody could help me, i thanks! Cleber N. Borges ( klebyn ) my objective: (steps TODO) ------------------- 1) to save PNG files; -----> i don't know the best way to make this; 2) transform the PNG files into GIF files (easy! no problem! ... i think ...) 3) reload the GiF files in R and use the caTools package to make a animated GIF. ------------------ ############################ the code ######## reverse the STRING strReverse <- function(x) sapply(lapply(strsplit(x, NULL), rev), paste, collapse="") ######## logotype to animate yourLogo = "Is Nice to play with R-package " logoWidth = 1.5 logoHeight = 2.5 L = nchar(yourLogo) TrigSplit = 360 / L yourLogo = strReverse(yourLogo) posx = numeric(L) posy = numeric(L) for( i in 0:L){ posx[i] = logoHeight * sin(i * TrigSplit * pi / 180) posy[i] = logoWidth * cos(i * TrigSplit * pi / 180) } max_x = max(posx)*1.1 max_y = max(posy)*3 min_x = min(posx)*1.1 min_y = min(posy)*3 cex = 2/(posy + 2) idx = 1:L for(j in 1:L-1) { ###################file = paste("CQM_",j,".png",sep="") ###################png(filename=file, bg="transparent") plot(0,t='n', xlim=c(min_x,max_x), ylim=c(min_y,max_y), axes=FALSE, ann=FALSE, font=3 ) for( i in 1:L){text(x=posx[i], y=posy[i], labels=substr(yourLogo,idx[i],idx[i]), col='blue', cex=cex[i] ) } idx = (append(idx[L],idx))[1:L] Sys.sleep(0.2) ###################dev.off() } ############## final code ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Apparently Analagous Threads
- Bivariate Normal Distribution Plots
- ggplot2 = bar size
- Starcraft Patch
- [680] trunk/wxruby2/samples/printing/printing.rb: Cleaned up to use the Ruby naming convention, added #! line, now uses Wx default ID''s in standard menu items.
- [LLVMdev] Structure Alignment