[R] playing with R: make a animated GIF file...
klebyn
klebyn at yahoo.com.br
Thu Oct 6 02:05:18 CEST 2005
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
More information about the R-help
mailing list